Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongoose mode doesn't descend into array definitions #36

Open
elliott-beach opened this issue Mar 25, 2018 · 0 comments
Open

mongoose mode doesn't descend into array definitions #36

elliott-beach opened this issue Mar 25, 2018 · 0 comments

Comments

@elliott-beach
Copy link

elliott-beach commented Mar 25, 2018

Mongoose mode doesn't descend into arrays. An object within an array of will have type mixed, unlike in the default JSON mode which will infer the type of the object within the array.
Is this intentional?

Repro:
Using example.json:

{
  "array":[{
    "value1": "a",
    "value2": "b"
    }]
}

With the default mode (json):

⋊> ~/m/p/so-app generate-schema example.json                                                                                                  
{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "array": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "value1": {
            "type": "string"
          },
          "value2": {
            "type": "string"
          }
        }
      }
    }
  }
}

With mongoose-mode:

⋊> ~/m/p/so-app generate-schema -m example.json                                                                                               
{
  "array": {
    "type": [
      "Mixed"
    ]
  }
}

I noticed this while idly investigating the asker's problem in this old StackOverflow question: https://stackoverflow.com/questions/39362065/how-to-create-a-mongoose-schema-from-json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant