@stoplight/json-schema-ref-parser
Advanced tools
Comparing version 9.1.3 to 9.1.4
@@ -19,3 +19,3 @@ "use strict"; | ||
// console.log('Dereferencing $ref pointers in %s', parser.$refs._root$Ref.path); | ||
let dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", [], [], {}, parser.$refs, options); | ||
let dereferenced = crawl(parser.schema, parser.$refs._root$Ref.path, "#", [], {}, parser.$refs, options); | ||
parser.$refs.circular = dereferenced.circular; | ||
@@ -32,3 +32,2 @@ parser.schema = dereferenced.value; | ||
* @param {object[]} parents - An array of the parent objects that have already been dereferenced | ||
* @param {object[]} processedObjects - An array of all the objects that have already been processed | ||
* @param {object} dereferencedCache - An map of all the dereferenced objects | ||
@@ -39,3 +38,3 @@ * @param {$Refs} $refs | ||
*/ | ||
function crawl (obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) { | ||
function crawl (obj, path, pathFromRoot, parents, dereferencedCache, $refs, options) { | ||
let dereferenced; | ||
@@ -47,21 +46,28 @@ let result = { | ||
if (options.dereference.circular === "ignore" || processedObjects.indexOf(obj) === -1) { | ||
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) { | ||
parents.push(obj); | ||
processedObjects.push(obj); | ||
if (obj && typeof obj === "object" && !ArrayBuffer.isView(obj)) { | ||
parents.push(obj); | ||
if ($Ref.isAllowed$Ref(obj, options)) { | ||
dereferenced = dereference$Ref(obj, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options); | ||
result.circular = dereferenced.circular; | ||
result.value = dereferenced.value; | ||
} | ||
else { | ||
for (let key of Object.keys(obj)) { | ||
let keyPath = Pointer.join(path, key); | ||
let keyPathFromRoot = Pointer.join(pathFromRoot, key); | ||
let value = obj[key]; | ||
let circular = false; | ||
if ($Ref.isAllowed$Ref(obj, options)) { | ||
dereferenced = dereference$Ref(obj, path, pathFromRoot, parents, dereferencedCache, $refs, options); | ||
result.circular = dereferenced.circular; | ||
result.value = dereferenced.value; | ||
} | ||
else { | ||
for (let key of Object.keys(obj)) { | ||
let keyPath = Pointer.join(path, key); | ||
let keyPathFromRoot = Pointer.join(pathFromRoot, key); | ||
let value = obj[key]; | ||
let circular = false; | ||
if ($Ref.isAllowed$Ref(value, options)) { | ||
dereferenced = dereference$Ref(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options); | ||
if ($Ref.isAllowed$Ref(value, options)) { | ||
dereferenced = dereference$Ref(value, keyPath, keyPathFromRoot, parents, dereferencedCache, $refs, options); | ||
circular = dereferenced.circular; | ||
// Avoid pointless mutations; breaks frozen objects to no profit | ||
if (obj[key] !== dereferenced.value) { | ||
obj[key] = dereferenced.value; | ||
} | ||
} | ||
else { | ||
if (parents.indexOf(value) === -1) { | ||
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, dereferencedCache, $refs, options); | ||
circular = dereferenced.circular; | ||
@@ -74,22 +80,12 @@ // Avoid pointless mutations; breaks frozen objects to no profit | ||
else { | ||
if (parents.indexOf(value) === -1) { | ||
dereferenced = crawl(value, keyPath, keyPathFromRoot, parents, processedObjects, dereferencedCache, $refs, options); | ||
circular = dereferenced.circular; | ||
// Avoid pointless mutations; breaks frozen objects to no profit | ||
if (obj[key] !== dereferenced.value) { | ||
obj[key] = dereferenced.value; | ||
} | ||
} | ||
else { | ||
circular = foundCircularReference(keyPath, $refs, options); | ||
} | ||
circular = foundCircularReference(keyPath, $refs, options); | ||
} | ||
} | ||
// Set the "isCircular" flag if this or any other property is circular | ||
result.circular = result.circular || circular; | ||
} | ||
// Set the "isCircular" flag if this or any other property is circular | ||
result.circular = result.circular || circular; | ||
} | ||
} | ||
parents.pop(); | ||
} | ||
parents.pop(); | ||
} | ||
@@ -107,3 +103,3 @@ | ||
* @param {object[]} parents - An array of the parent objects that have already been dereferenced | ||
* @param {object[]} processedObjects - An array of all the objects that have already been dereferenced | ||
* @param {object} dereferencedCache - An map of all the dereferenced objects | ||
* @param {$Refs} $refs | ||
@@ -113,3 +109,3 @@ * @param {$RefParserOptions} options | ||
*/ | ||
function dereference$Ref ($ref, path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options) { | ||
function dereference$Ref ($ref, path, pathFromRoot, parents, dereferencedCache, $refs, options) { | ||
// console.log('Dereferencing $ref pointer "%s" at %s', $ref.$ref, path); | ||
@@ -139,3 +135,2 @@ | ||
let pointer = $refs._resolve($refPath, path, options); | ||
@@ -161,3 +156,3 @@ | ||
// Determine if the dereferenced value is circular | ||
let dereferenced = crawl(dereferencedValue, pointer.path, pathFromRoot, parents, processedObjects, dereferencedCache, $refs, options); | ||
let dereferenced = crawl(dereferencedValue, pointer.path, pathFromRoot, parents, dereferencedCache, $refs, options); | ||
circular = dereferenced.circular; | ||
@@ -164,0 +159,0 @@ dereferencedValue = dereferenced.value; |
{ | ||
"name": "@stoplight/json-schema-ref-parser", | ||
"version": "9.1.3", | ||
"version": "9.1.4", | ||
"description": "Parse, Resolve, and Dereference JSON Schema $ref pointers", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173620
3759