Skip to content

Commit 8b69249

Browse files
committed
added tests for checking the entire resource for anchors instead of just the local subschema
1 parent b069ac3 commit 8b69249

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
@@ -669,5 +669,23 @@
669669
"valid": true
670670
}
671671
]
672+
},
673+
{
674+
"description": "$ref to $dynamicRef finds detached $dynamicAnchor",
675+
"schema": {
676+
"$ref": "http://localhost:1234/draft2020-12/detached-dynamicref#/$defs/foo"
677+
},
678+
"tests": [
679+
{
680+
"description": "number is valid",
681+
"data": 1,
682+
"valid": true
683+
},
684+
{
685+
"description": "non-number is invalid",
686+
"data": "a",
687+
"valid": false
688+
}
689+
]
672690
}
673691
]

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)