shuttle-hq/synth

Cannot use key "type" as a name as a schema attribute

bitbreakr opened this issue · 2 comments

Describe the bug
One of my DB columns is named type, I am manually creating this DB table, and it will not generate because of the name "type" used at the top level.

To Reproduce

  1. Schema (if applicable)
{
  "type": "array",
  "length": {
    "type": "number",
    "subtype": "u64",
    "range": {
      "low": 6,
      "high": 7,
      "step": 1
    }
  },
  "content": {
    "type": "object",
    "id": {
      "type": "string",
      "uuid": {}
    },
    "email": {
      "type": "string",
      "format": {
        "format": "dev-{name}@email.com",
        "arguments": {
          "name": {
            "type": "string",
            "faker": {
              "generator": "username"
            }
          },
          "email": {
            "type": "string",
            "faker": {
              "generator": "safe_email"
            }
          }
        }
      }
    },
    "notificationEmailEnable": {
      "type": "bool",
      "frequency": 0.5
    },
    "notificationPhoneEnable": {
      "type": "bool",
      "frequency": 0.5
    },
    "type": {
      "type": "one_of",
      "variants": [
        {
          "weight": 0.5,
          "type": "string",
          "pattern": "M|F"
        },
        {
          "weight": 0.5,
          "type": "null"
        }
      ]
    }
  }
}

  1. See error
Error: Unable to open the namespace "db_seed"

Caused by:
    0: at file db/users.json
    1: Failed to parse collection
    2: invalid type: map, expected variant identifier at line 61 column 1

Expected behavior
I expect I can generate the schema with any attributes names I want

Screenshots
If applicable, add screenshots to help explain your problem.

Environment (please complete the following information):

  • OS: MacOS
  • Version: latest

Additional context
Add any other context about the problem here.

Hey @bitbreakr, there's a work around for this -> #1.

Although admittedly this should be documented somewhere explicitly.

Thanks for your reply, it has helped!