json-schema-generator
json-schema-generator copied to clipboard
Items in array are not properly generated
If I have an array with 2 objects that have different properties it generates a item that resembles only the first object. The test json is this:
{
"data": [
{
"id": "1",
"type": "type1",
"attributes": {
"message": "Message",
"status": "pending"
}
},
{
"id": "2",
"something": "typ2",
"attributes": {
"name": "Name1",
"activity": "None"
}
}
]
}
If I generate the schema with version draft3 I get this:
{
"$schema": "http://json-schema.org/draft-03/schema#",
"description": "Generated from /web/app/shared/notifications/responses/get_notifications.json with shasum db9e033f3530d2420c527de7bf2c611551a61c23",
"type": "object",
"required": true,
"properties": {
"data": {
"type": "array",
"required": true,
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "object",
"required": true,
"properties": {
"id": {
"type": "string",
"required": true
},
"type": {
"type": "string",
"required": false
},
"attributes": {
"type": "object",
"required": true,
"properties": {
"message": {
"type": "string",
"required": true
},
"status": {
"type": "string",
"required": true
}
}
}
}
}
}
}
}
As you can see it completely ignores the second object in the array. If I generate it with schema4 I get this:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"description": "Generated from /web/app/shared/notifications/responses/get_notifications.json with shasum db9e033f3530d2420c527de7bf2c611551a61c23",
"type": "object",
"required": [
"data"
],
"properties": {
"data": {
"type": "array",
"minItems": 1,
"uniqueItems": true,
"items": {
"type": "object",
"required": [
"id",
"attributes"
],
"properties": {
"id": {
"type": "string"
},
"type": {
"type": "string"
},
"attributes": {
"type": "object",
"required": [
"message",
"status",
"name",
"activity"
],
"properties": {
"message": {
"type": "string"
},
"status": {
"type": "string"
}
}
}
}
}
}
}
}
The generated schema sees the attributes of the second object and has them as required but does not specify them in the properties. And it completely ignores the 'type' and 'something' attributes in both objects.
Am I missing something here?