Skip to content

Add some simple tests for URN base URIs. #578

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 3 commits into from
Jul 31, 2022
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
188 changes: 188 additions & 0 deletions tests/draft-next/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,193 @@
"valid": false
}
]
},
{
"description": "simple URN base URI with $ref via the URN",
"schema": {
"$comment": "URIs do not have to have HTTP(s) schemes",
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
"minimum": 30,
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"}
}
},
"tests": [
{
"description": "valid under the URN IDed schema",
"data": {"foo": 37},
"valid": true
},
{
"description": "invalid under the URN IDed schema",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "simple URN base URI with JSON pointer",
"schema": {
"$comment": "URIs do not have to have HTTP(s) schemes",
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with NSS",
"schema": {
"$comment": "RFC 8141 §2.2",
"$id": "urn:example:1/406/47452/2",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with r-component",
"schema": {
"$comment": "RFC 8141 §2.3.1",
"$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with q-component",
"schema": {
"$comment": "RFC 8141 §2.3.2",
"$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with f-component",
"schema": {
"$comment": "RFC 8141 §2.3.3, but we don't allow fragments",
"$ref": "https://json-schema.org/draft/next/schema"
},
"tests": [
{
"description": "is invalid",
"data": {"$id": "urn:example:foo-bar-baz-qux#somepart"},
"valid": false
}
]
},
{
"description": "URN base URI with URN and JSON pointer ref",
"schema": {
"$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed",
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with URN and anchor ref",
"schema": {
"$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed",
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#something"}
},
"$defs": {
"bar": {
"$anchor": "something",
"type": "string"
}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
}
]
188 changes: 188 additions & 0 deletions tests/draft2019-09/ref.json
Original file line number Diff line number Diff line change
Expand Up @@ -642,5 +642,193 @@
"valid": false
}
]
},
{
"description": "simple URN base URI with $ref via the URN",
"schema": {
"$comment": "URIs do not have to have HTTP(s) schemes",
"$id": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed",
"minimum": 30,
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-ffff-ffff-4321feebdaed"}
}
},
"tests": [
{
"description": "valid under the URN IDed schema",
"data": {"foo": 37},
"valid": true
},
{
"description": "invalid under the URN IDed schema",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "simple URN base URI with JSON pointer",
"schema": {
"$comment": "URIs do not have to have HTTP(s) schemes",
"$id": "urn:uuid:deadbeef-1234-00ff-ff00-4321feebdaed",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with NSS",
"schema": {
"$comment": "RFC 8141 §2.2",
"$id": "urn:example:1/406/47452/2",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with r-component",
"schema": {
"$comment": "RFC 8141 §2.3.1",
"$id": "urn:example:foo-bar-baz-qux?+CCResolve:cc=uk",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with q-component",
"schema": {
"$comment": "RFC 8141 §2.3.2",
"$id": "urn:example:weather?=op=map&lat=39.56&lon=-104.85&datetime=1969-07-21T02:56:15Z",
"properties": {
"foo": {"$ref": "#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with f-component",
"schema": {
"$comment": "RFC 8141 §2.3.3, but we don't allow fragments",
"$ref": "https://json-schema.org/draft/2019-09/schema"
},
"tests": [
{
"description": "is invalid",
"data": {"$id": "urn:example:foo-bar-baz-qux#somepart"},
"valid": false
}
]
},
{
"description": "URN base URI with URN and JSON pointer ref",
"schema": {
"$id": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed",
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-0000-0000-4321feebdaed#/$defs/bar"}
},
"$defs": {
"bar": {"type": "string"}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
},
{
"description": "URN base URI with URN and anchor ref",
"schema": {
"$id": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed",
"properties": {
"foo": {"$ref": "urn:uuid:deadbeef-1234-ff00-00ff-4321feebdaed#something"}
},
"$defs": {
"bar": {
"$anchor": "something",
"type": "string"
}
}
},
"tests": [
{
"description": "a string is valid",
"data": {"foo": "bar"},
"valid": true
},
{
"description": "a non-string is invalid",
"data": {"foo": 12},
"valid": false
}
]
}
]
Loading