Skip to content

Add tests for refs with relative uris #457

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

Merged
merged 2 commits into from
Jun 1, 2021
Merged
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
11 changes: 11 additions & 0 deletions remotes/ref-and-definitions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$id": "http://localhost:1234/ref-and-definitions.json",
"definitions": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"allOf": [ { "$ref": "#/definitions/inner" } ]
}
11 changes: 11 additions & 0 deletions remotes/ref-and-defs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$id": "http://localhost:1234/ref-and-defs.json",
Copy link
Member

Choose a reason for hiding this comment

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

When we talked about $ids being required to be absolute URIs, I said,

Same goes for the $ids in the "remotes" schemas.

It occurred to me that that's not true. The "remotes" are designed as if they are fetched from http://localhost:1234/{path-to-schema}. Therefore, they have a retrieval URI and don't need an absolute URI. That's why none of them have $id and that's not a problem. So, $ids (or even relative $ids) are fine in the "remotes" schemas, but they aren't necessary. I'm ok with leaving them in (even tho they are redundant) or taking them out.

"$defs": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"$ref": "#/$defs/inner"
}
104 changes: 104 additions & 0 deletions tests/draft2019-09/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,5 +430,109 @@
"valid": true
}
]
},
{
"description": "refs with relative uris and defs",
"schema": {
"$id": "http://example.com/schema-relative-uri-defs1.json",
"properties": {
"foo": {
"$id": "schema-relative-uri-defs2.json",
"$defs": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"$ref": "#/$defs/inner"
}
},
"$ref": "schema-relative-uri-defs2.json"
},
"tests": [
{
"description": "invalid on inner field",
"data": {
"foo": {
"bar": 1
},
"bar": "a"
},
"valid": false
},
{
"description": "invalid on outer field",
"data": {
"foo": {
"bar": "a"
},
"bar": 1
},
"valid": false
},
{
"description": "valid on both fields",
"data": {
"foo": {
"bar": "a"
},
"bar": "a"
},
"valid": true
}
]
},
{
"description": "relative refs with absolute uris and defs",
"schema": {
"$id": "http://example.com/schema-refs-absolute-uris-defs1.json",
"properties": {
"foo": {
"$id": "http://example.com/schema-refs-absolute-uris-defs2.json",
"$defs": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"$ref": "#/$defs/inner"
}
},
"$ref": "schema-refs-absolute-uris-defs2.json"
},
"tests": [
{
"description": "invalid on inner field",
"data": {
"foo": {
"bar": 1
},
"bar": "a"
},
"valid": false
},
{
"description": "invalid on outer field",
"data": {
"foo": {
"bar": "a"
},
"bar": 1
},
"valid": false
},
{
"description": "valid on both fields",
"data": {
"foo": {
"bar": "a"
},
"bar": "a"
},
"valid": true
}
]
}
]
23 changes: 23 additions & 0 deletions tests/draft2019-09/refRemote.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,28 @@
"valid": false
}
]
},
{
"description": "remote ref with ref to defs",
"schema": {
"$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json",
"$ref": "ref-and-defs.json"
},
"tests": [
{
"description": "invalid",
"data": {
"bar": 1
},
"valid": false
},
{
"description": "valid",
"data": {
"bar": "a"
},
"valid": true
}
]
}
]
104 changes: 104 additions & 0 deletions tests/draft2020-12/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,5 +432,109 @@
"valid": true
}
]
},
{
"description": "refs with relative uris and defs",
"schema": {
"$id": "http://example.com/schema-relative-uri-defs1.json",
"properties": {
"foo": {
"$id": "schema-relative-uri-defs2.json",
"$defs": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"$ref": "#/$defs/inner"
}
},
"$ref": "schema-relative-uri-defs2.json",
},
"tests": [
{
"description": "invalid on inner field",
"data": {
"foo": {
"bar": 1
},
"bar": "a"
},
"valid": false
},
{
"description": "invalid on outer field",
"data": {
"foo": {
"bar": "a"
},
"bar": 1
},
"valid": false
},
{
"description": "valid on both fields",
"data": {
"foo": {
"bar": "a"
},
"bar": "a"
},
"valid": true
}
]
},
{
"description": "relative refs with absolute uris and defs",
"schema": {
"$id": "http://example.com/schema-refs-absolute-uris-defs1.json",
"properties": {
"foo": {
"$id": "http://example.com/schema-refs-absolute-uris-defs2.json",
"$defs": {
"inner": {
"properties": {
"bar": { "type": "string" }
}
}
},
"$ref": "#/$defs/inner"
}
},
"$ref": "schema-refs-absolute-uris-defs2.json"
},
"tests": [
{
"description": "invalid on inner field",
"data": {
"foo": {
"bar": 1
},
"bar": "a"
},
"valid": false
},
{
"description": "invalid on outer field",
"data": {
"foo": {
"bar": "a"
},
"bar": 1
},
"valid": false
},
{
"description": "valid on both fields",
"data": {
"foo": {
"bar": "a"
},
"bar": "a"
},
"valid": true
}
]
}
]
23 changes: 23 additions & 0 deletions tests/draft2020-12/refRemote.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,28 @@
"valid": false
}
]
},
{
"description": "remote ref with ref to defs",
"schema": {
"$id": "http://localhost:1234/schema-remote-ref-ref-defs1.json",
"$ref": "ref-and-defs.json"
},
"tests": [
{
"description": "invalid",
"data": {
"bar": 1
},
"valid": false
},
{
"description": "valid",
"data": {
"bar": "a"
},
"valid": true
}
]
}
]
Loading