Skip to content

Commit 1326f36

Browse files
Merge pull request #493 from json-schema-org/ether/id-sibling-to-ref
test that sibling $ids to $refs are ignored
2 parents 2f6a498 + b9bddc9 commit 1326f36

File tree

4 files changed

+144
-0
lines changed

4 files changed

+144
-0
lines changed

tests/draft3/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,42 @@
200200
}
201201
]
202202
},
203+
{
204+
"description": "$ref prevents a sibling $id from changing the base uri",
205+
"schema": {
206+
"$id": "http://localhost:1234/sibling_id/base/",
207+
"definitions": {
208+
"foo": {
209+
"$id": "http://localhost:1234/sibling_id/foo.json",
210+
"minimum": 2
211+
},
212+
"base_foo": {
213+
"$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
214+
"$id": "foo.json",
215+
"minimum": 5
216+
}
217+
},
218+
"allOf": [
219+
{
220+
"$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json",
221+
"$id": "http://localhost:1234/sibling_id/",
222+
"$ref": "foo.json"
223+
}
224+
]
225+
},
226+
"tests": [
227+
{
228+
"description": "$ref resolves to /definitions/foo, data validates",
229+
"data": 10,
230+
"valid": true
231+
},
232+
{
233+
"description": "$ref resolves to /definitions/foo, data does not validate",
234+
"data": 1,
235+
"valid": false
236+
}
237+
]
238+
},
203239
{
204240
"description": "remote ref, containing refs itself",
205241
"schema": {"$ref": "http://json-schema.org/draft-03/schema#"},

tests/draft4/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@
175175
}
176176
]
177177
},
178+
{
179+
"description": "$ref prevents a sibling $id from changing the base uri",
180+
"schema": {
181+
"$id": "http://localhost:1234/sibling_id/base/",
182+
"definitions": {
183+
"foo": {
184+
"$id": "http://localhost:1234/sibling_id/foo.json",
185+
"minimum": 2
186+
},
187+
"base_foo": {
188+
"$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
189+
"$id": "foo.json",
190+
"minimum": 5
191+
}
192+
},
193+
"allOf": [
194+
{
195+
"$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json",
196+
"$id": "http://localhost:1234/sibling_id/",
197+
"$ref": "foo.json"
198+
}
199+
]
200+
},
201+
"tests": [
202+
{
203+
"description": "$ref resolves to /definitions/foo, data validates",
204+
"data": 10,
205+
"valid": true
206+
},
207+
{
208+
"description": "$ref resolves to /definitions/foo, data does not validate",
209+
"data": 1,
210+
"valid": false
211+
}
212+
]
213+
},
178214
{
179215
"description": "remote ref, containing refs itself",
180216
"schema": {"$ref": "http://json-schema.org/draft-04/schema#"},

tests/draft6/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@
175175
}
176176
]
177177
},
178+
{
179+
"description": "$ref prevents a sibling $id from changing the base uri",
180+
"schema": {
181+
"$id": "http://localhost:1234/sibling_id/base/",
182+
"definitions": {
183+
"foo": {
184+
"$id": "http://localhost:1234/sibling_id/foo.json",
185+
"minimum": 2
186+
},
187+
"base_foo": {
188+
"$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
189+
"$id": "foo.json",
190+
"minimum": 5
191+
}
192+
},
193+
"allOf": [
194+
{
195+
"$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json",
196+
"$id": "http://localhost:1234/sibling_id/",
197+
"$ref": "foo.json"
198+
}
199+
]
200+
},
201+
"tests": [
202+
{
203+
"description": "$ref resolves to /definitions/foo, data validates",
204+
"data": 10,
205+
"valid": true
206+
},
207+
{
208+
"description": "$ref resolves to /definitions/foo, data does not validate",
209+
"data": 1,
210+
"valid": false
211+
}
212+
]
213+
},
178214
{
179215
"description": "remote ref, containing refs itself",
180216
"schema": {"$ref": "http://json-schema.org/draft-06/schema#"},

tests/draft7/ref.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,42 @@
175175
}
176176
]
177177
},
178+
{
179+
"description": "$ref prevents a sibling $id from changing the base uri",
180+
"schema": {
181+
"$id": "http://localhost:1234/sibling_id/base/",
182+
"definitions": {
183+
"foo": {
184+
"$id": "http://localhost:1234/sibling_id/foo.json",
185+
"minimum": 2
186+
},
187+
"base_foo": {
188+
"$comment": "this canonical uri is http://localhost:1234/sibling_id/base/foo.json",
189+
"$id": "foo.json",
190+
"minimum": 5
191+
}
192+
},
193+
"allOf": [
194+
{
195+
"$comment": "$ref resolves to http://localhost:1234/sibling_id/base/foo.json, not ttp://localhost:1234/sibling_id/foo.json",
196+
"$id": "http://localhost:1234/sibling_id/",
197+
"$ref": "foo.json"
198+
}
199+
]
200+
},
201+
"tests": [
202+
{
203+
"description": "$ref resolves to /definitions/foo, data validates",
204+
"data": 10,
205+
"valid": true
206+
},
207+
{
208+
"description": "$ref resolves to /definitions/foo, data does not validate",
209+
"data": 1,
210+
"valid": false
211+
}
212+
]
213+
},
178214
{
179215
"description": "remote ref, containing refs itself",
180216
"schema": {"$ref": "http://json-schema.org/draft-07/schema#"},

0 commit comments

Comments
 (0)