shuttle-hq / synth

The Declarative Data Generator
https://www.getsynth.com/
Apache License 2.0
1.37k stars 107 forks source link

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

Closed bitbreakr closed 1 year ago

bitbreakr commented 1 year ago

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"
        }
      ]
    }
    }
    }
2. See error
```bash
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):

Additional context Add any other context about the problem here.

christos-h commented 1 year ago

Hey @bitbreakr, there's a work around for this -> https://github.com/shuttle-hq/synth/issues/1.

Although admittedly this should be documented somewhere explicitly.

bitbreakr commented 1 year ago

Thanks for your reply, it has helped!