Skip to content

Commit 64a3e7b

Browse files
authored
Merge pull request #721 from json-schema-org/gregsdennis/dynamicref-skips-resources
add tests for $dynamicRef skipping over resources
2 parents b9f14e6 + 9cd64ec commit 64a3e7b

File tree

4 files changed

+222
-0
lines changed

4 files changed

+222
-0
lines changed

tests/draft-next/dynamicRef.json

+55
Original file line numberDiff line numberDiff line change
@@ -642,5 +642,60 @@
642642
"valid": false
643643
}
644644
]
645+
},
646+
{
647+
"description": "$dynamicRef skips over intermediate resources - direct reference",
648+
"schema": {
649+
"$schema": "https://json-schema.org/draft/next/schema",
650+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main",
651+
"type": "object",
652+
"properties": {
653+
"bar-item": {
654+
"$ref": "item"
655+
}
656+
},
657+
"$defs": {
658+
"bar": {
659+
"$id": "bar",
660+
"type": "array",
661+
"items": {
662+
"$ref": "item"
663+
},
664+
"$defs": {
665+
"item": {
666+
"$id": "item",
667+
"type": "object",
668+
"properties": {
669+
"content": {
670+
"$dynamicRef": "#content"
671+
}
672+
},
673+
"$defs": {
674+
"defaultContent": {
675+
"$dynamicAnchor": "content",
676+
"type": "integer"
677+
}
678+
}
679+
},
680+
"content": {
681+
"$dynamicAnchor": "content",
682+
"type": "string"
683+
}
684+
}
685+
}
686+
}
687+
},
688+
"tests": [
689+
{
690+
"description": "integer property passes",
691+
"data": { "bar-item": { "content": 42 } },
692+
"valid": true
693+
},
694+
{
695+
"description": "string property fails",
696+
"data": { "bar-item": { "content": "value" } },
697+
"valid": false
698+
}
699+
]
645700
}
646701
]
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/next/schema",
6+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main",
7+
"type": "object",
8+
"properties": {
9+
"bar-item": {
10+
"$ref": "bar#/$defs/item"
11+
}
12+
},
13+
"$defs": {
14+
"bar": {
15+
"$id": "bar",
16+
"type": "array",
17+
"items": {
18+
"$ref": "item"
19+
},
20+
"$defs": {
21+
"item": {
22+
"$id": "item",
23+
"type": "object",
24+
"properties": {
25+
"content": {
26+
"$dynamicRef": "#content"
27+
}
28+
},
29+
"$defs": {
30+
"defaultContent": {
31+
"$dynamicAnchor": "content",
32+
"type": "integer"
33+
}
34+
}
35+
},
36+
"content": {
37+
"$dynamicAnchor": "content",
38+
"type": "string"
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"tests": [
45+
{
46+
"description": "integer property passes",
47+
"data": { "bar-item": { "content": 42 } },
48+
"valid": true
49+
},
50+
{
51+
"description": "string property fails",
52+
"data": { "bar-item": { "content": "value" } },
53+
"valid": false
54+
}
55+
]
56+
}]

tests/draft2020-12/dynamicRef.json

+55
Original file line numberDiff line numberDiff line change
@@ -756,5 +756,60 @@
756756
"valid": false
757757
}
758758
]
759+
},
760+
{
761+
"description": "$dynamicRef skips over intermediate resources - direct reference",
762+
"schema": {
763+
"$schema": "https://json-schema.org/draft/2020-12/schema",
764+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/main",
765+
"type": "object",
766+
"properties": {
767+
"bar-item": {
768+
"$ref": "item"
769+
}
770+
},
771+
"$defs": {
772+
"bar": {
773+
"$id": "bar",
774+
"type": "array",
775+
"items": {
776+
"$ref": "item"
777+
},
778+
"$defs": {
779+
"item": {
780+
"$id": "item",
781+
"type": "object",
782+
"properties": {
783+
"content": {
784+
"$dynamicRef": "#content"
785+
}
786+
},
787+
"$defs": {
788+
"defaultContent": {
789+
"$dynamicAnchor": "content",
790+
"type": "integer"
791+
}
792+
}
793+
},
794+
"content": {
795+
"$dynamicAnchor": "content",
796+
"type": "string"
797+
}
798+
}
799+
}
800+
}
801+
},
802+
"tests": [
803+
{
804+
"description": "integer property passes",
805+
"data": { "bar-item": { "content": 42 } },
806+
"valid": true
807+
},
808+
{
809+
"description": "string property fails",
810+
"data": { "bar-item": { "content": "value" } },
811+
"valid": false
812+
}
813+
]
759814
}
760815
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
[
2+
{
3+
"description": "$dynamicRef skips over intermediate resources - pointer reference across resource boundary",
4+
"schema": {
5+
"$schema": "https://json-schema.org/draft/2020-12/schema",
6+
"$id": "https://test.json-schema.org/dynamic-ref-skips-intermediate-resource/optional/main",
7+
"type": "object",
8+
"properties": {
9+
"bar-item": {
10+
"$ref": "bar#/$defs/item"
11+
}
12+
},
13+
"$defs": {
14+
"bar": {
15+
"$id": "bar",
16+
"type": "array",
17+
"items": {
18+
"$ref": "item"
19+
},
20+
"$defs": {
21+
"item": {
22+
"$id": "item",
23+
"type": "object",
24+
"properties": {
25+
"content": {
26+
"$dynamicRef": "#content"
27+
}
28+
},
29+
"$defs": {
30+
"defaultContent": {
31+
"$dynamicAnchor": "content",
32+
"type": "integer"
33+
}
34+
}
35+
},
36+
"content": {
37+
"$dynamicAnchor": "content",
38+
"type": "string"
39+
}
40+
}
41+
}
42+
}
43+
},
44+
"tests": [
45+
{
46+
"description": "integer property passes",
47+
"data": { "bar-item": { "content": 42 } },
48+
"valid": true
49+
},
50+
{
51+
"description": "string property fails",
52+
"data": { "bar-item": { "content": "value" } },
53+
"valid": false
54+
}
55+
]
56+
}]

0 commit comments

Comments
 (0)