Skip to content

Commit de3f769

Browse files
committed
Add tests for some more differing URI scenarios.
Covers: * A $ref to an absolute URI present in the retrieved schema * A schema with URN $id with a nested $ref * Retrieving a schema with a different $id than the retrieval URI * Retrieving a schema with $ref whose retrieval URI was an HTTP URI but whose $id is an URN (These involve sibling $refs so don't apply to pre-2019). Missing is a test for an URN retrieval URL, which unfortunately we have no way of communicating at the minute. Refs: #578 (comment)
1 parent 4cfead7 commit de3f769

File tree

9 files changed

+238
-0
lines changed

9 files changed

+238
-0
lines changed

remotes/different-id-ref-string.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$id": "http://localhost:1234/real-id-ref-string.json",
3+
"$defs": {"bar": {"type": "string"}},
4+
"$ref": "#/$defs/bar"
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"$defs": {
3+
"bar": {
4+
"$id": "http://localhost:1234/the-nested-id.json",
5+
"type": "string"
6+
}
7+
},
8+
"$ref": "http://localhost:1234/the-nested-id.json"
9+
}

remotes/urn-ref-string.json

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$id": "urn:uuid:feebdaed-ffff-0000-ffff-0000deadbeef",
3+
"$defs": {"bar": {"type": "string"}},
4+
"$ref": "#/$defs/bar"
5+
}

tests/draft-next/ref.json

+25
Original file line numberDiff line numberDiff line change
@@ -830,5 +830,30 @@
830830
"valid": false
831831
}
832832
]
833+
},
834+
{
835+
"description": "URN ref with nested pointer ref",
836+
"schema": {
837+
"$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
838+
"$defs": {
839+
"foo": {
840+
"$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
841+
"$defs": {"bar": {"type": "string"}},
842+
"$ref": "#/$defs/bar"
843+
}
844+
}
845+
},
846+
"tests": [
847+
{
848+
"description": "a string is valid",
849+
"data": "bar",
850+
"valid": true
851+
},
852+
{
853+
"description": "a non-string is invalid",
854+
"data": 12,
855+
"valid": false
856+
}
857+
]
833858
}
834859
]

tests/draft-next/refRemote.json

+48
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,53 @@
229229
"valid": true
230230
}
231231
]
232+
},
233+
{
234+
"description": "remote HTTP ref with different $id",
235+
"schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"},
236+
"tests": [
237+
{
238+
"description": "number is invalid",
239+
"data": 1,
240+
"valid": false
241+
},
242+
{
243+
"description": "string is valid",
244+
"data": "foo",
245+
"valid": true
246+
}
247+
]
248+
},
249+
{
250+
"description": "remote HTTP ref with different URN $id",
251+
"schema": {"$ref": "http://localhost:1234/urn-ref-string.json"},
252+
"tests": [
253+
{
254+
"description": "number is invalid",
255+
"data": 1,
256+
"valid": false
257+
},
258+
{
259+
"description": "string is valid",
260+
"data": "foo",
261+
"valid": true
262+
}
263+
]
264+
},
265+
{
266+
"description": "remote HTTP ref with nested absolute ref",
267+
"schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"},
268+
"tests": [
269+
{
270+
"description": "number is invalid",
271+
"data": 1,
272+
"valid": false
273+
},
274+
{
275+
"description": "string is valid",
276+
"data": "foo",
277+
"valid": true
278+
}
279+
]
232280
}
233281
]

tests/draft2019-09/ref.json

+25
Original file line numberDiff line numberDiff line change
@@ -830,5 +830,30 @@
830830
"valid": false
831831
}
832832
]
833+
},
834+
{
835+
"description": "URN ref with nested pointer ref",
836+
"schema": {
837+
"$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
838+
"$defs": {
839+
"foo": {
840+
"$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
841+
"$defs": {"bar": {"type": "string"}},
842+
"$ref": "#/$defs/bar"
843+
}
844+
}
845+
},
846+
"tests": [
847+
{
848+
"description": "a string is valid",
849+
"data": "bar",
850+
"valid": true
851+
},
852+
{
853+
"description": "a non-string is invalid",
854+
"data": 12,
855+
"valid": false
856+
}
857+
]
833858
}
834859
]

tests/draft2019-09/refRemote.json

+48
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,53 @@
229229
"valid": true
230230
}
231231
]
232+
},
233+
{
234+
"description": "remote HTTP ref with different $id",
235+
"schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"},
236+
"tests": [
237+
{
238+
"description": "number is invalid",
239+
"data": 1,
240+
"valid": false
241+
},
242+
{
243+
"description": "string is valid",
244+
"data": "foo",
245+
"valid": true
246+
}
247+
]
248+
},
249+
{
250+
"description": "remote HTTP ref with different URN $id",
251+
"schema": {"$ref": "http://localhost:1234/urn-ref-string.json"},
252+
"tests": [
253+
{
254+
"description": "number is invalid",
255+
"data": 1,
256+
"valid": false
257+
},
258+
{
259+
"description": "string is valid",
260+
"data": "foo",
261+
"valid": true
262+
}
263+
]
264+
},
265+
{
266+
"description": "remote HTTP ref with nested absolute ref",
267+
"schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"},
268+
"tests": [
269+
{
270+
"description": "number is invalid",
271+
"data": 1,
272+
"valid": false
273+
},
274+
{
275+
"description": "string is valid",
276+
"data": "foo",
277+
"valid": true
278+
}
279+
]
232280
}
233281
]

tests/draft2020-12/ref.json

+25
Original file line numberDiff line numberDiff line change
@@ -830,5 +830,30 @@
830830
"valid": false
831831
}
832832
]
833+
},
834+
{
835+
"description": "URN ref with nested pointer ref",
836+
"schema": {
837+
"$ref": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
838+
"$defs": {
839+
"foo": {
840+
"$id": "urn:uuid:deadbeef-4321-ffff-ffff-1234feebdaed",
841+
"$defs": {"bar": {"type": "string"}},
842+
"$ref": "#/$defs/bar"
843+
}
844+
}
845+
},
846+
"tests": [
847+
{
848+
"description": "a string is valid",
849+
"data": "bar",
850+
"valid": true
851+
},
852+
{
853+
"description": "a non-string is invalid",
854+
"data": 12,
855+
"valid": false
856+
}
857+
]
833858
}
834859
]

tests/draft2020-12/refRemote.json

+48
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,53 @@
229229
"valid": true
230230
}
231231
]
232+
},
233+
{
234+
"description": "remote HTTP ref with different $id",
235+
"schema": {"$ref": "http://localhost:1234/different-id-ref-string.json"},
236+
"tests": [
237+
{
238+
"description": "number is invalid",
239+
"data": 1,
240+
"valid": false
241+
},
242+
{
243+
"description": "string is valid",
244+
"data": "foo",
245+
"valid": true
246+
}
247+
]
248+
},
249+
{
250+
"description": "remote HTTP ref with different URN $id",
251+
"schema": {"$ref": "http://localhost:1234/urn-ref-string.json"},
252+
"tests": [
253+
{
254+
"description": "number is invalid",
255+
"data": 1,
256+
"valid": false
257+
},
258+
{
259+
"description": "string is valid",
260+
"data": "foo",
261+
"valid": true
262+
}
263+
]
264+
},
265+
{
266+
"description": "remote HTTP ref with nested absolute ref",
267+
"schema": {"$ref": "http://localhost:1234/nested-absolute-ref-to-string.json"},
268+
"tests": [
269+
{
270+
"description": "number is invalid",
271+
"data": 1,
272+
"valid": false
273+
},
274+
{
275+
"description": "string is valid",
276+
"data": "foo",
277+
"valid": true
278+
}
279+
]
232280
}
233281
]

0 commit comments

Comments
 (0)