Skip to content

Commit 415bda9

Browse files
committed
tests for $ref using base URI learned from $id
1 parent 6afa9b3 commit 415bda9

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed

remotes/subSchemas-ids.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"$id": "http://localhost:1234/subSchemas-ids.json",
3+
"allOf": [
4+
{"$ref": "#/$defs/referencing"}
5+
],
6+
"$defs": {
7+
"referencing": {
8+
"$id": "referencing.json",
9+
"allOf": [
10+
{"$ref": "#/$defs/referenced"}
11+
],
12+
"$defs": {
13+
"referenced": {
14+
"enum": ["should-be-valid"]
15+
}
16+
}
17+
},
18+
"referenced": {
19+
"enum": ["should-NOT-be-valid"]
20+
}
21+
}
22+
}

tests/draft2019-09/ref.json

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1055,5 +1055,49 @@
10551055
"valid": false
10561056
}
10571057
]
1058-
}
1058+
},
1059+
{
1060+
"description": "$ref uses base URI learned from $id",
1061+
"schema": {
1062+
"allOf": [
1063+
{"$ref": "#/$defs/referencing"}
1064+
],
1065+
"$defs": {
1066+
"referencing": {
1067+
"$id": "/referencing.json",
1068+
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
1069+
"allOf": [
1070+
{"$ref": "#/$defs/referenced"}
1071+
],
1072+
"$defs": {
1073+
"referenced": {
1074+
"$comment": "This schema IS being referenced",
1075+
"enum": ["should-be-valid"]
1076+
}
1077+
}
1078+
},
1079+
"referenced": {
1080+
"$comment": "This schema is NOT being referenced",
1081+
"enum": ["should-NOT-be-valid"]
1082+
}
1083+
}
1084+
},
1085+
"tests": [
1086+
{
1087+
"description": "the correct schema is referenced",
1088+
"data": "should-be-valid",
1089+
"valid": true
1090+
},
1091+
{
1092+
"description": "the incorrect schema is not referenced",
1093+
"data": "should-NOT-be-valid",
1094+
"valid": false
1095+
},
1096+
{
1097+
"description": "sanity check that other invalid values aren't accepted either",
1098+
"data": "bogus",
1099+
"valid": false
1100+
}
1101+
]
1102+
}
10591103
]

tests/draft2019-09/refRemote.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,31 @@
310310
"valid": true
311311
}
312312
]
313+
},
314+
{
315+
"description": "$ref uses base URI learned from $id in remote schemas",
316+
"schema": {
317+
"$id": "http://localhost:1234/",
318+
"allOf": [
319+
{"$ref": "subSchemas-ids.json"}
320+
]
321+
},
322+
"tests": [
323+
{
324+
"description": "the correct schema is referenced",
325+
"data": "should-be-valid",
326+
"valid": true
327+
},
328+
{
329+
"description": "the incorrect schema is not referenced",
330+
"data": "should-NOT-be-valid",
331+
"valid": false
332+
},
333+
{
334+
"description": "sanity check that other invalid values aren't accepted either",
335+
"data": "bogus",
336+
"valid": false
337+
}
338+
]
313339
}
314340
]

tests/draft7/ref.json

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1012,5 +1012,49 @@
10121012
"valid": false
10131013
}
10141014
]
1015+
},
1016+
{
1017+
"description": "$ref uses base URI learned from $id",
1018+
"schema": {
1019+
"allOf": [
1020+
{"$ref": "#/$defs/referencing"}
1021+
],
1022+
"$defs": {
1023+
"referencing": {
1024+
"$id": "/referencing.json",
1025+
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
1026+
"allOf": [
1027+
{"$ref": "#/$defs/referenced"}
1028+
],
1029+
"$defs": {
1030+
"referenced": {
1031+
"$comment": "This schema IS being referenced",
1032+
"enum": ["should-be-valid"]
1033+
}
1034+
}
1035+
},
1036+
"referenced": {
1037+
"$comment": "This schema is NOT being referenced",
1038+
"enum": ["should-NOT-be-valid"]
1039+
}
1040+
}
1041+
},
1042+
"tests": [
1043+
{
1044+
"description": "the correct schema is referenced",
1045+
"data": "should-be-valid",
1046+
"valid": true
1047+
},
1048+
{
1049+
"description": "the incorrect schema is not referenced",
1050+
"data": "should-NOT-be-valid",
1051+
"valid": false
1052+
},
1053+
{
1054+
"description": "sanity check that other invalid values aren't accepted either",
1055+
"data": "bogus",
1056+
"valid": false
1057+
}
1058+
]
10151059
}
10161060
]

tests/draft7/refRemote.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,5 +235,31 @@
235235
"valid": true
236236
}
237237
]
238+
},
239+
{
240+
"description": "$ref uses base URI learned from $id in remote schemas",
241+
"schema": {
242+
"$id": "http://localhost:1234/",
243+
"allOf": [
244+
{"$ref": "subSchemas-ids.json"}
245+
]
246+
},
247+
"tests": [
248+
{
249+
"description": "the correct schema is referenced",
250+
"data": "should-be-valid",
251+
"valid": true
252+
},
253+
{
254+
"description": "the incorrect schema is not referenced",
255+
"data": "should-NOT-be-valid",
256+
"valid": false
257+
},
258+
{
259+
"description": "sanity check that other invalid values aren't accepted either",
260+
"data": "bogus",
261+
"valid": false
262+
}
263+
]
238264
}
239265
]

0 commit comments

Comments
 (0)