I expect array A to contain at least all the elements of attribute array B.
Here are some examples:
// valid
{
"A": [1,2,3],
"B": [1,2]
}
// valid
{
"A": [1,2],
"B": [1,2]
}
// invalid
{
"A": [1,2],
"B": [1,2,3]
}
There are no specific requirements regarding the draft of JSON Schema
I found this answer, and it was similar to my need: Is it possible in json schema to define a constraint between two properties
I tried using:
- minContains & $data
{
...
"propertires": {
"A": {
"minContains": {"$data": "1/B"}
},
"B": {
...
}
}
}
result: invalid test cases can also pass
2
Answers
Well the thing is that minContains is for counting occurrences. Try schema below.
TEST CASES
It should be noted that
$data
is not a JSON Schema keyword. Some implementations have chosen to support some kind of functionality for it, but that functionality is not specified officially and will vary across implementations, if it’s supported at all.The primary reason it has not been adopted is that it forms invalid schemas. In your example,
"minContains": {"$data": "1/B"}
,minContains
requires a number, but you’ve given it an object.I have created an alternative
data
keyword in a custom vocab that you’re welcome to look at, but so far it only has support in .Net.In the end, JSON Schema doesn’t have a way to express the kinds of references you want.