Skip to content

Commit 100e982

Browse files
committed
Add tests for unevaluatedItems with minContains = 0
It is tempting to forgo evaluation of the 'contains' schema when `minContains = 0`. However, when an `unevaluatedItems` schema is present, the `contains` schema must still be evaluated as it will affect the results of the `unevaluatedItems` schema.
1 parent 83e866b commit 100e982

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed

tests/draft-next/unevaluatedItems.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,37 @@
711711
}
712712
]
713713
},
714+
{
715+
"description" : "unevaluatedItems with minContains = 0",
716+
"schema" : {
717+
"$schema": "https://json-schema.org/draft/next/schema",
718+
"contains": {"type": "string"},
719+
"minContains": 0,
720+
"unevaluatedItems": false
721+
},
722+
"tests" : [
723+
{
724+
"description": "empty array is valid",
725+
"data": [],
726+
"valid": true
727+
},
728+
{
729+
"description": "no items evaluated by contains",
730+
"data": [0],
731+
"valid": false
732+
},
733+
{
734+
"description": "some but not all items evaluated by contains",
735+
"data": ["foo", 0],
736+
"valid": false
737+
},
738+
{
739+
"description": "all items evaluated by contains",
740+
"data": ["foo", "bar"],
741+
"valid": true
742+
}
743+
]
744+
},
714745
{
715746
"description": "non-array instances are valid",
716747
"schema": {

tests/draft2020-12/unevaluatedItems.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,37 @@
718718
}
719719
]
720720
},
721+
{
722+
"description" : "unevaluatedItems with minContains = 0",
723+
"schema" : {
724+
"$schema": "https://json-schema.org/draft/2020-12/schema",
725+
"contains": {"type": "string"},
726+
"minContains": 0,
727+
"unevaluatedItems": false
728+
},
729+
"tests" : [
730+
{
731+
"description": "empty array is valid",
732+
"data": [],
733+
"valid": true
734+
},
735+
{
736+
"description": "no items evaluated by contains",
737+
"data": [0],
738+
"valid": false
739+
},
740+
{
741+
"description": "some but not all items evaluated by contains",
742+
"data": ["foo", 0],
743+
"valid": false
744+
},
745+
{
746+
"description": "all items evaluated by contains",
747+
"data": ["foo", "bar"],
748+
"valid": true
749+
}
750+
]
751+
},
721752
{
722753
"description": "non-array instances are valid",
723754
"schema": {

0 commit comments

Comments
 (0)