-
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #391 from ether/recursiveRef (rebased, squashed)
test $recursiveRef + $recursiveAnchor
- Loading branch information
Showing
1 changed file
with
310 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,310 @@ | ||
[ | ||
{ | ||
"description": "$recursiveRef without $recursiveAnchor works like $ref", | ||
"schema": { | ||
"properties": { | ||
"foo": { "$recursiveRef": "#" } | ||
}, | ||
"additionalProperties": false | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "match", | ||
"data": {"foo": false}, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "recursive match", | ||
"data": { "foo": { "foo": false } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "mismatch", | ||
"data": { "bar": false }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "recursive mismatch", | ||
"data": { "foo": { "bar": false } }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef without using nesting", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef2/schema.json", | ||
"$defs": { | ||
"myobject": { | ||
"$id": "myobject.json", | ||
"$recursiveAnchor": true, | ||
"anyOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { "$recursiveRef": "#" } | ||
} | ||
] | ||
} | ||
}, | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "$ref": "#/$defs/myobject" } | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "integer matches at the outer level", | ||
"data": 1, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "single level match", | ||
"data": { "foo": "hi" }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "integer does not match as a property value", | ||
"data": { "foo": 1 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "two levels, properties match with inner definition", | ||
"data": { "foo": { "bar": "hi" } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "two levels, no match", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef with nesting", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef3/schema.json", | ||
"$recursiveAnchor": true, | ||
"$defs": { | ||
"myobject": { | ||
"$id": "myobject.json", | ||
"$recursiveAnchor": true, | ||
"anyOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { "$recursiveRef": "#" } | ||
} | ||
] | ||
} | ||
}, | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "$ref": "#/$defs/myobject" } | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "integer matches at the outer level", | ||
"data": 1, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "single level match", | ||
"data": { "foo": "hi" }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "integer now matches as a property value", | ||
"data": { "foo": 1 }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "two levels, properties match with inner definition", | ||
"data": { "foo": { "bar": "hi" } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "two levels, properties match with $recursiveRef", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": true | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef with $recursiveAnchor: false works like $ref", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef4/schema.json", | ||
"$recursiveAnchor": false, | ||
"$defs": { | ||
"myobject": { | ||
"$id": "myobject.json", | ||
"$recursiveAnchor": false, | ||
"anyOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { "$recursiveRef": "#" } | ||
} | ||
] | ||
} | ||
}, | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "$ref": "#/$defs/myobject" } | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "integer matches at the outer level", | ||
"data": 1, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "single level match", | ||
"data": { "foo": "hi" }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "integer does not match as a property value", | ||
"data": { "foo": 1 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "two levels, properties match with inner definition", | ||
"data": { "foo": { "bar": "hi" } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "two levels, integer does not match as a property value", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef with no $recursiveAnchor works like $ref", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef5/schema.json", | ||
"$defs": { | ||
"myobject": { | ||
"$id": "myobject.json", | ||
"$recursiveAnchor": false, | ||
"anyOf": [ | ||
{ "type": "string" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { "$recursiveRef": "#" } | ||
} | ||
] | ||
} | ||
}, | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "$ref": "#/$defs/myobject" } | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "integer matches at the outer level", | ||
"data": 1, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "single level match", | ||
"data": { "foo": "hi" }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "integer does not match as a property value", | ||
"data": { "foo": 1 }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "two levels, properties match with inner definition", | ||
"data": { "foo": { "bar": "hi" } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "two levels, integer does not match as a property value", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef with no $recursiveAnchor in the initial target schema resource", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef6/base.json", | ||
"$recursiveAnchor": true, | ||
"anyOf": [ | ||
{ "type": "boolean" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { | ||
"$id": "http://localhost:4242/recursiveRef6/inner.json", | ||
"$comment": "there is no $recursiveAnchor: true here, so we do NOT recurse to the base", | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "type": "object", "additionalProperties": { "$recursiveRef": "#" } } | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "leaf node does not match; no recursion", | ||
"data": { "foo": true }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "leaf node matches: recursion uses the inner schema", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "leaf node matches: recursion uses the inner schema", | ||
"data": { "foo": { "bar": true } }, | ||
"valid": false | ||
} | ||
] | ||
}, | ||
{ | ||
"description": "$recursiveRef with no $recursiveAnchor in the outer schema resource", | ||
"schema": { | ||
"$id": "http://localhost:4242/recursiveRef7/base.json", | ||
"anyOf": [ | ||
{ "type": "boolean" }, | ||
{ | ||
"type": "object", | ||
"additionalProperties": { | ||
"$id": "http://localhost:4242/recursiveRef7/inner.json", | ||
"$recursiveAnchor": true, | ||
"anyOf": [ | ||
{ "type": "integer" }, | ||
{ "type": "object", "additionalProperties": { "$recursiveRef": "#" } } | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"tests": [ | ||
{ | ||
"description": "leaf node does not match; no recursion", | ||
"data": { "foo": true }, | ||
"valid": false | ||
}, | ||
{ | ||
"description": "leaf node matches: recursion only uses inner schema", | ||
"data": { "foo": { "bar": 1 } }, | ||
"valid": true | ||
}, | ||
{ | ||
"description": "leaf node does not match: recursion only uses inner schema", | ||
"data": { "foo": { "bar": true } }, | ||
"valid": false | ||
} | ||
] | ||
} | ||
] |