Skip to content

Commit 46f67df

Browse files
committed
[244] Add a bunch of meta-schema tests
This adds tests using the meta-schema as a schema. This does not test things that cannot currently be guaranteed to be represented in a schema, for example, normalized URL requirements and optional "format" for "pattern".
1 parent fce9e9b commit 46f67df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+3425
-0
lines changed

tests/draft2019-09/additionalItems.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,5 +126,55 @@
126126
"valid": false
127127
}
128128
]
129+
},
130+
{
131+
"description": "Meta-schema applicator tests: array",
132+
"schema": {
133+
"$ref": "https://json-schema.org/draft/2019-09/schema"
134+
},
135+
"tests": [
136+
{
137+
"description": "Non-schema additionalItems: number",
138+
"data": {
139+
"additionalItems": 1
140+
},
141+
"valid": false
142+
},
143+
{
144+
"description": "Non-schema additionalItems: string",
145+
"data": {
146+
"additionalItems": "hello"
147+
},
148+
"valid": false
149+
},
150+
{
151+
"description": "Non-schema additionalItems: array",
152+
"data": {
153+
"additionalItems": []
154+
},
155+
"valid": false
156+
},
157+
{
158+
"description": "Non-schema additionalItems: null",
159+
"data": {
160+
"additionalItems": null
161+
},
162+
"valid": false
163+
},
164+
{
165+
"description": "Boolean additionalItems",
166+
"data": {
167+
"additionalItems": true
168+
},
169+
"valid": true
170+
},
171+
{
172+
"description": "Object additionalItems",
173+
"data": {
174+
"additionalItems": {}
175+
},
176+
"valid": true
177+
}
178+
]
129179
}
130180
]

tests/draft2019-09/additionalProperties.json

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,5 +129,55 @@
129129
"valid": false
130130
}
131131
]
132+
},
133+
{
134+
"description": "Meta-schema applicator tests: object",
135+
"schema": {
136+
"$ref": "https://json-schema.org/draft/2019-09/schema"
137+
},
138+
"tests": [
139+
{
140+
"description": "Non-schema additionalProperties: number",
141+
"data": {
142+
"additionalProperties": 1
143+
},
144+
"valid": false
145+
},
146+
{
147+
"description": "Non-schema additionalProperties: string",
148+
"data": {
149+
"additionalProperties": "hello"
150+
},
151+
"valid": false
152+
},
153+
{
154+
"description": "Non-schema additionalProperties: array",
155+
"data": {
156+
"additionalProperties": []
157+
},
158+
"valid": false
159+
},
160+
{
161+
"description": "Non-schema additionalProperties: null",
162+
"data": {
163+
"additionalProperties": null
164+
},
165+
"valid": false
166+
},
167+
{
168+
"description": "Boolean additionalProperties",
169+
"data": {
170+
"additionalProperties": true
171+
},
172+
"valid": true
173+
},
174+
{
175+
"description": "Object additionalProperties",
176+
"data": {
177+
"additionalProperties": {}
178+
},
179+
"valid": true
180+
}
181+
]
132182
}
133183
]

tests/draft2019-09/allOf.json

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,5 +290,104 @@
290290
"valid": true
291291
}
292292
]
293+
},
294+
{
295+
"description": "Meta-schema applicator tests: Boolean logic",
296+
"schema": {
297+
"$ref": "https://json-schema.org/draft/2019-09/schema"
298+
},
299+
"tests": [
300+
{
301+
"description": "Non-array allOf: number",
302+
"data": {
303+
"allOf": 1
304+
},
305+
"valid": false
306+
},
307+
{
308+
"description": "Non-array allOf: string",
309+
"data": {
310+
"allOf": "hello"
311+
},
312+
"valid": false
313+
},
314+
{
315+
"description": "Non-array allOf: Boolean",
316+
"data": {
317+
"allOf": true
318+
},
319+
"valid": false
320+
},
321+
{
322+
"description": "Non-array allOf: object",
323+
"data": {
324+
"allOf": {}
325+
},
326+
"valid": false
327+
},
328+
{
329+
"description": "Non-array allOf: null",
330+
"data": {
331+
"allOf": null
332+
},
333+
"valid": false
334+
},
335+
{
336+
"description": "Empty allOf",
337+
"data": {
338+
"allOf": []
339+
},
340+
"valid": false
341+
},
342+
{
343+
"description": "Not-a-schema allOf: string",
344+
"data": {
345+
"allOf": [ "integer" ]
346+
},
347+
"valid": false
348+
},
349+
{
350+
"description": "Not-a-schema allOf: number",
351+
"data": {
352+
"allOf": [ 1 ]
353+
},
354+
"valid": false
355+
},
356+
{
357+
"description": "Not-a-schema allOf: null",
358+
"data": {
359+
"allOf": [ null ]
360+
},
361+
"valid": false
362+
},
363+
{
364+
"description": "Not-a-schema allOf: array",
365+
"data": {
366+
"allOf": [ [] ]
367+
},
368+
"valid": false
369+
},
370+
{
371+
"description": "Valid allOf: boolean schema",
372+
"data": {
373+
"allOf": [ true ]
374+
},
375+
"valid": true
376+
},
377+
{
378+
"description": "Valid allOf: empty schema",
379+
"data": {
380+
"allOf": [ {} ]
381+
},
382+
"valid": true
383+
},
384+
{
385+
"description": "Valid allOf: schema",
386+
"data": {
387+
"allOf": [ { "type": "integer" } ]
388+
},
389+
"valid": true
390+
}
391+
]
293392
}
294393
]

tests/draft2019-09/anchor.json

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,95 @@
7777
"valid": false
7878
}
7979
]
80+
},
81+
{
82+
"description": "Meta-schema core tests: $anchor",
83+
"schema": {
84+
"$ref": "https://json-schema.org/draft/2019-09/schema"
85+
},
86+
"tests": [
87+
{
88+
"description": "Non-string $anchor: number",
89+
"data": {
90+
"$anchor": 1
91+
},
92+
"valid": false
93+
},
94+
{
95+
"description": "Non-string $anchor: Boolean",
96+
"data": {
97+
"$anchor": true
98+
},
99+
"valid": false
100+
},
101+
{
102+
"description": "Non-string $anchor: null",
103+
"data": {
104+
"$anchor": null
105+
},
106+
"valid": false
107+
},
108+
{
109+
"description": "Non-string $anchor: array",
110+
"data": {
111+
"$anchor": []
112+
},
113+
"valid": false
114+
},
115+
{
116+
"description": "Non-string $anchor: object",
117+
"data": {
118+
"$anchor": {}
119+
},
120+
"valid": false
121+
},
122+
{
123+
"description": "Valid $anchor",
124+
"data": {
125+
"$anchor": "himom"
126+
},
127+
"valid": true
128+
},
129+
{
130+
"description": "Invalid $anchor: starts with invalid",
131+
"data": {
132+
"$anchor": "-himom"
133+
},
134+
"valid": false
135+
},
136+
{
137+
"description": "Invalid $anchor: ends with invalid",
138+
"data": {
139+
"$anchor": "himom@"
140+
},
141+
"valid": false
142+
},
143+
{
144+
"description": "Fragment syntax disallowed",
145+
"data": {
146+
"$ref": "#foo",
147+
"$defs": {
148+
"A": {
149+
"$anchor": "#foo",
150+
"type": "integer"
151+
}
152+
}
153+
},
154+
"valid": false
155+
},
156+
{
157+
"description": "Invalid characters disallowed",
158+
"data": {
159+
"$ref": "#/a/b",
160+
"$defs": {
161+
"A": {
162+
"$anchor": "/a/b",
163+
"type": "integer"
164+
}
165+
}
166+
},
167+
"valid": false
168+
}
169+
]
80170
}
81171
]

0 commit comments

Comments
 (0)