Skip to content

Commit e56aa91

Browse files
committed
Add a test for 2019's interaction between additional/unevaluatedItems
The interesting bit here actually *only* applies to 2019, as it's the only draft containing both unevaluatedItems as well as additionalItems -- the latter in its specified behavior containing: if "items" is absent or its annotation result is the boolean true, "additionalItems" MUST be ignored. (from https://datatracker.ietf.org/doc/html/draft-handrews-json-schema-02#section-9.3.1.2) In newer drafts (i.e. 2020), when additionalItems "became" items, this condition was dropped (i.e. items without a neighboring prefixItems now is indeed *not* ignored). Refs: https://github.com/orgs/json-schema-org/discussions/57 Closes: #292
1 parent 69a09a3 commit e56aa91

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

tests/draft-next/unevaluatedItems.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,27 @@
116116
}
117117
]
118118
},
119+
{
120+
"description": "unevaluatedItems with items",
121+
"schema": {
122+
"$schema": "https://json-schema.org/draft/next/schema",
123+
"items": {"type": "number"},
124+
"unevaluatedItems": {"type": "string"}
125+
},
126+
"tests": [
127+
{
128+
"description": "valid under items",
129+
"comment": "no elements are considered by unevaluatedItems",
130+
"data": [5, 6, 7, 8],
131+
"valid": true
132+
},
133+
{
134+
"description": "invalid under items",
135+
"data": ["foo", "bar", "baz"],
136+
"valid": false
137+
}
138+
]
139+
},
119140
{
120141
"description": "unevaluatedItems with nested tuple",
121142
"schema": {

tests/draft2019-09/unevaluatedItems.json

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
]
100100
},
101101
{
102-
"description": "unevaluatedItems with additionalItems",
102+
"description": "unevaluatedItems with items and additionalItems",
103103
"schema": {
104104
"$schema": "https://json-schema.org/draft/2019-09/schema",
105105
"items": [
@@ -116,6 +116,48 @@
116116
}
117117
]
118118
},
119+
{
120+
"description": "unevaluatedItems with ignored additionalItems",
121+
"schema": {
122+
"$schema": "https://json-schema.org/draft/2019-09/schema",
123+
"additionalItems": {"type": "number"},
124+
"unevaluatedItems": {"type": "string"}
125+
},
126+
"tests": [
127+
{
128+
"description": "invalid under unevaluatedItems",
129+
"comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema",
130+
"data": ["foo", 1],
131+
"valid": false
132+
},
133+
{
134+
"description": "all valid under unevaluatedItems",
135+
"data": ["foo", "bar", "baz"],
136+
"valid": true
137+
}
138+
]
139+
},
140+
{
141+
"description": "unevaluatedItems with ignored applicator additionalItems",
142+
"schema": {
143+
"$schema": "https://json-schema.org/draft/2019-09/schema",
144+
"allOf": [ { "additionalItems": { "type": "number" } } ],
145+
"unevaluatedItems": {"type": "string"}
146+
},
147+
"tests": [
148+
{
149+
"description": "invalid under unevaluatedItems",
150+
"comment": "additionalItems is entirely ignored when items isn't present, so all elements need to be valid against the unevaluatedItems schema",
151+
"data": ["foo", 1],
152+
"valid": false
153+
},
154+
{
155+
"description": "all valid under unevaluatedItems",
156+
"data": ["foo", "bar", "baz"],
157+
"valid": true
158+
}
159+
]
160+
},
119161
{
120162
"description": "unevaluatedItems with nested tuple",
121163
"schema": {

tests/draft2020-12/unevaluatedItems.json

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999
]
100100
},
101101
{
102-
"description": "unevaluatedItems with items",
102+
"description": "unevaluatedItems with items and prefixItems",
103103
"schema": {
104104
"$schema": "https://json-schema.org/draft/2020-12/schema",
105105
"prefixItems": [
@@ -116,6 +116,27 @@
116116
}
117117
]
118118
},
119+
{
120+
"description": "unevaluatedItems with items",
121+
"schema": {
122+
"$schema": "https://json-schema.org/draft/2020-12/schema",
123+
"items": {"type": "number"},
124+
"unevaluatedItems": {"type": "string"}
125+
},
126+
"tests": [
127+
{
128+
"description": "valid under items",
129+
"comment": "no elements are considered by unevaluatedItems",
130+
"data": [5, 6, 7, 8],
131+
"valid": true
132+
},
133+
{
134+
"description": "invalid under items",
135+
"data": ["foo", "bar", "baz"],
136+
"valid": false
137+
}
138+
]
139+
},
119140
{
120141
"description": "unevaluatedItems with nested tuple",
121142
"schema": {

0 commit comments

Comments
 (0)