Skip to content

Commit a0097d4

Browse files
authored
Merge pull request #679 from json-schema-org/gregsdennis/ref-to-ref-to-non-local-target
added tests for checking the entire resource for anchors instead of just the local subschema
2 parents 8cdfac4 + 8b69249 commit a0097d4

File tree

10 files changed

+155
-0
lines changed

10 files changed

+155
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$id": "http://localhost:1234/draft2019-09/detached-ref",
3+
"$schema": "https://json-schema.org/draft/2019-09/schema",
4+
"$defs": {
5+
"foo": {
6+
"$ref": "#detached"
7+
},
8+
"detached": {
9+
"$anchor": "detached",
10+
"type": "integer"
11+
}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$id": "http://localhost:1234/draft2020-12/detached-dynamicref",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"$defs": {
5+
"foo": {
6+
"$dynamicRef": "#detached"
7+
},
8+
"detached": {
9+
"$dynamicAnchor": "detached",
10+
"type": "integer"
11+
}
12+
}
13+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$id": "http://localhost:1234/draft2020-12/detached-ref",
3+
"$schema": "https://json-schema.org/draft/2020-12/schema",
4+
"$defs": {
5+
"foo": {
6+
"$ref": "#detached"
7+
},
8+
"detached": {
9+
"$anchor": "detached",
10+
"type": "integer"
11+
}
12+
}
13+
}

remotes/draft6/detached-ref.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$id": "http://localhost:1234/draft6/detached-ref",
3+
"$schema": "http://json-schema.org/draft-06/schema#",
4+
"definitions": {
5+
"foo": {
6+
"$ref": "#detached"
7+
},
8+
"detached": {
9+
"$id": "#detached",
10+
"type": "integer"
11+
}
12+
}
13+
}

remotes/draft7/detached-ref.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"$id": "http://localhost:1234/draft7/detached-ref",
3+
"$schema": "http://json-schema.org/draft-07/schema#",
4+
"definitions": {
5+
"foo": {
6+
"$ref": "#detached"
7+
},
8+
"detached": {
9+
"$id": "#detached",
10+
"type": "integer"
11+
}
12+
}
13+
}

tests/draft2019-09/ref.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,5 +1055,23 @@
10551055
"valid": false
10561056
}
10571057
]
1058+
},
1059+
{
1060+
"description": "$ref to $ref finds detached $anchor",
1061+
"schema": {
1062+
"$ref": "http://localhost:1234/draft2019-09/detached-ref#/$defs/foo"
1063+
},
1064+
"tests": [
1065+
{
1066+
"description": "number is valid",
1067+
"data": 1,
1068+
"valid": true
1069+
},
1070+
{
1071+
"description": "non-number is invalid",
1072+
"data": "a",
1073+
"valid": false
1074+
}
1075+
]
10581076
}
10591077
]

tests/draft2020-12/dynamicRef.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,5 +708,23 @@
708708
"valid": true
709709
}
710710
]
711+
},
712+
{
713+
"description": "$ref to $dynamicRef finds detached $dynamicAnchor",
714+
"schema": {
715+
"$ref": "http://localhost:1234/draft2020-12/detached-dynamicref#/$defs/foo"
716+
},
717+
"tests": [
718+
{
719+
"description": "number is valid",
720+
"data": 1,
721+
"valid": true
722+
},
723+
{
724+
"description": "non-number is invalid",
725+
"data": "a",
726+
"valid": false
727+
}
728+
]
711729
}
712730
]

tests/draft2020-12/ref.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,5 +1055,23 @@
10551055
"valid": false
10561056
}
10571057
]
1058+
},
1059+
{
1060+
"description": "$ref to $ref finds detached $anchor",
1061+
"schema": {
1062+
"$ref": "http://localhost:1234/draft2020-12/detached-ref#/$defs/foo"
1063+
},
1064+
"tests": [
1065+
{
1066+
"description": "number is valid",
1067+
"data": 1,
1068+
"valid": true
1069+
},
1070+
{
1071+
"description": "non-number is invalid",
1072+
"data": "a",
1073+
"valid": false
1074+
}
1075+
]
10581076
}
10591077
]

tests/draft6/ref.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,5 +925,23 @@
925925
"valid": false
926926
}
927927
]
928+
},
929+
{
930+
"description": "$ref to $ref finds location-independent $id",
931+
"schema": {
932+
"$ref": "http://localhost:1234/draft6/detached-ref#/definitions/foo"
933+
},
934+
"tests": [
935+
{
936+
"description": "number is valid",
937+
"data": 1,
938+
"valid": true
939+
},
940+
{
941+
"description": "non-number is invalid",
942+
"data": "a",
943+
"valid": false
944+
}
945+
]
928946
}
929947
]

tests/draft7/ref.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1039,5 +1039,23 @@
10391039
"valid": false
10401040
}
10411041
]
1042+
},
1043+
{
1044+
"description": "$ref to $ref finds location-independent $id",
1045+
"schema": {
1046+
"$ref": "http://localhost:1234/draft7/detached-ref#/definitions/foo"
1047+
},
1048+
"tests": [
1049+
{
1050+
"description": "number is valid",
1051+
"data": 1,
1052+
"valid": true
1053+
},
1054+
{
1055+
"description": "non-number is invalid",
1056+
"data": "a",
1057+
"valid": false
1058+
}
1059+
]
10421060
}
10431061
]

0 commit comments

Comments
 (0)