Skip to content

Commit d45cc45

Browse files
committed
tests for $ref using base URI learned from $id
1 parent 817b724 commit d45cc45

File tree

7 files changed

+186
-1
lines changed

7 files changed

+186
-1
lines changed

bin/jsonschema_suite

+22
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,28 @@ REMOTES = {
5151
u"refToInteger": {u"$ref": u"#/$defs/integer"},
5252
}
5353
},
54+
"subSchemas-ids.json": {
55+
u"$id": u"http://localhost:1234/subSchemas-ids.json",
56+
u"allOf": [
57+
{u"$ref": u"#/$defs/referencing"}
58+
],
59+
u"$defs": {
60+
u"referencing": {
61+
u"$id": u"referencing.json",
62+
u"allOf": [
63+
{u"$ref": u"#/$defs/referenced"}
64+
],
65+
u"$defs": {
66+
u"referenced": {
67+
u"enum": [u"should-be-valid"]
68+
}
69+
}
70+
},
71+
u"referenced": {
72+
u"enum": [u"should-NOT-be-valid"]
73+
}
74+
}
75+
},
5476
"folder/folderInteger.json": {u"type": u"integer"}
5577
}
5678
REMOTES_DIR = os.path.join(ROOT_DIR, "remotes")

index.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const refs = {
88
'http://localhost:1234/subSchemas.json': require('./remotes/subSchemas.json'),
99
'http://localhost:1234/folder/folderInteger.json': require('./remotes/folder/folderInteger.json'),
1010
'http://localhost:1234/name.json': require('./remotes/name.json'),
11-
'http://localhost:1234/name-defs.json': require('./remotes/name-defs.json')
11+
'http://localhost:1234/name-defs.json': require('./remotes/name-defs.json'),
12+
'http://localhost:1234/subSchemas-ids.json': require('./remotes/subSchemas-ids.json')
1213
};
1314

1415
const SKIP = {

remotes/subSchemas-ids.json

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

+44
Original file line numberDiff line numberDiff line change
@@ -382,5 +382,49 @@
382382
"valid": false
383383
}
384384
]
385+
},
386+
{
387+
"description": "$ref uses base URI learned from $id",
388+
"schema": {
389+
"allOf": [
390+
{"$ref": "#/$defs/referencing"}
391+
],
392+
"$defs": {
393+
"referencing": {
394+
"$id": "/referencing.json",
395+
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
396+
"allOf": [
397+
{"$ref": "#/$defs/referenced"}
398+
],
399+
"$defs": {
400+
"referenced": {
401+
"$comment": "This schema IS being referenced",
402+
"enum": ["should-be-valid"]
403+
}
404+
}
405+
},
406+
"referenced": {
407+
"$comment": "This schema is NOT being referenced",
408+
"enum": ["should-NOT-be-valid"]
409+
}
410+
}
411+
},
412+
"tests": [
413+
{
414+
"description": "the correct schema is referenced",
415+
"data": "should-be-valid",
416+
"valid": true
417+
},
418+
{
419+
"description": "the incorrect schema is not referenced",
420+
"data": "should-NOT-be-valid",
421+
"valid": false
422+
},
423+
{
424+
"description": "sanity check that other invalid values aren't accepted either",
425+
"data": "bogus",
426+
"valid": false
427+
}
428+
]
385429
}
386430
]

tests/draft2019-09/refRemote.json

+26
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,31 @@
163163
"valid": false
164164
}
165165
]
166+
},
167+
{
168+
"description": "$ref uses base URI learned from $id in remote schemas",
169+
"schema": {
170+
"$id": "http://localhost:1234/",
171+
"allOf": [
172+
{"$ref": "subSchemas-ids.json"}
173+
]
174+
},
175+
"tests": [
176+
{
177+
"description": "the correct schema is referenced",
178+
"data": "should-be-valid",
179+
"valid": true
180+
},
181+
{
182+
"description": "the incorrect schema is not referenced",
183+
"data": "should-NOT-be-valid",
184+
"valid": false
185+
},
186+
{
187+
"description": "sanity check that other invalid values aren't accepted either",
188+
"data": "bogus",
189+
"valid": false
190+
}
191+
]
166192
}
167193
]

tests/draft7/ref.json

+44
Original file line numberDiff line numberDiff line change
@@ -439,5 +439,49 @@
439439
"valid": false
440440
}
441441
]
442+
},
443+
{
444+
"description": "$ref uses base URI learned from $id",
445+
"schema": {
446+
"allOf": [
447+
{"$ref": "#/$defs/referencing"}
448+
],
449+
"$defs": {
450+
"referencing": {
451+
"$id": "/referencing.json",
452+
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
453+
"allOf": [
454+
{"$ref": "#/$defs/referenced"}
455+
],
456+
"$defs": {
457+
"referenced": {
458+
"$comment": "This schema IS being referenced",
459+
"enum": ["should-be-valid"]
460+
}
461+
}
462+
},
463+
"referenced": {
464+
"$comment": "This schema is NOT being referenced",
465+
"enum": ["should-NOT-be-valid"]
466+
}
467+
}
468+
},
469+
"tests": [
470+
{
471+
"description": "the correct schema is referenced",
472+
"data": "should-be-valid",
473+
"valid": true
474+
},
475+
{
476+
"description": "the incorrect schema is not referenced",
477+
"data": "should-NOT-be-valid",
478+
"valid": false
479+
},
480+
{
481+
"description": "sanity check that other invalid values aren't accepted either",
482+
"data": "bogus",
483+
"valid": false
484+
}
485+
]
442486
}
443487
]

tests/draft7/refRemote.json

+26
Original file line numberDiff line numberDiff line change
@@ -167,5 +167,31 @@
167167
"valid": false
168168
}
169169
]
170+
},
171+
{
172+
"description": "$ref uses base URI learned from $id in remote schemas",
173+
"schema": {
174+
"$id": "http://localhost:1234/",
175+
"allOf": [
176+
{"$ref": "subSchemas-ids.json"}
177+
]
178+
},
179+
"tests": [
180+
{
181+
"description": "the correct schema is referenced",
182+
"data": "should-be-valid",
183+
"valid": true
184+
},
185+
{
186+
"description": "the incorrect schema is not referenced",
187+
"data": "should-NOT-be-valid",
188+
"valid": false
189+
},
190+
{
191+
"description": "sanity check that other invalid values aren't accepted either",
192+
"data": "bogus",
193+
"valid": false
194+
}
195+
]
170196
}
171197
]

0 commit comments

Comments
 (0)