From 7bcf16a494e8bbf17bdd1a8f5ecaa3309eca49ae Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Sat, 10 Aug 2024 04:15:02 +0530 Subject: [PATCH] Draft 2 to 3, rules on `optional`, `requires` keyword (#43) --- ...-optional-true-in-properties-children.json | 11 ++++ ...perties-children-and-required-present.json | 12 +++++ ...optional-false-in-properties-children.json | 13 +++++ ...ties-children-initialize-dependencies.json | 10 ++++ ...res-is-present-in-properties-children.json | 10 ++++ .../optional-in-properties-children.json | 53 +++++++++++++++++++ ...res-is-present-in-properties-children.json | 25 +++++++++ 7 files changed, 134 insertions(+) create mode 100644 rules/from-draft2/to-draft3/011-optional-true-in-properties-children.json create mode 100644 rules/from-draft2/to-draft3/012-optional-false-in-properties-children-and-required-present.json create mode 100644 rules/from-draft2/to-draft3/013-optional-false-in-properties-children.json create mode 100644 rules/from-draft2/to-draft3/014-requires-is-present-in-properties-children-initialize-dependencies.json create mode 100644 rules/from-draft2/to-draft3/015-requires-is-present-in-properties-children.json create mode 100644 test/from-draft2/to-draft3/optional-in-properties-children.json create mode 100644 test/from-draft2/to-draft3/requires-is-present-in-properties-children.json diff --git a/rules/from-draft2/to-draft3/011-optional-true-in-properties-children.json b/rules/from-draft2/to-draft3/011-optional-true-in-properties-children.json new file mode 100644 index 0000000..7d52940 --- /dev/null +++ b/rules/from-draft2/to-draft3/011-optional-true-in-properties-children.json @@ -0,0 +1,11 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "properties" }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "optional" }, + { "operation": "equals", "path": [ "properties", {}, "optional" ], "value": true } + ], + "transform": [ + { "operation": "remove", "path": [ "properties", {}, "optional" ] } + ] +} diff --git a/rules/from-draft2/to-draft3/012-optional-false-in-properties-children-and-required-present.json b/rules/from-draft2/to-draft3/012-optional-false-in-properties-children-and-required-present.json new file mode 100644 index 0000000..3e10e42 --- /dev/null +++ b/rules/from-draft2/to-draft3/012-optional-false-in-properties-children-and-required-present.json @@ -0,0 +1,12 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "properties" }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "optional" }, + { "operation": "equals", "path": [ "properties", {}, "optional" ], "value": false }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "required" } + ], + "transform": [ + { "operation": "prefix-until-unique", "path": [ "properties", {}, "required" ], "value": "x-" } + ] +} diff --git a/rules/from-draft2/to-draft3/013-optional-false-in-properties-children.json b/rules/from-draft2/to-draft3/013-optional-false-in-properties-children.json new file mode 100644 index 0000000..9005bbb --- /dev/null +++ b/rules/from-draft2/to-draft3/013-optional-false-in-properties-children.json @@ -0,0 +1,13 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "properties" }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "optional" }, + { "operation": "equals", "path": [ "properties", {}, "optional" ], "value": false }, + { "operation": "not-has-key", "path": [ "properties", {} ], "value": "required" } + ], + "transform": [ + { "operation": "move", "to": [ "properties", {}, "required" ], "from": [ "properties", {}, "optional" ] }, + { "operation": "replace", "path": [ "properties", {}, "required" ], "value": true } + ] +} diff --git a/rules/from-draft2/to-draft3/014-requires-is-present-in-properties-children-initialize-dependencies.json b/rules/from-draft2/to-draft3/014-requires-is-present-in-properties-children-initialize-dependencies.json new file mode 100644 index 0000000..3c5c620 --- /dev/null +++ b/rules/from-draft2/to-draft3/014-requires-is-present-in-properties-children-initialize-dependencies.json @@ -0,0 +1,10 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "properties" }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "requires" } + ], + "transform": [ + { "operation": "add", "path": [ "dependencies" ], "value": {} } + ] +} diff --git a/rules/from-draft2/to-draft3/015-requires-is-present-in-properties-children.json b/rules/from-draft2/to-draft3/015-requires-is-present-in-properties-children.json new file mode 100644 index 0000000..f8bb3af --- /dev/null +++ b/rules/from-draft2/to-draft3/015-requires-is-present-in-properties-children.json @@ -0,0 +1,10 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "properties" }, + { "operation": "has-key", "path": [ "properties", {} ], "value": "requires" } + ], + "transform": [ + { "operation": "move", "to": [ "dependencies", {} ], "from": [ "properties", {}, "requires" ] } + ] +} diff --git a/test/from-draft2/to-draft3/optional-in-properties-children.json b/test/from-draft2/to-draft3/optional-in-properties-children.json new file mode 100644 index 0000000..5e8f5e6 --- /dev/null +++ b/test/from-draft2/to-draft3/optional-in-properties-children.json @@ -0,0 +1,53 @@ +[ + { + "title": "properties has children who have optional:false and required is already present", + "from": { + "properties": { + "foo": { + "required": "string", + "optional": false + } + } + }, + "to": { + "properties": { + "foo": { + "x-required": "string", + "required": true + } + } + } + }, + { + "title": "properties has children who have optional:false", + "from": { + "properties": { + "foo": { + "optional": false + } + } + }, + "to": { + "properties": { + "foo": { + "required": true + } + } + } + }, + { + "title": "properties has children who have optional:true", + "from": { + "properties": { + "foo": { + "optional": true + } + } + }, + "to": { + "properties": { + "foo": {} + } + } + } +] diff --git a/test/from-draft2/to-draft3/requires-is-present-in-properties-children.json b/test/from-draft2/to-draft3/requires-is-present-in-properties-children.json new file mode 100644 index 0000000..91ed504 --- /dev/null +++ b/test/from-draft2/to-draft3/requires-is-present-in-properties-children.json @@ -0,0 +1,25 @@ +[ + { + "title": "properties has children who have `requires` keyword", + "from": { + "properties": { + "foo": { + "requires": "bar" + }, + "bar": { + "requires": { "type": "string"} + } + } + }, + "to": { + "properties": { + "foo": {}, + "bar": {} + }, + "dependencies": { + "foo": "bar", + "bar": { "type": "string"} + } + } + } +]