json-schema-generator
json-schema-generator copied to clipboard
Only evaluates first parent keys
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' ]
}
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))