Closed kesslerdev closed 5 years ago
I am afraid I can't understand your question. The generated Schema looks correct to me. But you want the schema to be generated to something else?
yes with this generation the schema don't validate all of objects in my array but only the first one. Or anthoter syntax (in blueprint) exist for validate all items of an array ?
@kesslerdev The generated schema appears to work as expected, here's examples I've tested. Could you please elaborate on what the problem you are facing is? Perhaps with actual JSON examples.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"links": {
"type": "array",
"items": {
"oneOf": [
{
"type": "object",
"properties": {
"rel": {
"type": "string"
},
"href": {
"type": "string"
}
},
"required": [
"rel",
"href"
],
"additionalProperties": false
}
]
}
}
},
"required": [
"links"
]
}
{
"links": [
{
"rel": "x",
"href": "x"
},
{
"rel": "x",
"href": "x"
},
{
"rel": "x",
"href": "x"
}
]
}
Errors:
.links[2]
should have required property 'rel'{
"links": [
{
"rel": "x",
"href": "x"
},
{
"rel": "x",
"href": "x"
},
{
"href": "x"
}
]
}
And I want to point out, your example also fails as expected with the schema.
links[0]
- should NOT have additional properties (reld
)links[2]
- should NOT have additional properties (reld
)links[3]
- should have required property 'res'links[3]
- should have required property 'href'you schema is correct but when i use MSON for generating the schema, it look wrong : it generate an array of object in items property instead of just an object or the oneOf format. In this case the generated schema validate only the first element of my array.
@kesslerdev In my comment I used the generated schema. The generated schema does validate every item in the array. Perhaps you're experiencing a bug in a JSON validation library instead?
@kylef what is the MSON code used for generting your schema ? i think my MSON is incorrect.
@kesslerdev, I'm was using the schema from your comment, the "generated" one.
Hello i have a problem when i validate an array of objects due of brackets in items properties
exemple: for invalid data : (unwanted properties in object & empty objects)
For structures
it prduce this schema :
in this case the validator show errors only in the first element others dont validate. In other issue ( #328 ) i show it is the normal behavior, item is an array of possible types but in drafter-04 for this it could be use the
oneOf
property. The schema must be rewriten to :