Skip to content

Commit 1d5583d

Browse files
karenetheridgeJulian
authored andcommitted
some tests of the interactions between $id, $anchor and $ref
1 parent 07c45c0 commit 1d5583d

File tree

6 files changed

+315
-2
lines changed

6 files changed

+315
-2
lines changed

tests/draft2019-09/anchor.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,5 +169,36 @@
169169
"valid": false
170170
}
171171
]
172+
},
173+
{
174+
"description": "non-schema object containing an $anchor property",
175+
"schema": {
176+
"$defs": {
177+
"const_not_anchor": {
178+
"const": {
179+
"$anchor": "not_a_real_anchor"
180+
}
181+
}
182+
},
183+
"if": {
184+
"const": "skip not_a_real_anchor"
185+
},
186+
"then": true,
187+
"else" : {
188+
"$ref": "#/$defs/const_not_anchor"
189+
}
190+
},
191+
"tests": [
192+
{
193+
"description": "skip traversing definition for a valid result",
194+
"data": "skip not_a_real_anchor",
195+
"valid": true
196+
},
197+
{
198+
"description": "const at const_not_anchor does not match",
199+
"data": 1,
200+
"valid": false
201+
}
202+
]
172203
}
173204
]

tests/draft2019-09/id.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,5 +252,36 @@
252252
"valid": false
253253
}
254254
]
255+
},
256+
{
257+
"description": "non-schema object containing an $id property",
258+
"schema": {
259+
"$defs": {
260+
"const_not_id": {
261+
"const": {
262+
"$id": "not_a_real_id"
263+
}
264+
}
265+
},
266+
"if": {
267+
"const": "skip not_a_real_id"
268+
},
269+
"then": true,
270+
"else" : {
271+
"$ref": "#/$defs/const_not_id"
272+
}
273+
},
274+
"tests": [
275+
{
276+
"description": "skip traversing definition for a valid result",
277+
"data": "skip not_a_real_id",
278+
"valid": true
279+
},
280+
{
281+
"description": "const at const_not_id does not match",
282+
"data": 1,
283+
"valid": false
284+
}
285+
]
255286
}
256287
]

tests/draft2019-09/ref.json

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,5 +575,70 @@
575575
"valid": false
576576
}
577577
]
578+
},
579+
{
580+
"description": "order of evaluation: $id and $ref",
581+
"schema": {
582+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
583+
"$id": "/base/base.json",
584+
"$ref": "int.json",
585+
"$defs": {
586+
"bigint": {
587+
"$comment": "canonical uri: /base/int.json",
588+
"$id": "int.json",
589+
"maximum": 10
590+
},
591+
"smallint": {
592+
"$comment": "canonical uri: /int.json",
593+
"$id": "/int.json",
594+
"maximum": 2
595+
}
596+
}
597+
},
598+
"tests": [
599+
{
600+
"description": "data is valid against first definition",
601+
"data": 5,
602+
"valid": true
603+
},
604+
{
605+
"description": "data is invalid against first definition",
606+
"data": 50,
607+
"valid": false
608+
}
609+
]
610+
},
611+
{
612+
"description": "order of evaluation: $id and $anchor and $ref",
613+
"schema": {
614+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
615+
"$id": "/base.json",
616+
"$ref": "#bigint",
617+
"$defs": {
618+
"bigint": {
619+
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
620+
"$anchor": "bigint",
621+
"maximum": 10
622+
},
623+
"smallint": {
624+
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
625+
"$id": "/",
626+
"$anchor": "bigint",
627+
"maximum": 2
628+
}
629+
}
630+
},
631+
"tests": [
632+
{
633+
"description": "data is valid against first definition",
634+
"data": 5,
635+
"valid": true
636+
},
637+
{
638+
"description": "data is invalid against first definition",
639+
"data": 50,
640+
"valid": false
641+
}
642+
]
578643
}
579644
]

tests/draft6/id.json

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,67 @@
4848
"valid": false
4949
}
5050
]
51+
},
52+
{
53+
"description": "non-schema object containing a plain-name $id property",
54+
"schema": {
55+
"$defs": {
56+
"const_not_anchor": {
57+
"const": {
58+
"$id": "#not_a_real_anchor"
59+
}
60+
}
61+
},
62+
"if": {
63+
"const": "skip not_a_real_anchor"
64+
},
65+
"then": true,
66+
"else" : {
67+
"$ref": "#/$defs/const_not_anchor"
68+
}
69+
},
70+
"tests": [
71+
{
72+
"description": "skip traversing definition for a valid result",
73+
"data": "skip not_a_real_anchor",
74+
"valid": true
75+
},
76+
{
77+
"description": "const at const_not_anchor does not match",
78+
"data": 1,
79+
"valid": false
80+
}
81+
]
82+
},
83+
{
84+
"description": "non-schema object containing an $id property",
85+
"schema": {
86+
"$defs": {
87+
"const_not_id": {
88+
"const": {
89+
"$id": "not_a_real_id"
90+
}
91+
}
92+
},
93+
"if": {
94+
"const": "skip not_a_real_id"
95+
},
96+
"then": true,
97+
"else" : {
98+
"$ref": "#/$defs/const_not_id"
99+
}
100+
},
101+
"tests": [
102+
{
103+
"description": "skip traversing definition for a valid result",
104+
"data": "skip not_a_real_id",
105+
"valid": true
106+
},
107+
{
108+
"description": "const at const_not_id does not match",
109+
"data": 1,
110+
"valid": false
111+
}
112+
]
51113
}
52-
53114
]

tests/draft7/id.json

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,67 @@
4848
"valid": false
4949
}
5050
]
51+
},
52+
{
53+
"description": "non-schema object containing a plain-name $id property",
54+
"schema": {
55+
"$defs": {
56+
"const_not_anchor": {
57+
"const": {
58+
"$id": "#not_a_real_anchor"
59+
}
60+
}
61+
},
62+
"if": {
63+
"const": "skip not_a_real_anchor"
64+
},
65+
"then": true,
66+
"else" : {
67+
"$ref": "#/$defs/const_not_anchor"
68+
}
69+
},
70+
"tests": [
71+
{
72+
"description": "skip traversing definition for a valid result",
73+
"data": "skip not_a_real_anchor",
74+
"valid": true
75+
},
76+
{
77+
"description": "const at const_not_anchor does not match",
78+
"data": 1,
79+
"valid": false
80+
}
81+
]
82+
},
83+
{
84+
"description": "non-schema object containing an $id property",
85+
"schema": {
86+
"$defs": {
87+
"const_not_id": {
88+
"const": {
89+
"$id": "not_a_real_id"
90+
}
91+
}
92+
},
93+
"if": {
94+
"const": "skip not_a_real_id"
95+
},
96+
"then": true,
97+
"else" : {
98+
"$ref": "#/$defs/const_not_id"
99+
}
100+
},
101+
"tests": [
102+
{
103+
"description": "skip traversing definition for a valid result",
104+
"data": "skip not_a_real_id",
105+
"valid": true
106+
},
107+
{
108+
"description": "const at const_not_id does not match",
109+
"data": 1,
110+
"valid": false
111+
}
112+
]
51113
}
52-
53114
]

tests/draft7/ref.json

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,5 +644,69 @@
644644
"valid": false
645645
}
646646
]
647+
},
648+
{
649+
"description": "order of evaluation: $id and $ref",
650+
"schema": {
651+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
652+
"$id": "/base/base.json",
653+
"$ref": "int.json",
654+
"$defs": {
655+
"bigint": {
656+
"$comment": "canonical uri: /base/int.json",
657+
"$id": "int.json",
658+
"maximum": 10
659+
},
660+
"smallint": {
661+
"$comment": "canonical uri: /int.json",
662+
"$id": "/int.json",
663+
"maximum": 2
664+
}
665+
}
666+
},
667+
"tests": [
668+
{
669+
"description": "data is valid against first definition",
670+
"data": 5,
671+
"valid": true
672+
},
673+
{
674+
"description": "data is invalid against first definition",
675+
"data": 50,
676+
"valid": false
677+
}
678+
]
679+
},
680+
{
681+
"description": "order of evaluation: plain-name $id and $ref",
682+
"schema": {
683+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
684+
"$id": "/base.json",
685+
"$ref": "#bigint",
686+
"$defs": {
687+
"bigint": {
688+
"$comment": "canonical uri: /base.json#/$defs/bigint; another valid uri for this location: /base.json#bigint",
689+
"$id": "#bigint",
690+
"maximum": 10
691+
},
692+
"smallint": {
693+
"$comment": "canonical uri: /#/$defs/smallint; another valid uri for this location: /#bigint",
694+
"$id": "/#bigint",
695+
"maximum": 2
696+
}
697+
}
698+
},
699+
"tests": [
700+
{
701+
"description": "data is valid against first definition",
702+
"data": 5,
703+
"valid": true
704+
},
705+
{
706+
"description": "data is invalid against first definition",
707+
"data": 50,
708+
"valid": false
709+
}
710+
]
647711
}
648712
]

0 commit comments

Comments
 (0)