Skip to content

Commit 0b777ff

Browse files
committed
Merge branch 'ether/more-anchor-and-id-tests'
* ether/more-anchor-and-id-tests: Forward port the just-added tests to 2020 and next. squash: use a unique $id to prevent namespace collisions across tests some tests of the interactions between $id, $anchor and $ref
2 parents 07c45c0 + d593591 commit 0b777ff

File tree

12 files changed

+577
-6
lines changed

12 files changed

+577
-6
lines changed

tests/draft-next/anchor.json

+31
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/draft-next/id.json

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

tests/draft-next/ref.json

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

tests/draft2019-09/anchor.json

+31
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

+34-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
[
22
{
33
"description": "Invalid use of fragments in location-independent $id",
4-
"schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
4+
"schema": {
5+
"$ref": "https://json-schema.org/draft/2019-09/schema"
6+
},
57
"tests": [
68
{
79
"description": "Identifier name",
@@ -252,5 +254,36 @@
252254
"valid": false
253255
}
254256
]
257+
},
258+
{
259+
"description": "non-schema object containing an $id property",
260+
"schema": {
261+
"$defs": {
262+
"const_not_id": {
263+
"const": {
264+
"$id": "not_a_real_id"
265+
}
266+
}
267+
},
268+
"if": {
269+
"const": "skip not_a_real_id"
270+
},
271+
"then": true,
272+
"else" : {
273+
"$ref": "#/$defs/const_not_id"
274+
}
275+
},
276+
"tests": [
277+
{
278+
"description": "skip traversing definition for a valid result",
279+
"data": "skip not_a_real_id",
280+
"valid": true
281+
},
282+
{
283+
"description": "const at const_not_id does not match",
284+
"data": 1,
285+
"valid": false
286+
}
287+
]
255288
}
256289
]

tests/draft2019-09/ref.json

+70-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@
177177
},
178178
{
179179
"description": "remote ref, containing refs itself",
180-
"schema": {"$ref": "https://json-schema.org/draft/2019-09/schema"},
180+
"schema": {
181+
"$ref": "https://json-schema.org/draft/2019-09/schema"
182+
},
181183
"tests": [
182184
{
183185
"description": "remote ref valid",
@@ -298,7 +300,7 @@
298300
"tests": [
299301
{
300302
"description": "valid tree",
301-
"data": {
303+
"data": {
302304
"meta": "root",
303305
"nodes": [
304306
{
@@ -327,7 +329,7 @@
327329
},
328330
{
329331
"description": "invalid tree",
330-
"data": {
332+
"data": {
331333
"meta": "root",
332334
"nodes": [
333335
{
@@ -575,5 +577,70 @@
575577
"valid": false
576578
}
577579
]
580+
},
581+
{
582+
"description": "order of evaluation: $id and $ref",
583+
"schema": {
584+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
585+
"$id": "/ref-and-id1/base.json",
586+
"$ref": "int.json",
587+
"$defs": {
588+
"bigint": {
589+
"$comment": "canonical uri: /ref-and-id1/int.json",
590+
"$id": "int.json",
591+
"maximum": 10
592+
},
593+
"smallint": {
594+
"$comment": "canonical uri: /ref-and-id1-int.json",
595+
"$id": "/ref-and-id1-int.json",
596+
"maximum": 2
597+
}
598+
}
599+
},
600+
"tests": [
601+
{
602+
"description": "data is valid against first definition",
603+
"data": 5,
604+
"valid": true
605+
},
606+
{
607+
"description": "data is invalid against first definition",
608+
"data": 50,
609+
"valid": false
610+
}
611+
]
612+
},
613+
{
614+
"description": "order of evaluation: $id and $anchor and $ref",
615+
"schema": {
616+
"$comment": "$id must be evaluated before $ref to get the proper $ref destination",
617+
"$id": "/ref-and-id2/base.json",
618+
"$ref": "#bigint",
619+
"$defs": {
620+
"bigint": {
621+
"$comment": "canonical uri: /ref-and-id2/base.json/$defs/bigint; another valid uri for this location: /ref-and-id2/base.json#bigint",
622+
"$anchor": "bigint",
623+
"maximum": 10
624+
},
625+
"smallint": {
626+
"$comment": "canonical uri: /ref-and-id2#/$defs/smallint; another valid uri for this location: /ref-and-id2/#bigint",
627+
"$id": "/ref-and-id2/",
628+
"$anchor": "bigint",
629+
"maximum": 2
630+
}
631+
}
632+
},
633+
"tests": [
634+
{
635+
"description": "data is valid against first definition",
636+
"data": 5,
637+
"valid": true
638+
},
639+
{
640+
"description": "data is invalid against first definition",
641+
"data": 50,
642+
"valid": false
643+
}
644+
]
578645
}
579646
]

tests/draft2020-12/anchor.json

+31
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
]

0 commit comments

Comments
 (0)