From 3a5733317a99c9c67ec13cef3cb1a2b440542724 Mon Sep 17 00:00:00 2001 From: Suprith KG Date: Fri, 16 Aug 2024 02:45:16 +0530 Subject: [PATCH] Ref ignores adjacent keywords Draft 7 to 2019-09, correction in the rules (#50) --- ...001-ref-and-adjecent-keywords-present.json | 10 ++++++ .../to-2019-09/002-ref-and-x-ref-present.json | 10 ++++++ ...003-correct-sideeffects-ref-transform.json | 9 ++++++ ...unknown-in-previous-draft-deprecated.json} | 0 ...nknown-in-previous-draft-maxContains.json} | 0 ...nknown-in-previous-draft-minContains.json} | 0 ...n-in-previous-draft-dependentSchemas.json} | 0 ...-in-previous-draft-dependentRequired.json} | 0 ...009-unknown-in-previous-draft-anchor.json} | 0 ...unknown-in-previous-draft-vocabulary.json} | 0 ...wn-in-previous-draft-recursiveAnchor.json} | 0 ...known-in-previous-draft-recursiveRef.json} | 0 ...> 013-unknown-in-previous-draft-defs.json} | 0 .../{011-schema.json => 014-schema.json} | 0 ...hash.json => 015-id-starts-with-hash.json} | 0 ...defs.json => 016-definitions-to-defs.json} | 0 ...dependencies-children-has-type-array.json} | 0 ...18-dependencies-to-dependentRequired.json} | 0 ...ependencies-children-has-type-object.json} | 0 ...020-dependencies-to-dependentSchemas.json} | 0 ...son => 021-dependencies-empty-object.json} | 0 test/from-draft7/to-2019-09/ref.json | 31 +++++++++++++++++++ 22 files changed, 60 insertions(+) create mode 100644 rules/from-draft7/to-2019-09/001-ref-and-adjecent-keywords-present.json create mode 100644 rules/from-draft7/to-2019-09/002-ref-and-x-ref-present.json create mode 100644 rules/from-draft7/to-2019-09/003-correct-sideeffects-ref-transform.json rename rules/from-draft7/to-2019-09/{001-unknown-in-previous-draft-deprecated.json => 004-unknown-in-previous-draft-deprecated.json} (100%) rename rules/from-draft7/to-2019-09/{002-unknown-in-previous-draft-maxContains.json => 005-unknown-in-previous-draft-maxContains.json} (100%) rename rules/from-draft7/to-2019-09/{003-unknown-in-previous-draft-minContains.json => 006-unknown-in-previous-draft-minContains.json} (100%) rename rules/from-draft7/to-2019-09/{004-unknown-in-previous-draft-dependentSchemas.json => 007-unknown-in-previous-draft-dependentSchemas.json} (100%) rename rules/from-draft7/to-2019-09/{005-unknown-in-previous-draft-dependentRequired.json => 008-unknown-in-previous-draft-dependentRequired.json} (100%) rename rules/from-draft7/to-2019-09/{006-unknown-in-previous-draft-anchor.json => 009-unknown-in-previous-draft-anchor.json} (100%) rename rules/from-draft7/to-2019-09/{007-unknown-in-previous-draft-vocabulary.json => 010-unknown-in-previous-draft-vocabulary.json} (100%) rename rules/from-draft7/to-2019-09/{008-unknown-in-previous-draft-recursiveAnchor.json => 011-unknown-in-previous-draft-recursiveAnchor.json} (100%) rename rules/from-draft7/to-2019-09/{009-unknown-in-previous-draft-recursiveRef.json => 012-unknown-in-previous-draft-recursiveRef.json} (100%) rename rules/from-draft7/to-2019-09/{010-unknown-in-previous-draft-defs.json => 013-unknown-in-previous-draft-defs.json} (100%) rename rules/from-draft7/to-2019-09/{011-schema.json => 014-schema.json} (100%) rename rules/from-draft7/to-2019-09/{012-id-starts-with-hash.json => 015-id-starts-with-hash.json} (100%) rename rules/from-draft7/to-2019-09/{013-definitions-to-defs.json => 016-definitions-to-defs.json} (100%) rename rules/from-draft7/to-2019-09/{014-dependencies-children-has-type-array.json => 017-dependencies-children-has-type-array.json} (100%) rename rules/from-draft7/to-2019-09/{015-dependencies-to-dependentRequired.json => 018-dependencies-to-dependentRequired.json} (100%) rename rules/from-draft7/to-2019-09/{016-dependencies-children-has-type-object.json => 019-dependencies-children-has-type-object.json} (100%) rename rules/from-draft7/to-2019-09/{017-dependencies-to-dependentSchemas.json => 020-dependencies-to-dependentSchemas.json} (100%) rename rules/from-draft7/to-2019-09/{018-dependencies-empty-object.json => 021-dependencies-empty-object.json} (100%) create mode 100644 test/from-draft7/to-2019-09/ref.json diff --git a/rules/from-draft7/to-2019-09/001-ref-and-adjecent-keywords-present.json b/rules/from-draft7/to-2019-09/001-ref-and-adjecent-keywords-present.json new file mode 100644 index 0000000..bbb03f4 --- /dev/null +++ b/rules/from-draft7/to-2019-09/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-draft7/to-2019-09/002-ref-and-x-ref-present.json b/rules/from-draft7/to-2019-09/002-ref-and-x-ref-present.json new file mode 100644 index 0000000..5e482fa --- /dev/null +++ b/rules/from-draft7/to-2019-09/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-draft7/to-2019-09/003-correct-sideeffects-ref-transform.json b/rules/from-draft7/to-2019-09/003-correct-sideeffects-ref-transform.json new file mode 100644 index 0000000..56ba6d3 --- /dev/null +++ b/rules/from-draft7/to-2019-09/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-draft7/to-2019-09/001-unknown-in-previous-draft-deprecated.json b/rules/from-draft7/to-2019-09/004-unknown-in-previous-draft-deprecated.json similarity index 100% rename from rules/from-draft7/to-2019-09/001-unknown-in-previous-draft-deprecated.json rename to rules/from-draft7/to-2019-09/004-unknown-in-previous-draft-deprecated.json diff --git a/rules/from-draft7/to-2019-09/002-unknown-in-previous-draft-maxContains.json b/rules/from-draft7/to-2019-09/005-unknown-in-previous-draft-maxContains.json similarity index 100% rename from rules/from-draft7/to-2019-09/002-unknown-in-previous-draft-maxContains.json rename to rules/from-draft7/to-2019-09/005-unknown-in-previous-draft-maxContains.json diff --git a/rules/from-draft7/to-2019-09/003-unknown-in-previous-draft-minContains.json b/rules/from-draft7/to-2019-09/006-unknown-in-previous-draft-minContains.json similarity index 100% rename from rules/from-draft7/to-2019-09/003-unknown-in-previous-draft-minContains.json rename to rules/from-draft7/to-2019-09/006-unknown-in-previous-draft-minContains.json diff --git a/rules/from-draft7/to-2019-09/004-unknown-in-previous-draft-dependentSchemas.json b/rules/from-draft7/to-2019-09/007-unknown-in-previous-draft-dependentSchemas.json similarity index 100% rename from rules/from-draft7/to-2019-09/004-unknown-in-previous-draft-dependentSchemas.json rename to rules/from-draft7/to-2019-09/007-unknown-in-previous-draft-dependentSchemas.json diff --git a/rules/from-draft7/to-2019-09/005-unknown-in-previous-draft-dependentRequired.json b/rules/from-draft7/to-2019-09/008-unknown-in-previous-draft-dependentRequired.json similarity index 100% rename from rules/from-draft7/to-2019-09/005-unknown-in-previous-draft-dependentRequired.json rename to rules/from-draft7/to-2019-09/008-unknown-in-previous-draft-dependentRequired.json diff --git a/rules/from-draft7/to-2019-09/006-unknown-in-previous-draft-anchor.json b/rules/from-draft7/to-2019-09/009-unknown-in-previous-draft-anchor.json similarity index 100% rename from rules/from-draft7/to-2019-09/006-unknown-in-previous-draft-anchor.json rename to rules/from-draft7/to-2019-09/009-unknown-in-previous-draft-anchor.json diff --git a/rules/from-draft7/to-2019-09/007-unknown-in-previous-draft-vocabulary.json b/rules/from-draft7/to-2019-09/010-unknown-in-previous-draft-vocabulary.json similarity index 100% rename from rules/from-draft7/to-2019-09/007-unknown-in-previous-draft-vocabulary.json rename to rules/from-draft7/to-2019-09/010-unknown-in-previous-draft-vocabulary.json diff --git a/rules/from-draft7/to-2019-09/008-unknown-in-previous-draft-recursiveAnchor.json b/rules/from-draft7/to-2019-09/011-unknown-in-previous-draft-recursiveAnchor.json similarity index 100% rename from rules/from-draft7/to-2019-09/008-unknown-in-previous-draft-recursiveAnchor.json rename to rules/from-draft7/to-2019-09/011-unknown-in-previous-draft-recursiveAnchor.json diff --git a/rules/from-draft7/to-2019-09/009-unknown-in-previous-draft-recursiveRef.json b/rules/from-draft7/to-2019-09/012-unknown-in-previous-draft-recursiveRef.json similarity index 100% rename from rules/from-draft7/to-2019-09/009-unknown-in-previous-draft-recursiveRef.json rename to rules/from-draft7/to-2019-09/012-unknown-in-previous-draft-recursiveRef.json diff --git a/rules/from-draft7/to-2019-09/010-unknown-in-previous-draft-defs.json b/rules/from-draft7/to-2019-09/013-unknown-in-previous-draft-defs.json similarity index 100% rename from rules/from-draft7/to-2019-09/010-unknown-in-previous-draft-defs.json rename to rules/from-draft7/to-2019-09/013-unknown-in-previous-draft-defs.json diff --git a/rules/from-draft7/to-2019-09/011-schema.json b/rules/from-draft7/to-2019-09/014-schema.json similarity index 100% rename from rules/from-draft7/to-2019-09/011-schema.json rename to rules/from-draft7/to-2019-09/014-schema.json diff --git a/rules/from-draft7/to-2019-09/012-id-starts-with-hash.json b/rules/from-draft7/to-2019-09/015-id-starts-with-hash.json similarity index 100% rename from rules/from-draft7/to-2019-09/012-id-starts-with-hash.json rename to rules/from-draft7/to-2019-09/015-id-starts-with-hash.json diff --git a/rules/from-draft7/to-2019-09/013-definitions-to-defs.json b/rules/from-draft7/to-2019-09/016-definitions-to-defs.json similarity index 100% rename from rules/from-draft7/to-2019-09/013-definitions-to-defs.json rename to rules/from-draft7/to-2019-09/016-definitions-to-defs.json diff --git a/rules/from-draft7/to-2019-09/014-dependencies-children-has-type-array.json b/rules/from-draft7/to-2019-09/017-dependencies-children-has-type-array.json similarity index 100% rename from rules/from-draft7/to-2019-09/014-dependencies-children-has-type-array.json rename to rules/from-draft7/to-2019-09/017-dependencies-children-has-type-array.json diff --git a/rules/from-draft7/to-2019-09/015-dependencies-to-dependentRequired.json b/rules/from-draft7/to-2019-09/018-dependencies-to-dependentRequired.json similarity index 100% rename from rules/from-draft7/to-2019-09/015-dependencies-to-dependentRequired.json rename to rules/from-draft7/to-2019-09/018-dependencies-to-dependentRequired.json diff --git a/rules/from-draft7/to-2019-09/016-dependencies-children-has-type-object.json b/rules/from-draft7/to-2019-09/019-dependencies-children-has-type-object.json similarity index 100% rename from rules/from-draft7/to-2019-09/016-dependencies-children-has-type-object.json rename to rules/from-draft7/to-2019-09/019-dependencies-children-has-type-object.json diff --git a/rules/from-draft7/to-2019-09/017-dependencies-to-dependentSchemas.json b/rules/from-draft7/to-2019-09/020-dependencies-to-dependentSchemas.json similarity index 100% rename from rules/from-draft7/to-2019-09/017-dependencies-to-dependentSchemas.json rename to rules/from-draft7/to-2019-09/020-dependencies-to-dependentSchemas.json diff --git a/rules/from-draft7/to-2019-09/018-dependencies-empty-object.json b/rules/from-draft7/to-2019-09/021-dependencies-empty-object.json similarity index 100% rename from rules/from-draft7/to-2019-09/018-dependencies-empty-object.json rename to rules/from-draft7/to-2019-09/021-dependencies-empty-object.json diff --git a/test/from-draft7/to-2019-09/ref.json b/test/from-draft7/to-2019-09/ref.json new file mode 100644 index 0000000..2901c2c --- /dev/null +++ b/test/from-draft7/to-2019-09/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" + } + } + } + } +]