Skip to content

Commit 9d0c502

Browse files
some tests of the interactions between $id, $anchor and $ref
1 parent c3f4319 commit 9d0c502

File tree

6 files changed

+319
-0
lines changed

6 files changed

+319
-0
lines changed

tests/draft2019-09/anchor.json

+31
Original file line numberDiff line numberDiff line change
@@ -77,5 +77,36 @@
7777
"valid": false
7878
}
7979
]
80+
},
81+
{
82+
"description": "non-schema object containing an $anchor property",
83+
"schema": {
84+
"$defs": {
85+
"const_not_anchor": {
86+
"const": {
87+
"$anchor": "not_a_real_anchor"
88+
}
89+
}
90+
},
91+
"if": {
92+
"const": "skip not_a_real_anchor"
93+
},
94+
"then": true,
95+
"else" : {
96+
"$ref": "#/$defs/const_not_anchor"
97+
}
98+
},
99+
"tests": [
100+
{
101+
"description": "skip traversing definition for a valid result",
102+
"data": "skip not_a_real_anchor",
103+
"valid": true
104+
},
105+
{
106+
"description": "const at const_not_anchor does not match",
107+
"data": 1,
108+
"valid": false
109+
}
110+
]
80111
}
81112
]

tests/draft2019-09/id.json

+31
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,36 @@
202202
"valid": true
203203
}
204204
]
205+
},
206+
{
207+
"description": "non-schema object containing an $id property",
208+
"schema": {
209+
"$defs": {
210+
"const_not_id": {
211+
"const": {
212+
"$id": "not_a_real_id"
213+
}
214+
}
215+
},
216+
"if": {
217+
"const": "skip not_a_real_id"
218+
},
219+
"then": true,
220+
"else" : {
221+
"$ref": "#/$defs/const_not_id"
222+
}
223+
},
224+
"tests": [
225+
{
226+
"description": "skip traversing definition for a valid result",
227+
"data": "skip not_a_real_id",
228+
"valid": true
229+
},
230+
{
231+
"description": "const at const_not_id does not match",
232+
"data": 1,
233+
"valid": false
234+
}
235+
]
205236
}
206237
]

tests/draft2019-09/ref.json

+65
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,70 @@
382382
"valid": false
383383
}
384384
]
385+
},
386+
{
387+
"description": "order of evaluation: $id and $ref",
388+
"schema": {
389+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
390+
"$id": "/base/base.json",
391+
"$ref": "int.json",
392+
"$defs": {
393+
"bigint": {
394+
"$comment": "canonical uri: /base/int.json",
395+
"$id": "int.json",
396+
"maximum": 10
397+
},
398+
"smallint": {
399+
"$comment": "canonical uri: /int.json",
400+
"$id": "/int.json",
401+
"maximum": 2
402+
}
403+
}
404+
},
405+
"tests": [
406+
{
407+
"description": "data is valid against first definition",
408+
"data": 5,
409+
"valid": true
410+
},
411+
{
412+
"description": "data is invalid against first definition",
413+
"data": 50,
414+
"valid": false
415+
}
416+
]
417+
},
418+
{
419+
"description": "order of evaluation: $id and $anchor and $ref",
420+
"schema": {
421+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
422+
"$id": "/base.json",
423+
"$ref": "#bigint",
424+
"$defs": {
425+
"bigint": {
426+
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
427+
"$anchor": "bigint",
428+
"maximum": 10
429+
},
430+
"smallint": {
431+
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
432+
"$id": "/",
433+
"$anchor": "bigint",
434+
"maximum": 2
435+
}
436+
}
437+
},
438+
"tests": [
439+
{
440+
"description": "data is valid against first definition",
441+
"data": 5,
442+
"valid": true
443+
},
444+
{
445+
"description": "data is invalid against first definition",
446+
"data": 50,
447+
"valid": false
448+
}
449+
]
385450
}
386451
]

tests/draft6/id.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[
2+
{
3+
"description": "non-schema object containing a plain-name $id property",
4+
"schema": {
5+
"$defs": {
6+
"const_not_anchor": {
7+
"const": {
8+
"$id": "#not_a_real_anchor"
9+
}
10+
}
11+
},
12+
"if": {
13+
"const": "skip not_a_real_anchor"
14+
},
15+
"then": true,
16+
"else" : {
17+
"$ref": "#/$defs/const_not_anchor"
18+
}
19+
},
20+
"tests": [
21+
{
22+
"description": "skip traversing definition for a valid result",
23+
"data": "skip not_a_real_anchor",
24+
"valid": true
25+
},
26+
{
27+
"description": "const at const_not_anchor does not match",
28+
"data": 1,
29+
"valid": false
30+
}
31+
]
32+
},
33+
{
34+
"description": "non-schema object containing an $id property",
35+
"schema": {
36+
"$defs": {
37+
"const_not_id": {
38+
"const": {
39+
"$id": "not_a_real_id"
40+
}
41+
}
42+
},
43+
"if": {
44+
"const": "skip not_a_real_id"
45+
},
46+
"then": true,
47+
"else" : {
48+
"$ref": "#/$defs/const_not_id"
49+
}
50+
},
51+
"tests": [
52+
{
53+
"description": "skip traversing definition for a valid result",
54+
"data": "skip not_a_real_id",
55+
"valid": true
56+
},
57+
{
58+
"description": "const at const_not_id does not match",
59+
"data": 1,
60+
"valid": false
61+
}
62+
]
63+
}
64+
]

tests/draft7/id.json

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[
2+
{
3+
"description": "non-schema object containing a plain-name $id property",
4+
"schema": {
5+
"$defs": {
6+
"const_not_anchor": {
7+
"const": {
8+
"$id": "#not_a_real_anchor"
9+
}
10+
}
11+
},
12+
"if": {
13+
"const": "skip not_a_real_anchor"
14+
},
15+
"then": true,
16+
"else" : {
17+
"$ref": "#/$defs/const_not_anchor"
18+
}
19+
},
20+
"tests": [
21+
{
22+
"description": "skip traversing definition for a valid result",
23+
"data": "skip not_a_real_anchor",
24+
"valid": true
25+
},
26+
{
27+
"description": "const at const_not_anchor does not match",
28+
"data": 1,
29+
"valid": false
30+
}
31+
]
32+
},
33+
{
34+
"description": "non-schema object containing an $id property",
35+
"schema": {
36+
"$defs": {
37+
"const_not_id": {
38+
"const": {
39+
"$id": "not_a_real_id"
40+
}
41+
}
42+
},
43+
"if": {
44+
"const": "skip not_a_real_id"
45+
},
46+
"then": true,
47+
"else" : {
48+
"$ref": "#/$defs/const_not_id"
49+
}
50+
},
51+
"tests": [
52+
{
53+
"description": "skip traversing definition for a valid result",
54+
"data": "skip not_a_real_id",
55+
"valid": true
56+
},
57+
{
58+
"description": "const at const_not_id does not match",
59+
"data": 1,
60+
"valid": false
61+
}
62+
]
63+
}
64+
]

tests/draft7/ref.json

+64
Original file line numberDiff line numberDiff line change
@@ -439,5 +439,69 @@
439439
"valid": false
440440
}
441441
]
442+
},
443+
{
444+
"description": "order of evaluation: $id and $ref",
445+
"schema": {
446+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
447+
"$id": "/base/base.json",
448+
"$ref": "int.json",
449+
"$defs": {
450+
"bigint": {
451+
"$comment": "canonical uri: /base/int.json",
452+
"$id": "int.json",
453+
"maximum": 10
454+
},
455+
"smallint": {
456+
"$comment": "canonical uri: /int.json",
457+
"$id": "/int.json",
458+
"maximum": 2
459+
}
460+
}
461+
},
462+
"tests": [
463+
{
464+
"description": "data is valid against first definition",
465+
"data": 5,
466+
"valid": true
467+
},
468+
{
469+
"description": "data is invalid against first definition",
470+
"data": 50,
471+
"valid": false
472+
}
473+
]
474+
},
475+
{
476+
"description": "order of evaluation: plain-name $id and $ref",
477+
"schema": {
478+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
479+
"$id": "/base.json",
480+
"$ref": "#bigint",
481+
"$defs": {
482+
"bigint": {
483+
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
484+
"$id": "#bigint",
485+
"maximum": 10
486+
},
487+
"smallint": {
488+
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
489+
"$id": "/#bigint",
490+
"maximum": 2
491+
}
492+
}
493+
},
494+
"tests": [
495+
{
496+
"description": "data is valid against first definition",
497+
"data": 5,
498+
"valid": true
499+
},
500+
{
501+
"description": "data is invalid against first definition",
502+
"data": 50,
503+
"valid": false
504+
}
505+
]
442506
}
443507
]

0 commit comments

Comments
 (0)