Contains not working as expected with array of objects #145
Replies: 4 comments 2 replies
-
JSON Schema is constraints based, and so anything you don't prohibit is allowed and considered valid. You haven't constrained additional properties using the You need to add See https://json-schema.org/understanding-json-schema/reference/object.html#additional-properties for more info. |
Beta Was this translation helpful? Give feedback.
-
but my constraint was that the list of objects should have contained {"somePropertiesA":true} ( it's not my project, but some external constraints for the job i'm in ), not that it should contain only that element or such. I'm receiving a list of object and i should check if one of those elements is precisely {"somePropertiesA":true}. |
Beta Was this translation helpful? Give feedback.
-
this is invalid, but is reported as valid
this is valid, correctly
This is invalid, and is reported correctly as invalid
This is valid, and is reported as valid
I have no idea why the API i'm working with was implemented like that, but if i don't find any solution i'll just check it in the code directly which seems easier |
Beta Was this translation helpful? Give feedback.
-
Ok, I added the additional property inside the contain, this creates 1 question. Why this was considered invalid
and this was not
since in both case they would validate a contain without the additionalProperties |
Beta Was this translation helpful? Give feedback.
-
Using the following schema:
the following object is considered valid
despite the schema saying "elements should contain a "somePropertyA":"true" object.
Is this the normal behaviour? most validators I tried will consider it valid (despite being intended not to be valid). The only way to make this work is passing an array with just the "intended" property, like
this will correctly be considered invalid.
Beta Was this translation helpful? Give feedback.
All reactions