Debian Codegraph @

spec/JSON-Schema-Test-Suite/tests/draft2020-12/ref.json

raw ◀ ▶
1 Debian patch touch this file
•1 [
2 {
3 "description": "root pointer ref",
4 "schema": {
5 "properties": {
6 "foo": {"$ref": "#"}
7 },
8 "additionalProperties": false
9 },
10 "tests": [
11 {
12 "description": "match",
13 "data": {"foo": false},
14 "valid": true
15 },
16 {
17 "description": "recursive match",
18 "data": {"foo": {"foo": false}},
19 "valid": true
20 },
21 {
22 "description": "mismatch",
23 "data": {"bar": false},
24 "valid": false
25 },
26 {
27 "description": "recursive mismatch",
28 "data": {"foo": {"bar": false}},
29 "valid": false
30 }
31 ]
32 },
33 {
34 "description": "relative pointer ref to object",
35 "schema": {
36 "properties": {
37 "foo": {"type": "integer"},
38 "bar": {"$ref": "#/properties/foo"}
39 }
40 },
41 "tests": [
42 {
43 "description": "match",
44 "data": {"bar": 3},
45 "valid": true
46 },
47 {
48 "description": "mismatch",
49 "data": {"bar": true},
50 "valid": false
51 }
52 ]
53 },
54 {
55 "description": "relative pointer ref to array",
56 "schema": {
57 "prefixItems": [
58 {"type": "integer"},
59 {"$ref": "#/prefixItems/0"}
60 ]
61 },
62 "tests": [
63 {
64 "description": "match array",
65 "data": [1, 2],
66 "valid": true
67 },
68 {
69 "description": "mismatch array",
70 "data": [1, "foo"],
71 "valid": false
72 }
73 ]
74 },
75 {
76 "description": "escaped pointer ref",
77 "schema": {
78 "$defs": {
79 "tilde~field": {"type": "integer"},
80 "slash/field": {"type": "integer"},
81 "percent%field": {"type": "integer"}
82 },
83 "properties": {
84 "tilde": {"$ref": "#/$defs/tilde~0field"},
85 "slash": {"$ref": "#/$defs/slash~1field"},
86 "percent": {"$ref": "#/$defs/percent%25field"}
87 }
88 },
89 "tests": [
90 {
91 "description": "slash invalid",
92 "data": {"slash": "aoeu"},
93 "valid": false
94 },
95 {
96 "description": "tilde invalid",
97 "data": {"tilde": "aoeu"},
98 "valid": false
99 },
100 {
101 "description": "percent invalid",
102 "data": {"percent": "aoeu"},
103 "valid": false
104 },
105 {
106 "description": "slash valid",
107 "data": {"slash": 123},
108 "valid": true
109 },
110 {
111 "description": "tilde valid",
112 "data": {"tilde": 123},
113 "valid": true
114 },
115 {
116 "description": "percent valid",
117 "data": {"percent": 123},
118 "valid": true
119 }
120 ]
121 },
122 {
123 "description": "nested refs",
124 "schema": {
125 "$defs": {
126 "a": {"type": "integer"},
127 "b": {"$ref": "#/$defs/a"},
128 "c": {"$ref": "#/$defs/b"}
129 },
130 "$ref": "#/$defs/c"
131 },
132 "tests": [
133 {
134 "description": "nested ref valid",
135 "data": 5,
136 "valid": true
137 },
138 {
139 "description": "nested ref invalid",
140 "data": "a",
141 "valid": false
142 }
143 ]
144 },
145 {
146 "description": "ref applies alongside sibling keywords",
147 "schema": {
148 "$defs": {
149 "reffed": {
150 "type": "array"
151 }
152 },
153 "properties": {
154 "foo": {
155 "$ref": "#/$defs/reffed",
156 "maxItems": 2
157 }
158 }
159 },
160 "tests": [
161 {
162 "description": "ref valid, maxItems valid",
163 "data": { "foo": [] },
164 "valid": true
165 },
166 {
167 "description": "ref valid, maxItems invalid",
168 "data": { "foo": [1, 2, 3] },
169 "valid": false
170 },
171 {
172 "description": "ref invalid",
173 "data": { "foo": "string" },
174 "valid": false
175 }
176 ]
177 },
178 {
179 "description": "remote ref, containing refs itself",
180 "schema": {
181 "$ref": "https://json-schema.org/draft/2020-12/schema"
182 },
183 "tests": [
184 {
185 "description": "remote ref valid",
186 "data": {"minLength": 1},
187 "valid": true
188 },
189 {
190 "description": "remote ref invalid",
191 "data": {"minLength": -1},
192 "valid": false
193 }
194 ]
195 },
196 {
197 "description": "property named $ref that is not a reference",
198 "schema": {
199 "properties": {
200 "$ref": {"type": "string"}
201 }
202 },
203 "tests": [
204 {
205 "description": "property named $ref valid",
206 "data": {"$ref": "a"},
207 "valid": true
208 },
209 {
210 "description": "property named $ref invalid",
211 "data": {"$ref": 2},
212 "valid": false
213 }
214 ]
215 },
216 {
217 "description": "property named $ref, containing an actual $ref",
218 "schema": {
219 "properties": {
220 "$ref": {"$ref": "#/$defs/is-string"}
221 },
222 "$defs": {
223 "is-string": {
224 "type": "string"
225 }
226 }
227 },
228 "tests": [
229 {
230 "description": "property named $ref valid",
231 "data": {"$ref": "a"},
232 "valid": true
233 },
234 {
235 "description": "property named $ref invalid",
236 "data": {"$ref": 2},
237 "valid": false
238 }
239 ]
240 },
241 {
242 "description": "$ref to boolean schema true",
243 "schema": {
244 "$ref": "#/$defs/bool",
245 "$defs": {
246 "bool": true
247 }
248 },
249 "tests": [
250 {
251 "description": "any value is valid",
252 "data": "foo",
253 "valid": true
254 }
255 ]
256 },
257 {
258 "description": "$ref to boolean schema false",
259 "schema": {
260 "$ref": "#/$defs/bool",
261 "$defs": {
262 "bool": false
263 }
264 },
265 "tests": [
266 {
267 "description": "any value is invalid",
268 "data": "foo",
269 "valid": false
270 }
271 ]
272 },
273 {
274 "description": "Recursive references between schemas",
275 "schema": {
276 "$id": "http://localhost:1234/tree",
277 "description": "tree of nodes",
278 "type": "object",
279 "properties": {
280 "meta": {"type": "string"},
281 "nodes": {
282 "type": "array",
283 "items": {"$ref": "node"}
284 }
285 },
286 "required": ["meta", "nodes"],
287 "$defs": {
288 "node": {
289 "$id": "http://localhost:1234/node",
290 "description": "node",
291 "type": "object",
292 "properties": {
293 "value": {"type": "number"},
294 "subtree": {"$ref": "tree"}
295 },
296 "required": ["value"]
297 }
298 }
299 },
300 "tests": [
301 {
302 "description": "valid tree",
303 "data": {
304 "meta": "root",
305 "nodes": [
306 {
307 "value": 1,
308 "subtree": {
309 "meta": "child",
310 "nodes": [
311 {"value": 1.1},
312 {"value": 1.2}
313 ]
314 }
315 },
316 {
317 "value": 2,
318 "subtree": {
319 "meta": "child",
320 "nodes": [
321 {"value": 2.1},
322 {"value": 2.2}
323 ]
324 }
325 }
326 ]
327 },
328 "valid": true
329 },
330 {
331 "description": "invalid tree",
332 "data": {
333 "meta": "root",
334 "nodes": [
335 {
336 "value": 1,
337 "subtree": {
338 "meta": "child",
339 "nodes": [
340 {"value": "string is invalid"},
341 {"value": 1.2}
342 ]
343 }
344 },
345 {
346 "value": 2,
347 "subtree": {
348 "meta": "child",
349 "nodes": [
350 {"value": 2.1},
351 {"value": 2.2}
352 ]
353 }
354 }
355 ]
356 },
357 "valid": false
358 }
359 ]
360 },
361 {
362 "description": "refs with quote",
363 "schema": {
364 "properties": {
365 "foo\"bar": {"$ref": "#/$defs/foo%22bar"}
366 },
367 "$defs": {
368 "foo\"bar": {"type": "number"}
369 }
370 },
371 "tests": [
372 {
373 "description": "object with numbers is valid",
374 "data": {
375 "foo\"bar": 1
376 },
377 "valid": true
378 },
379 {
380 "description": "object with strings is invalid",
381 "data": {
382 "foo\"bar": "1"
383 },
384 "valid": false
385 }
386 ]
387 },
388 {
389 "description": "ref creates new scope when adjacent to keywords",
390 "schema": {
391 "$defs": {
392 "A": {
393 "unevaluatedProperties": false
394 }
395 },
396 "properties": {
397 "prop1": {
398 "type": "string"
399 }
400 },
401 "$ref": "#/$defs/A"
402 },
403 "tests": [
404 {
405 "description": "referenced subschema doesn't see annotations from properties",
406 "data": {
407 "prop1": "match"
408 },
409 "valid": false
410 }
411 ]
412 },
413 {
414 "description": "naive replacement of $ref with its destination is not correct",
415 "schema": {
416 "$defs": {
417 "a_string": { "type": "string" }
418 },
419 "enum": [
420 { "$ref": "#/$defs/a_string" }
421 ]
422 },
423 "tests": [
424 {
425 "description": "do not evaluate the $ref inside the enum, matching any string",
426 "data": "this is a string",
427 "valid": false
428 },
429 {
430 "description": "do not evaluate the $ref inside the enum, definition exact match",
431 "data": { "type": "string" },
432 "valid": false
433 },
434 {
435 "description": "match the enum exactly",
436 "data": { "$ref": "#/$defs/a_string" },
437 "valid": true
438 }
439 ]
440 },
441 {
442 "description": "refs with relative uris and defs",
443 "schema": {
444 "$id": "http://example.com/schema-relative-uri-defs1.json",
445 "properties": {
446 "foo": {
447 "$id": "schema-relative-uri-defs2.json",
448 "$defs": {
449 "inner": {
450 "properties": {
451 "bar": { "type": "string" }
452 }
453 }
454 },
455 "$ref": "#/$defs/inner"
456 }
457 },
458 "$ref": "schema-relative-uri-defs2.json"
459 },
460 "tests": [
461 {
462 "description": "invalid on inner field",
463 "data": {
464 "foo": {
465 "bar": 1
466 },
467 "bar": "a"
468 },
469 "valid": false
470 },
471 {
472 "description": "invalid on outer field",
473 "data": {
474 "foo": {
475 "bar": "a"
476 },
477 "bar": 1
478 },
479 "valid": false
480 },
481 {
482 "description": "valid on both fields",
483 "data": {
484 "foo": {
485 "bar": "a"
486 },
487 "bar": "a"
488 },
489 "valid": true
490 }
491 ]
492 },
493 {
494 "description": "relative refs with absolute uris and defs",
495 "schema": {
496 "$id": "http://example.com/schema-refs-absolute-uris-defs1.json",
497 "properties": {
498 "foo": {
499 "$id": "http://example.com/schema-refs-absolute-uris-defs2.json",
500 "$defs": {
501 "inner": {
502 "properties": {
503 "bar": { "type": "string" }
504 }
505 }
506 },
507 "$ref": "#/$defs/inner"
508 }
509 },
510 "$ref": "schema-refs-absolute-uris-defs2.json"
511 },
512 "tests": [
513 {
514 "description": "invalid on inner field",
515 "data": {
516 "foo": {
517 "bar": 1
518 },
519 "bar": "a"
520 },
521 "valid": false
522 },
523 {
524 "description": "invalid on outer field",
525 "data": {
526 "foo": {
527 "bar": "a"
528 },
529 "bar": 1
530 },
531 "valid": false
532 },
533 {
534 "description": "valid on both fields",
535 "data": {
536 "foo": {
537 "bar": "a"
538 },
539 "bar": "a"
540 },
541 "valid": true
542 }
543 ]
544 },
545 {
546 "description": "$id must be resolved against nearest parent, not just immediate parent",
547 "schema": {
548 "$id": "http://example.com/a.json",
549 "$defs": {
550 "x": {
551 "$id": "http://example.com/b/c.json",
552 "not": {
553 "$defs": {
554 "y": {
555 "$id": "d.json",
556 "type": "number"
557 }
558 }
559 }
560 }
561 },
562 "allOf": [
563 {
564 "$ref": "http://example.com/b/d.json"
565 }
566 ]
567 },
568 "tests": [
569 {
570 "description": "number should pass",
571 "data": 1,
572 "valid": true
573 },
574 {
575 "description": "non-number should fail",
576 "data": "a",
577 "valid": false
578 }
579 ]
580 }
581 ]