Skip to content

Add tests for unevaluated with dynamic reference #696

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 4 commits into from
Nov 16, 2023
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
42 changes: 42 additions & 0 deletions tests/draft-next/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,48 @@
}
]
},
{
"description": "unevaluatedItems with $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"$id": "https://example.com/derived",

"$ref": "/baseSchema",

"$defs": {
"derived": {
"$dynamicAnchor": "addons",
"prefixItems": [
true,
{ "type": "string" }
]
},
"baseSchema": {
"$id": "/baseSchema",

"$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedItems": false,
"type": "array",
"prefixItems": [
{ "type": "string" }
],
"$dynamicRef": "#addons"
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems can't see inside cousins",
"schema": {
Expand Down
48 changes: 48 additions & 0 deletions tests/draft-next/unevaluatedProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,54 @@
}
]
},
{
"description": "unevaluatedProperties with $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/next/schema",
"$id": "https://example.com/derived",

"$ref": "/baseSchema",

"$defs": {
"derived": {
"$dynamicAnchor": "addons",
"properties": {
"bar": { "type": "string" }
}
},
"baseSchema": {
"$id": "/baseSchema",

"$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedProperties": false,
"type": "object",
"properties": {
"foo": { "type": "string" }
},
"$dynamicRef": "#addons"
}
}
},
"tests": [
{
"description": "with no unevaluated properties",
"data": {
"foo": "foo",
"bar": "bar"
},
"valid": true
},
{
"description": "with unevaluated properties",
"data": {
"foo": "foo",
"bar": "bar",
"baz": "baz"
},
"valid": false
}
]
},
{
"description": "unevaluatedProperties can't see inside cousins",
"schema": {
Expand Down
45 changes: 45 additions & 0 deletions tests/draft2019-09/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,51 @@
}
]
},
{
"description": "unevaluatedItems with $recursiveRef",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.com/extended-tree",

"$recursiveAnchor": true,

"$ref": "/tree",
"items": [
true,
true,
{ "type": "string" }
],

"$defs": {
"tree": {
"$id": "/tree",
"$recursiveAnchor": true,

"type": "array",
"items": [
{ "type": "number" },
{
"$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedItems": false,
"$recursiveRef": "#"
}
]
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": [1, [2, [], "b"], "a"],
"valid": true
},
{
"description": "with unevaluated items",
"data": [1, [2, [], "b", "too many"], "a"],
"valid": false
}
]
},
{
"description": "unevaluatedItems can't see inside cousins",
"schema": {
Expand Down
58 changes: 58 additions & 0 deletions tests/draft2019-09/unevaluatedProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,64 @@
}
]
},
{
"description": "unevaluatedProperties with $recursiveRef",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.com/extended-tree",

"$recursiveAnchor": true,

"$ref": "/tree",
"properties": {
"name": { "type": "string" }
},

"$defs": {
"tree": {
"$id": "/tree",
"$recursiveAnchor": true,

"type": "object",
"properties": {
"node": true,
"branches": {
"$comment": "unevaluatedProperties comes first so it's more likely to bugs errors with implementations that are sensitive to keyword ordering",
"unevaluatedProperties": false,
"$recursiveRef": "#"
}
},
"required": ["node"]
}
}
},
"tests": [
{
"description": "with no unevaluated properties",
"data": {
"name": "a",
"node": 1,
"branches": {
"name": "b",
"node": 2
}
},
"valid": true
},
{
"description": "with unevaluated properties",
"data": {
"name": "a",
"node": 1,
"branches": {
"foo": "b",
"node": 2
}
},
"valid": false
}
]
},
{
"description": "unevaluatedProperties can't see inside cousins",
"schema": {
Expand Down
49 changes: 49 additions & 0 deletions tests/draft2020-12/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,55 @@
}
]
},
{
"description": "unevaluatedItems with $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/derived",

"$ref": "/baseSchema",

"$defs": {
"derived": {
"$dynamicAnchor": "addons",
"prefixItems": [
true,
{ "type": "string" }
]
},
"baseSchema": {
"$id": "/baseSchema",

"$comment": "unevaluatedItems comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedItems": false,
"type": "array",
"prefixItems": [
{ "type": "string" }
],
"$dynamicRef": "#addons",

"$defs": {
"defaultAddons": {
"$comment": "Needed to satisfy the bookending requirement",
"$dynamicAnchor": "addons"
}
}
}
}
},
"tests": [
{
"description": "with no unevaluated items",
"data": ["foo", "bar"],
"valid": true
},
{
"description": "with unevaluated items",
"data": ["foo", "bar", "baz"],
"valid": false
}
]
},
{
"description": "unevaluatedItems can't see inside cousins",
"schema": {
Expand Down
55 changes: 55 additions & 0 deletions tests/draft2020-12/unevaluatedProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,61 @@
}
]
},
{
"description": "unevaluatedProperties with $dynamicRef",
"schema": {
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://example.com/derived",

"$ref": "/baseSchema",

"$defs": {
"derived": {
"$dynamicAnchor": "addons",
"properties": {
"bar": { "type": "string" }
}
},
"baseSchema": {
"$id": "/baseSchema",

"$comment": "unevaluatedProperties comes first so it's more likely to catch bugs with implementations that are sensitive to keyword ordering",
"unevaluatedProperties": false,
"type": "object",
"properties": {
"foo": { "type": "string" }
},
"$dynamicRef": "#addons",

"$defs": {
"defaultAddons": {
"$comment": "Needed to satisfy the bookending requirement",
"$dynamicAnchor": "addons"
}
}
}
}
},
"tests": [
{
"description": "with no unevaluated properties",
"data": {
"foo": "foo",
"bar": "bar"
},
"valid": true
},
{
"description": "with unevaluated properties",
"data": {
"foo": "foo",
"bar": "bar",
"baz": "baz"
},
"valid": false
}
]
},
{
"description": "unevaluatedProperties can't see inside cousins",
"schema": {
Expand Down