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

Only evaluates first parent keys #38

Open
johnfrancisgit opened this issue Nov 26, 2023 · 1 comment
Open

Only evaluates first parent keys #38

johnfrancisgit opened this issue Nov 26, 2023 · 1 comment

Comments

@johnfrancisgit
Copy link

The test JSON example does not create the schema for child keys as it says in the documentation:

var jsonSchemaGenerator = require('json-schema-generator')

const json_raw = {
  "title": "fresh fruit schema v1",
  "type": "object",
  "required": ["skin", "colors", "taste"],
  "properties": {
      "colors": {
          "type": "array",
          "minItems": 1,
          "uniqueItems": true,
          "items": {
              "type": "string"
          }
      },
      "skin": {
          "type": "string"
      },
      "taste": {
          "type": "number",
          "minimum": 5
      }
  }
}

var jsonSchema = jsonSchemaGenerator(json_raw)
console.log(jsonSchema);

Outputs:

{
  '$schema': 'http://json-schema.org/draft-04/schema#',
  description: '',
  type: 'object',
  properties: {
    extra: { type: 'object', properties: [Object], required: [Array] },
    data: { type: 'object', properties: [Object], required: [Array] },
    key: { type: 'object', properties: [Object], required: [Array] },
    metadata: { type: 'object', properties: [Object], required: [Array] }
  },
  required: [ 'extra', 'data', 'key', 'metadata' ]
}
@sudhanshug16
Copy link

It's probably because you are calling console.log with the schema object. console.log truncates the output on the second level. You might wanna try console.log(JSON.stringify(jsonSchema))

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

2 participants