From 943afe2e418fcc3aebc570e51bd9f7d631e04191 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Mon, 26 Aug 2024 05:17:11 +0530 Subject: [PATCH] Add ref adjacent keywords case for Draft4 to Draft 6 transform (#52) --- ...001-ref-and-adjecent-keywords-present.json | 10 ++++++ .../to-draft6/002-ref-and-x-ref-present.json | 10 ++++++ ...003-correct-sideeffects-ref-transform.json | 9 ++++++ ... 004-unknown-in-previous-draft-const.json} | 0 ...5-unknown-in-previous-draft-contains.json} | 0 ...6-unknown-in-previous-draft-examples.json} | 0 ...nown-in-previous-draft-propertyNames.json} | 0 ...=> 008-unknown-in-previous-draft-$id.json} | 0 .../{006-schema.json => 009-schema.json} | 0 ...07-id-present.json => 010-id-present.json} | 0 ...=> 011-exclusiveMaximum-boolean-true.json} | 0 ...> 012-exclusiveMaximum-boolean-false.json} | 0 ...=> 013-exclusiveMinimum-boolean-true.json} | 0 ...> 014-exclusiveMinimum-boolean-false.json} | 0 test/from-draft4/to-draft6/ref.json | 31 +++++++++++++++++++ 15 files changed, 60 insertions(+) create mode 100644 rules/from-draft4/to-draft6/001-ref-and-adjecent-keywords-present.json create mode 100644 rules/from-draft4/to-draft6/002-ref-and-x-ref-present.json create mode 100644 rules/from-draft4/to-draft6/003-correct-sideeffects-ref-transform.json rename rules/from-draft4/to-draft6/{001-unknown-in-previous-draft-const.json => 004-unknown-in-previous-draft-const.json} (100%) rename rules/from-draft4/to-draft6/{002-unknown-in-previous-draft-contains.json => 005-unknown-in-previous-draft-contains.json} (100%) rename rules/from-draft4/to-draft6/{003-unknown-in-previous-draft-examples.json => 006-unknown-in-previous-draft-examples.json} (100%) rename rules/from-draft4/to-draft6/{004-unknown-in-previous-draft-propertyNames.json => 007-unknown-in-previous-draft-propertyNames.json} (100%) rename rules/from-draft4/to-draft6/{005-unknown-in-previous-draft-$id.json => 008-unknown-in-previous-draft-$id.json} (100%) rename rules/from-draft4/to-draft6/{006-schema.json => 009-schema.json} (100%) rename rules/from-draft4/to-draft6/{007-id-present.json => 010-id-present.json} (100%) rename rules/from-draft4/to-draft6/{008-exclusiveMaximum-boolean-true.json => 011-exclusiveMaximum-boolean-true.json} (100%) rename rules/from-draft4/to-draft6/{009-exclusiveMaximum-boolean-false.json => 012-exclusiveMaximum-boolean-false.json} (100%) rename rules/from-draft4/to-draft6/{010-exclusiveMinimum-boolean-true.json => 013-exclusiveMinimum-boolean-true.json} (100%) rename rules/from-draft4/to-draft6/{011-exclusiveMinimum-boolean-false.json => 014-exclusiveMinimum-boolean-false.json} (100%) create mode 100644 test/from-draft4/to-draft6/ref.json diff --git a/rules/from-draft4/to-draft6/001-ref-and-adjecent-keywords-present.json b/rules/from-draft4/to-draft6/001-ref-and-adjecent-keywords-present.json new file mode 100644 index 0000000..bbb03f4 --- /dev/null +++ b/rules/from-draft4/to-draft6/001-ref-and-adjecent-keywords-present.json @@ -0,0 +1,10 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "$ref" }, + { "operation": "type-is", "path": [ {} ], "value": [ "array", "booelan", "integer", "number", "object", "string" ] } + ], + "transform": [ + { "operation": "prefix-until-unique", "path": [ {} ], "value": "x-" } + ] +} diff --git a/rules/from-draft4/to-draft6/002-ref-and-x-ref-present.json b/rules/from-draft4/to-draft6/002-ref-and-x-ref-present.json new file mode 100644 index 0000000..5e482fa --- /dev/null +++ b/rules/from-draft4/to-draft6/002-ref-and-x-ref-present.json @@ -0,0 +1,10 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "$ref" }, + { "operation": "has-key", "path": [], "value": "x-$ref" } + ], + "transform": [ + { "operation": "prefix-until-unique", "path": [ "x-$ref" ], "value": "x-" } + ] +} diff --git a/rules/from-draft4/to-draft6/003-correct-sideeffects-ref-transform.json b/rules/from-draft4/to-draft6/003-correct-sideeffects-ref-transform.json new file mode 100644 index 0000000..56ba6d3 --- /dev/null +++ b/rules/from-draft4/to-draft6/003-correct-sideeffects-ref-transform.json @@ -0,0 +1,9 @@ +{ + "vocabulary": "core", + "condition": [ + { "operation": "has-key", "path": [], "value": "x-$ref" } + ], + "transform": [ + { "operation": "move", "to": [ "$ref" ], "from": [ "x-$ref" ] } + ] +} diff --git a/rules/from-draft4/to-draft6/001-unknown-in-previous-draft-const.json b/rules/from-draft4/to-draft6/004-unknown-in-previous-draft-const.json similarity index 100% rename from rules/from-draft4/to-draft6/001-unknown-in-previous-draft-const.json rename to rules/from-draft4/to-draft6/004-unknown-in-previous-draft-const.json diff --git a/rules/from-draft4/to-draft6/002-unknown-in-previous-draft-contains.json b/rules/from-draft4/to-draft6/005-unknown-in-previous-draft-contains.json similarity index 100% rename from rules/from-draft4/to-draft6/002-unknown-in-previous-draft-contains.json rename to rules/from-draft4/to-draft6/005-unknown-in-previous-draft-contains.json diff --git a/rules/from-draft4/to-draft6/003-unknown-in-previous-draft-examples.json b/rules/from-draft4/to-draft6/006-unknown-in-previous-draft-examples.json similarity index 100% rename from rules/from-draft4/to-draft6/003-unknown-in-previous-draft-examples.json rename to rules/from-draft4/to-draft6/006-unknown-in-previous-draft-examples.json diff --git a/rules/from-draft4/to-draft6/004-unknown-in-previous-draft-propertyNames.json b/rules/from-draft4/to-draft6/007-unknown-in-previous-draft-propertyNames.json similarity index 100% rename from rules/from-draft4/to-draft6/004-unknown-in-previous-draft-propertyNames.json rename to rules/from-draft4/to-draft6/007-unknown-in-previous-draft-propertyNames.json diff --git a/rules/from-draft4/to-draft6/005-unknown-in-previous-draft-$id.json b/rules/from-draft4/to-draft6/008-unknown-in-previous-draft-$id.json similarity index 100% rename from rules/from-draft4/to-draft6/005-unknown-in-previous-draft-$id.json rename to rules/from-draft4/to-draft6/008-unknown-in-previous-draft-$id.json diff --git a/rules/from-draft4/to-draft6/006-schema.json b/rules/from-draft4/to-draft6/009-schema.json similarity index 100% rename from rules/from-draft4/to-draft6/006-schema.json rename to rules/from-draft4/to-draft6/009-schema.json diff --git a/rules/from-draft4/to-draft6/007-id-present.json b/rules/from-draft4/to-draft6/010-id-present.json similarity index 100% rename from rules/from-draft4/to-draft6/007-id-present.json rename to rules/from-draft4/to-draft6/010-id-present.json diff --git a/rules/from-draft4/to-draft6/008-exclusiveMaximum-boolean-true.json b/rules/from-draft4/to-draft6/011-exclusiveMaximum-boolean-true.json similarity index 100% rename from rules/from-draft4/to-draft6/008-exclusiveMaximum-boolean-true.json rename to rules/from-draft4/to-draft6/011-exclusiveMaximum-boolean-true.json diff --git a/rules/from-draft4/to-draft6/009-exclusiveMaximum-boolean-false.json b/rules/from-draft4/to-draft6/012-exclusiveMaximum-boolean-false.json similarity index 100% rename from rules/from-draft4/to-draft6/009-exclusiveMaximum-boolean-false.json rename to rules/from-draft4/to-draft6/012-exclusiveMaximum-boolean-false.json diff --git a/rules/from-draft4/to-draft6/010-exclusiveMinimum-boolean-true.json b/rules/from-draft4/to-draft6/013-exclusiveMinimum-boolean-true.json similarity index 100% rename from rules/from-draft4/to-draft6/010-exclusiveMinimum-boolean-true.json rename to rules/from-draft4/to-draft6/013-exclusiveMinimum-boolean-true.json diff --git a/rules/from-draft4/to-draft6/011-exclusiveMinimum-boolean-false.json b/rules/from-draft4/to-draft6/014-exclusiveMinimum-boolean-false.json similarity index 100% rename from rules/from-draft4/to-draft6/011-exclusiveMinimum-boolean-false.json rename to rules/from-draft4/to-draft6/014-exclusiveMinimum-boolean-false.json diff --git a/test/from-draft4/to-draft6/ref.json b/test/from-draft4/to-draft6/ref.json new file mode 100644 index 0000000..c75fda1 --- /dev/null +++ b/test/from-draft4/to-draft6/ref.json @@ -0,0 +1,31 @@ +[ + { + "title": "$ref present in schema, with adjacent keywords", + "from": { + "id": "http://example.com", + "properties": { + "foo": { + "$ref": "/bar", + "type": "string", + "id": "zoo" + }, + "bar": { + "id": "bar" + } + } + }, + "to": { + "id": "http://example.com", + "properties": { + "foo": { + "$ref": "/bar", + "x-type": "string", + "x-id": "zoo" + }, + "bar": { + "id": "bar" + } + } + } + } +]