Skip to content

Commit

Permalink
Add tests for unevaluated with dynamic reference
Browse files Browse the repository at this point in the history
  • Loading branch information
jdesrosiers committed Oct 24, 2023
1 parent cda4281 commit f13fb46
Show file tree
Hide file tree
Showing 4 changed files with 203 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/draft2019-09/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,50 @@
}
]
},
{
"description": "unevaluatedItems with $recursiveRef",
"schema": {
"$schema": "https://json-schema.org/draft/2019-09/schema",
"$id": "https://example.com/extended-tree",

"$recursiveAnchor": true,

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

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

"type": "array",
"prefixItems": [
{ "type": "number" },
{
"$recursiveRef": "#",
"unevaluatedItems": false
}
]
}
}
},
"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
57 changes: 57 additions & 0 deletions tests/draft2019-09/unevaluatedProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,63 @@
}
]
},
{
"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": {
"$recursiveRef": "#",
"unevaluatedProperties": false
}
},
"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
48 changes: 48 additions & 0 deletions tests/draft2020-12/unevaluatedItems.json
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,54 @@
}
]
},
{
"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",

"type": "array",
"prefixItems": [
{ "type": "string" }
],
"$dynamicRef": "#addons",
"unevaluatedItems": false,

"$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
54 changes: 54 additions & 0 deletions tests/draft2020-12/unevaluatedProperties.json
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,60 @@
}
]
},
{
"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",

"type": "object",
"properties": {
"foo": { "type": "string" }
},
"$dynamicRef": "#addons",
"unevaluatedProperties": false,

"$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

0 comments on commit f13fb46

Please sign in to comment.