@json-schema-tools/traverse
Advanced tools
Comparing version 1.8.1 to 1.9.0
@@ -7,3 +7,3 @@ import { JSONSchema } from "@json-schema-tools/meta-schema"; | ||
* @param isCycle false if the schema passed is not the root of a detected cycle. Useful for special handling of cycled schemas. | ||
* @param path json path string separated by periods | ||
* @param path json-path string in dot-notation as per [draft-goessner-dispatch-jsonpath-00](https://www.ietf.org/archive/id/draft-goessner-dispatch-jsonpath-00.html#name-overview-of-jsonpath-expres) | ||
*/ | ||
@@ -10,0 +10,0 @@ export declare type MutationFunction = (schema: JSONSchema, isCycle: boolean, path: string) => JSONSchema; |
@@ -13,6 +13,10 @@ "use strict"; | ||
}; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from) { | ||
for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) | ||
to[j] = from[i]; | ||
return to; | ||
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { | ||
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { | ||
if (ar || !(i in from)) { | ||
if (!ar) ar = Array.prototype.slice.call(from, 0, i); | ||
ar[i] = from[i]; | ||
} | ||
} | ||
return to.concat(ar || Array.prototype.slice.call(from)); | ||
}; | ||
@@ -27,3 +31,10 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var jsonPathStringify = function (s) { | ||
return s.map(function (i) { return i === "" ? i.toString() : ("/" + i.toString()); }).join(""); | ||
return s.map(function (i) { | ||
if (i === "") { | ||
return '$'; | ||
} | ||
else { | ||
return ".".concat(i); | ||
} | ||
}).join(""); | ||
}; | ||
@@ -102,3 +113,3 @@ var isCycle = function (s, recursiveStack) { | ||
mutableSchema.anyOf = schema.anyOf.map(function (x, i) { | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack), ["anyOf", i.toString()])); | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack, true), ["anyOf[".concat(i, "]")], false)); | ||
return result; | ||
@@ -109,3 +120,3 @@ }); | ||
mutableSchema.allOf = schema.allOf.map(function (x, i) { | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack), ["allOf", i.toString()])); | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack, true), ["allOf[".concat(i, "]")], false)); | ||
return result; | ||
@@ -116,3 +127,3 @@ }); | ||
mutableSchema.oneOf = schema.oneOf.map(function (x, i) { | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack), ["oneOf", i.toString()])); | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack, true), ["oneOf[".concat(i, "]")], false)); | ||
return result; | ||
@@ -126,3 +137,3 @@ }); | ||
mutableSchema.items = schema.items.map(function (x, i) { | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack), ["items", i.toString()])); | ||
var result = rec(x, __spreadArray(__spreadArray([], pathStack, true), ["items[".concat(i, "]")], false)); | ||
return result; | ||
@@ -148,3 +159,3 @@ }); | ||
itemsIsSingleSchema = true; | ||
mutableSchema.items = traverse(schema.items, mutation, traverseOptions, depth + 1, recursiveStack, pathStack, prePostMap, cycleSet); | ||
mutableSchema.items = traverse(schema.items, mutation, traverseOptions, depth + 1, recursiveStack, __spreadArray(__spreadArray([], pathStack, true), ["items"], false), prePostMap, cycleSet); | ||
} | ||
@@ -154,3 +165,3 @@ } | ||
if (schema.additionalItems !== undefined && !!schema.additionalItems === true && !itemsIsSingleSchema) { | ||
mutableSchema.additionalItems = rec(schema.additionalItems, __spreadArray(__spreadArray([], pathStack), ["additionalItems"])); | ||
mutableSchema.additionalItems = rec(schema.additionalItems, __spreadArray(__spreadArray([], pathStack, true), ["additionalItems"], false)); | ||
} | ||
@@ -161,3 +172,3 @@ if (schema.properties !== undefined) { | ||
Object.keys(schema.properties).forEach(function (schemaPropKey) { | ||
mutableProps_1[schemaPropKey] = rec(sProps_1[schemaPropKey], __spreadArray(__spreadArray([], pathStack), ["properties", schemaPropKey.toString()])); | ||
mutableProps_1[schemaPropKey] = rec(sProps_1[schemaPropKey], __spreadArray(__spreadArray([], pathStack, true), ["properties", schemaPropKey.toString()], false)); | ||
}); | ||
@@ -170,3 +181,3 @@ mutableSchema.properties = mutableProps_1; | ||
Object.keys(schema.patternProperties).forEach(function (regex) { | ||
mutableProps_2[regex] = rec(sProps_2[regex], __spreadArray(__spreadArray([], pathStack), ["patternProperties", regex.toString()])); | ||
mutableProps_2[regex] = rec(sProps_2[regex], __spreadArray(__spreadArray([], pathStack, true), ["patternProperties", regex.toString()], false)); | ||
}); | ||
@@ -176,3 +187,3 @@ mutableSchema.patternProperties = mutableProps_2; | ||
if (schema.additionalProperties !== undefined && !!schema.additionalProperties === true) { | ||
mutableSchema.additionalProperties = rec(schema.additionalProperties, __spreadArray(__spreadArray([], pathStack), ["additionalProperties"])); | ||
mutableSchema.additionalProperties = rec(schema.additionalProperties, __spreadArray(__spreadArray([], pathStack, true), ["additionalProperties"], false)); | ||
} | ||
@@ -179,0 +190,0 @@ } |
{ | ||
"name": "@json-schema-tools/traverse", | ||
"version": "1.8.1", | ||
"version": "1.9.0", | ||
"description": "This package exports a method that will traverse a JSON-Schema, calling a mutation function for each sub schema found. It is useful for building tools to work with JSON Schemas.", | ||
@@ -30,14 +30,13 @@ "main": "build/index.js", | ||
"devDependencies": { | ||
"@json-schema-tools/meta-schema": "^1.6.18", | ||
"@types/jest": "^26.0.23", | ||
"@types/node": "^15.12.3", | ||
"@typescript-eslint/eslint-plugin": "^4.27.0", | ||
"@typescript-eslint/parser": "^4.27.0", | ||
"eslint": "^7.28.0", | ||
"jest": "^26.6.3", | ||
"ts-jest": "^26.5.6", | ||
"typedoc": "^0.21.0", | ||
"typescript": "4.3.4" | ||
}, | ||
"dependencies": {} | ||
"@json-schema-tools/meta-schema": "^1.7.0", | ||
"@types/jest": "^29.1.1", | ||
"@types/node": "^18.8.2", | ||
"@typescript-eslint/eslint-plugin": "^5.39.0", | ||
"@typescript-eslint/parser": "^5.39.0", | ||
"eslint": "^8.24.0", | ||
"jest": "^29.1.2", | ||
"ts-jest": "^29.0.3", | ||
"typedoc": "^0.23.15", | ||
"typescript": "^4.8.4" | ||
} | ||
} |
@@ -57,2 +57,6 @@ # JSON Schema Traverse | ||
## API Docs | ||
https://json-schema-tools.github.io/traverse/ | ||
## Features Todo | ||
@@ -59,0 +63,0 @@ |
237
71
25724
5