Skip to content

Commit

Permalink
tests for $ref using base URI learned from $id
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangalamb committed Apr 26, 2023
1 parent 6afa9b3 commit 415bda9
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 1 deletion.
22 changes: 22 additions & 0 deletions remotes/subSchemas-ids.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"$id": "http://localhost:1234/subSchemas-ids.json",
"allOf": [
{"$ref": "#/$defs/referencing"}
],
"$defs": {
"referencing": {
"$id": "referencing.json",
"allOf": [
{"$ref": "#/$defs/referenced"}
],
"$defs": {
"referenced": {
"enum": ["should-be-valid"]
}
}
},
"referenced": {
"enum": ["should-NOT-be-valid"]
}
}
}
46 changes: 45 additions & 1 deletion tests/draft2019-09/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -1055,5 +1055,49 @@
"valid": false
}
]
}
},
{
"description": "$ref uses base URI learned from $id",
"schema": {
"allOf": [
{"$ref": "#/$defs/referencing"}
],
"$defs": {
"referencing": {
"$id": "/referencing.json",
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
"allOf": [
{"$ref": "#/$defs/referenced"}
],
"$defs": {
"referenced": {
"$comment": "This schema IS being referenced",
"enum": ["should-be-valid"]
}
}
},
"referenced": {
"$comment": "This schema is NOT being referenced",
"enum": ["should-NOT-be-valid"]
}
}
},
"tests": [
{
"description": "the correct schema is referenced",
"data": "should-be-valid",
"valid": true
},
{
"description": "the incorrect schema is not referenced",
"data": "should-NOT-be-valid",
"valid": false
},
{
"description": "sanity check that other invalid values aren't accepted either",
"data": "bogus",
"valid": false
}
]
}
]
26 changes: 26 additions & 0 deletions tests/draft2019-09/refRemote.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,5 +310,31 @@
"valid": true
}
]
},
{
"description": "$ref uses base URI learned from $id in remote schemas",
"schema": {
"$id": "http://localhost:1234/",
"allOf": [
{"$ref": "subSchemas-ids.json"}
]
},
"tests": [
{
"description": "the correct schema is referenced",
"data": "should-be-valid",
"valid": true
},
{
"description": "the incorrect schema is not referenced",
"data": "should-NOT-be-valid",
"valid": false
},
{
"description": "sanity check that other invalid values aren't accepted either",
"data": "bogus",
"valid": false
}
]
}
]
44 changes: 44 additions & 0 deletions tests/draft7/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -1012,5 +1012,49 @@
"valid": false
}
]
},
{
"description": "$ref uses base URI learned from $id",
"schema": {
"allOf": [
{"$ref": "#/$defs/referencing"}
],
"$defs": {
"referencing": {
"$id": "/referencing.json",
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
"allOf": [
{"$ref": "#/$defs/referenced"}
],
"$defs": {
"referenced": {
"$comment": "This schema IS being referenced",
"enum": ["should-be-valid"]
}
}
},
"referenced": {
"$comment": "This schema is NOT being referenced",
"enum": ["should-NOT-be-valid"]
}
}
},
"tests": [
{
"description": "the correct schema is referenced",
"data": "should-be-valid",
"valid": true
},
{
"description": "the incorrect schema is not referenced",
"data": "should-NOT-be-valid",
"valid": false
},
{
"description": "sanity check that other invalid values aren't accepted either",
"data": "bogus",
"valid": false
}
]
}
]
26 changes: 26 additions & 0 deletions tests/draft7/refRemote.json
Original file line number Diff line number Diff line change
Expand Up @@ -235,5 +235,31 @@
"valid": true
}
]
},
{
"description": "$ref uses base URI learned from $id in remote schemas",
"schema": {
"$id": "http://localhost:1234/",
"allOf": [
{"$ref": "subSchemas-ids.json"}
]
},
"tests": [
{
"description": "the correct schema is referenced",
"data": "should-be-valid",
"valid": true
},
{
"description": "the incorrect schema is not referenced",
"data": "should-NOT-be-valid",
"valid": false
},
{
"description": "sanity check that other invalid values aren't accepted either",
"data": "bogus",
"valid": false
}
]
}
]

0 comments on commit 415bda9

Please sign in to comment.