krg7880 / json-schema-generator

Generates draft v4 schema from a local file or a remote JSON url.
MIT License
174 stars 53 forks source link

Only evaluates first parent keys #38

Open johnfrancisgit opened 1 year ago

johnfrancisgit commented 1 year ago

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 commented 12 months ago

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