json-schema-generator icon indicating copy to clipboard operation
json-schema-generator copied to clipboard

Only evaluates first parent keys

Open johnfrancisgit opened this issue 1 year ago • 1 comments

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' ]
}

johnfrancisgit avatar Nov 26 '23 18:11 johnfrancisgit

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))

sudhanshug16 avatar Dec 03 '23 20:12 sudhanshug16