diff --git a/bindings/node/index.js b/bindings/node/index.js index b68f1e1..ba74a12 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -35,14 +35,6 @@ async function transformer (root, path, ruleset, trails, originalSchema, from) { } return false - }, - - // TODO: Use standard JSON-e operators instead - omit: (object, keys) => { - return _.omit(object, _.castArray(keys)) - }, - replace: (value, regex, replacement) => { - return value.replace(new RegExp(regex, 'g'), replacement) } }) diff --git a/rules/jsonschema-2019-09-to-2019-09.json b/rules/jsonschema-2019-09-to-2019-09.json index dd59c0c..21fa0b1 100644 --- a/rules/jsonschema-2019-09-to-2019-09.json +++ b/rules/jsonschema-2019-09-to-2019-09.json @@ -15,7 +15,17 @@ } }, "transform": { - "$eval": "omit(schema, 'dependentSchemas')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependentSchemas'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -32,7 +42,17 @@ } }, "transform": { - "$eval": "omit(schema, 'dependentRequired')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependentRequired'", + "then": { + "$eval": "v" + } + } + } } } ] diff --git a/rules/jsonschema-2019-09-to-2020-12.json b/rules/jsonschema-2019-09-to-2020-12.json index 3728567..7e94865 100644 --- a/rules/jsonschema-2019-09-to-2020-12.json +++ b/rules/jsonschema-2019-09-to-2020-12.json @@ -38,7 +38,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'items')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='items'", + "then": { + "$eval": "v" + } + } + } }, { "prefixItems": { "$eval": "schema.items" @@ -64,10 +74,23 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/items/(\\d+)', '/prefixItems/$1')" + "$if": "split(schema['$ref'], 'items')[1][1] in '1234567890'", + "then":{ + "$eval": "join(split(schema['$ref'], 'items'), 'prefixItems')" + } } } ] @@ -90,10 +113,20 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/additionalItems', '/items')" + "$eval": "join(split(schema['$ref'], 'additionalItems'), 'items')" } } ] @@ -116,7 +149,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'additionalItems')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='additionalItems'", + "then": { + "$eval": "v" + } + } + } }, { "items": { "$eval": "schema.additionalItems" @@ -167,7 +210,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" @@ -190,7 +243,17 @@ } }, "transform": { - "$eval": "omit(schema, '$recursiveAnchor')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveAnchor'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -208,7 +271,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$recursiveAnchor')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveAnchor'", + "then": { + "$eval": "v" + } + } + } }, { "$$dynamicAnchor": { "$eval": "'anchor-' + jsonHash(original)" @@ -232,7 +305,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$recursiveRef')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$recursiveRef'", + "then": { + "$eval": "v" + } + } + } }, { "$$dynamicRef": { "$if": "hasContext('$recursiveAnchor', true)", diff --git a/rules/jsonschema-draft3-to-draft4.json b/rules/jsonschema-draft3-to-draft4.json index bbb41aa..281247e 100644 --- a/rules/jsonschema-draft3-to-draft4.json +++ b/rules/jsonschema-draft3-to-draft4.json @@ -35,7 +35,17 @@ } }, "transform": { - "$eval": "omit(schema, 'type')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='type'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -55,7 +65,17 @@ } }, "transform": { - "$eval": "omit(schema, 'type')" + "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='type'", + "then": { + "$eval": "v" + } + } + } } }, { @@ -73,7 +93,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'divisibleBy')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='divisibleBy'", + "then": { + "$eval": "v" + } + } + } }, { "multipleOf": { "$eval": "schema.divisibleBy" diff --git a/rules/jsonschema-draft4-to-draft6.json b/rules/jsonschema-draft4-to-draft6.json index c3f4127..9f76891 100644 --- a/rules/jsonschema-draft4-to-draft6.json +++ b/rules/jsonschema-draft4-to-draft6.json @@ -36,7 +36,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'id')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='id'", + "then": { + "$eval": "v" + } + } + } }, { "$$id": { "$eval": "schema.id" @@ -63,7 +73,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'minimum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='minimum'", + "then": { + "$eval": "v" + } + } + } }, { "exclusiveMinimum": { "$eval": "schema.minimum" @@ -90,7 +110,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'maximum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='maximum'", + "then": { + "$eval": "v" + } + } + } }, { "exclusiveMaximum": { "$eval": "schema.maximum" @@ -117,7 +147,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'exclusiveMinimum')" } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='exclusiveMinimum'", + "then": { + "$eval": "v" + } + } + } } ] } }, @@ -139,7 +179,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'exclusiveMaximum')" } + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='exclusiveMaximum'", + "then": { + "$eval": "v" + } + } + } } ] } }, @@ -182,7 +232,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" diff --git a/rules/jsonschema-draft6-to-draft7.json b/rules/jsonschema-draft6-to-draft7.json index 7557e41..63d7fd8 100644 --- a/rules/jsonschema-draft6-to-draft7.json +++ b/rules/jsonschema-draft6-to-draft7.json @@ -60,7 +60,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + }}, { "const": { "$eval": "schema.enum[0]" diff --git a/rules/jsonschema-draft7-to-2019-09.json b/rules/jsonschema-draft7-to-2019-09.json index 6a0621f..81f7bd9 100644 --- a/rules/jsonschema-draft7-to-2019-09.json +++ b/rules/jsonschema-draft7-to-2019-09.json @@ -37,7 +37,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$id')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$id'", + "then": { + "$eval": "v" + } + } + } }, { "$$anchor": { "$eval": "schema['$id'][1:]" @@ -61,7 +71,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'definitions')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='definitions'", + "then": { + "$eval": "v" + } + } + }}, { "$$defs": { "$eval": "schema.definitions" @@ -86,10 +106,20 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, '$ref')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='$ref'", + "then": { + "$eval": "v" + } + } + } }, { "$$ref": { - "$eval": "replace(schema['$ref'], '/definitions/', '/$defs/')" + "$eval": "join(split(schema['$ref'], 'definitions'), '$defs')" } } ] @@ -134,7 +164,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'enum')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='enum'", + "then": { + "$eval": "v" + } + } + } }, { "const": { "$eval": "schema.enum[0]" @@ -158,7 +198,17 @@ }, "transform": { "$merge": [ - { "$eval": "omit(schema, 'dependencies')" }, + { "$map": { + "$eval": "schema" + }, + "each(v,k)": { + "${k}": { + "$if": "k!='dependencies'", + "then": { + "$eval": "v" + } + } + } }, { "dependentRequired": { "$map": {