Debian Codegraph @

spec/JSON-Schema-Test-Suite/tests/draft2019-09/ref.json

raw symbols ◀ ▶ SCIP
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 "items": [
58 {"type": "integer"},
59 {"$ref": "#/items/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": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
181 "tests": [
182 {
183 "description": "remote ref valid",
184 "data": {"minLength": 1},
185 "valid": true
186 },
187 {
188 "description": "remote ref invalid",
189 "data": {"minLength": -1},
190 "valid": false
191 }
192 ]
193 },
194 {
195 "description": "property named $ref that is not a reference",
196 "schema": {
197 "properties": {
198 "$ref": {"type": "string"}
199 }
200 },
201 "tests": [
202 {
203 "description": "property named $ref valid",
204 "data": {"$ref": "a"},
205 "valid": true
206 },
207 {
208 "description": "property named $ref invalid",
209 "data": {"$ref": 2},
210 "valid": false
211 }
212 ]
213 },
214 {
215 "description": "property named $ref, containing an actual $ref",
216 "schema": {
217 "properties": {
218 "$ref": {"$ref": "#/$defs/is-string"}
219 },
220 "$defs": {
221 "is-string": {
222 "type": "string"
223 }
224 }
225 },
226 "tests": [
227 {
228 "description": "property named $ref valid",
229 "data": {"$ref": "a"},
230 "valid": true
231 },
232 {
233 "description": "property named $ref invalid",
234 "data": {"$ref": 2},
235 "valid": false
236 }
237 ]
238 },
239 {
240 "description": "$ref to boolean schema true",
241 "schema": {
242 "$ref": "#/$defs/bool",
243 "$defs": {
244 "bool": true
245 }
246 },
247 "tests": [
248 {
249 "description": "any value is valid",
250 "data": "foo",
251 "valid": true
252 }
253 ]
254 },
255 {
256 "description": "$ref to boolean schema false",
257 "schema": {
258 "$ref": "#/$defs/bool",
259 "$defs": {
260 "bool": false
261 }
262 },
263 "tests": [
264 {
265 "description": "any value is invalid",
266 "data": "foo",
267 "valid": false
268 }
269 ]
270 },
271 {
272 "description": "Recursive references between schemas",
273 "schema": {
274 "$id": "http://localhost:1234/tree",
275 "description": "tree of nodes",
276 "type": "object",
277 "properties": {
278 "meta": {"type": "string"},
279 "nodes": {
280 "type": "array",
281 "items": {"$ref": "node"}
282 }
283 },
284 "required": ["meta", "nodes"],
285 "$defs": {
286 "node": {
287 "$id": "http://localhost:1234/node",
288 "description": "node",
289 "type": "object",
290 "properties": {
291 "value": {"type": "number"},
292 "subtree": {"$ref": "tree"}
293 },
294 "required": ["value"]
295 }
296 }
297 },
298 "tests": [
299 {
300 "description": "valid tree",
301 "data": {
302 "meta": "root",
303 "nodes": [
304 {
305 "value": 1,
306 "subtree": {
307 "meta": "child",
308 "nodes": [
309 {"value": 1.1},
310 {"value": 1.2}
311 ]
312 }
313 },
314 {
315 "value": 2,
316 "subtree": {
317 "meta": "child",
318 "nodes": [
319 {"value": 2.1},
320 {"value": 2.2}
321 ]
322 }
323 }
324 ]
325 },
326 "valid": true
327 },
328 {
329 "description": "invalid tree",
330 "data": {
331 "meta": "root",
332 "nodes": [
333 {
334 "value": 1,
335 "subtree": {
336 "meta": "child",
337 "nodes": [
338 {"value": "string is invalid"},
339 {"value": 1.2}
340 ]
341 }
342 },
343 {
344 "value": 2,
345 "subtree": {
346 "meta": "child",
347 "nodes": [
348 {"value": 2.1},
349 {"value": 2.2}
350 ]
351 }
352 }
353 ]
354 },
355 "valid": false
356 }
357 ]
358 },
359 {
360 "description": "refs with quote",
361 "schema": {
362 "properties": {
363 "foo\"bar": {"$ref": "#/$defs/foo%22bar"}
364 },
365 "$defs": {
366 "foo\"bar": {"type": "number"}
367 }
368 },
369 "tests": [
370 {
371 "description": "object with numbers is valid",
372 "data": {
373 "foo\"bar": 1
374 },
375 "valid": true
376 },
377 {
378 "description": "object with strings is invalid",
379 "data": {
380 "foo\"bar": "1"
381 },
382 "valid": false
383 }
384 ]
385 },
386 {
387 "description": "ref creates new scope when adjacent to keywords",
388 "schema": {
389 "$defs": {
390 "A": {
391 "unevaluatedProperties": false
392 }
393 },
394 "properties": {
395 "prop1": {
396 "type": "string"
397 }
398 },
399 "$ref": "#/$defs/A"
400 },
401 "tests": [
402 {
403 "description": "referenced subschema doesn't see annotations from properties",
404 "data": {
405 "prop1": "match"
406 },
407 "valid": false
408 }
409 ]
410 },
411 {
412 "description": "naive replacement of $ref with its destination is not correct",
413 "schema": {
414 "$defs": {
415 "a_string": { "type": "string" }
416 },
417 "enum": [
418 { "$ref": "#/$defs/a_string" }
419 ]
420 },
421 "tests": [
422 {
423 "description": "do not evaluate the $ref inside the enum, matching any string",
424 "data": "this is a string",
425 "valid": false
426 },
427 {
428 "description": "do not evaluate the $ref inside the enum, definition exact match",
429 "data": { "type": "string" },
430 "valid": false
431 },
432 {
433 "description": "match the enum exactly",
434 "data": { "$ref": "#/$defs/a_string" },
435 "valid": true
436 }
437 ]
438 },
439 {
440 "description": "refs with relative uris and defs",
441 "schema": {
442 "$id": "http://example.com/schema-relative-uri-defs1.json",
443 "properties": {
444 "foo": {
445 "$id": "schema-relative-uri-defs2.json",
446 "$defs": {
447 "inner": {
448 "properties": {
449 "bar": { "type": "string" }
450 }
451 }
452 },
453 "$ref": "#/$defs/inner"
454 }
455 },
456 "$ref": "schema-relative-uri-defs2.json"
457 },
458 "tests": [
459 {
460 "description": "invalid on inner field",
461 "data": {
462 "foo": {
463 "bar": 1
464 },
465 "bar": "a"
466 },
467 "valid": false
468 },
469 {
470 "description": "invalid on outer field",
471 "data": {
472 "foo": {
473 "bar": "a"
474 },
475 "bar": 1
476 },
477 "valid": false
478 },
479 {
480 "description": "valid on both fields",
481 "data": {
482 "foo": {
483 "bar": "a"
484 },
485 "bar": "a"
486 },
487 "valid": true
488 }
489 ]
490 },
491 {
492 "description": "relative refs with absolute uris and defs",
493 "schema": {
494 "$id": "http://example.com/schema-refs-absolute-uris-defs1.json",
495 "properties": {
496 "foo": {
497 "$id": "http://example.com/schema-refs-absolute-uris-defs2.json",
498 "$defs": {
499 "inner": {
500 "properties": {
501 "bar": { "type": "string" }
502 }
503 }
504 },
505 "$ref": "#/$defs/inner"
506 }
507 },
508 "$ref": "schema-refs-absolute-uris-defs2.json"
509 },
510 "tests": [
511 {
512 "description": "invalid on inner field",
513 "data": {
514 "foo": {
515 "bar": 1
516 },
517 "bar": "a"
518 },
519 "valid": false
520 },
521 {
522 "description": "invalid on outer field",
523 "data": {
524 "foo": {
525 "bar": "a"
526 },
527 "bar": 1
528 },
529 "valid": false
530 },
531 {
532 "description": "valid on both fields",
533 "data": {
534 "foo": {
535 "bar": "a"
536 },
537 "bar": "a"
538 },
539 "valid": true
540 }
541 ]
542 },
543 {
544 "description": "$id must be resolved against nearest parent, not just immediate parent",
545 "schema": {
546 "$id": "http://example.com/a.json",
547 "$defs": {
548 "x": {
549 "$id": "http://example.com/b/c.json",
550 "not": {
551 "$defs": {
552 "y": {
553 "$id": "d.json",
554 "type": "number"
555 }
556 }
557 }
558 }
559 },
560 "allOf": [
561 {
562 "$ref": "http://example.com/b/d.json"
563 }
564 ]
565 },
566 "tests": [
567 {
568 "description": "number should pass",
569 "data": 1,
570 "valid": true
571 },
572 {
573 "description": "non-number should fail",
574 "data": "a",
575 "valid": false
576 }
577 ]
578 }
579 ]