From f1b230c6905f252a4abd8df806ef034e36509652 Mon Sep 17 00:00:00 2001 From: Oleg Schelykalnov Date: Thu, 14 Oct 2021 20:42:25 +0300 Subject: [PATCH] Add test from Appendix C. Example of recursive schema extension of the draft. --- remotes/tree.json | 16 ++++++++++++++++ tests/draft-future/dynamicRef.json | 30 ++++++++++++++++++++++++++++++ tests/draft2020-12/dynamicRef.json | 30 ++++++++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 remotes/tree.json diff --git a/remotes/tree.json b/remotes/tree.json new file mode 100644 index 00000000..a12d98b0 --- /dev/null +++ b/remotes/tree.json @@ -0,0 +1,16 @@ +{ + "description": "tree schema, extensible", + "$id": "http://localhost:1234/tree.json", + "$dynamicAnchor": "node", + + "type": "object", + "properties": { + "data": true, + "children": { + "type": "array", + "items": { + "$dynamicRef": "#node" + } + } + } +} diff --git a/tests/draft-future/dynamicRef.json b/tests/draft-future/dynamicRef.json index 40ed6d37..7d9da462 100644 --- a/tests/draft-future/dynamicRef.json +++ b/tests/draft-future/dynamicRef.json @@ -441,5 +441,35 @@ "valid": true } ] + }, + { + "description": "strict-tree schema, guards against misspelled properties", + "schema": { + "$id": "http://localhost:1234/strict-tree.json", + "$dynamicAnchor": "node", + + "$ref": "tree.json", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "instance with misspelled field", + "data": { + "children": [{ + "daat": 1 + }] + }, + "valid": false + }, + { + "description": "instance with correct field", + "data": { + "children": [{ + "data": 1 + }] + }, + "valid": true + } + ] } ] diff --git a/tests/draft2020-12/dynamicRef.json b/tests/draft2020-12/dynamicRef.json index 40ed6d37..7d9da462 100644 --- a/tests/draft2020-12/dynamicRef.json +++ b/tests/draft2020-12/dynamicRef.json @@ -441,5 +441,35 @@ "valid": true } ] + }, + { + "description": "strict-tree schema, guards against misspelled properties", + "schema": { + "$id": "http://localhost:1234/strict-tree.json", + "$dynamicAnchor": "node", + + "$ref": "tree.json", + "unevaluatedProperties": false + }, + "tests": [ + { + "description": "instance with misspelled field", + "data": { + "children": [{ + "daat": 1 + }] + }, + "valid": false + }, + { + "description": "instance with correct field", + "data": { + "children": [{ + "data": 1 + }] + }, + "valid": true + } + ] } ]