Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for $ref using base URI learned from $id #403

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$defs is only a 2019-09 and later keyword. For draft 7, you'll need a copy of this file that uses definitions.

"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": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$defs should be definitions for draft 7

Copy link
Member

@Julian Julian Apr 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's weird that the sanity check for unknown keywords doesn't flag this, as that's the point of it, but I don't have time to look into why right this second.)

"referencing": {
"$id": "/referencing.json",
"$comment": "The $id here changes the base URI that $ref's value is resolved against",
"allOf": [
{"$ref": "#/$defs/referenced"}
],
"$defs": {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$defs -> definitions

"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
}
]
}
]