Comparing version 0.6.4 to 0.7.0
@@ -9,10 +9,12 @@ 'use strict'; | ||
function copy(obj, refs, parent, resolve) { | ||
function copy(_, obj, refs, parent, resolve) { | ||
var target = Array.isArray(obj) ? [] : {}; | ||
if (typeof obj.$ref === 'string') { | ||
var base = $.getDocumentURI(obj.$ref); | ||
var id = obj.$ref; | ||
var base = $.getDocumentURI(id); | ||
var local = id.indexOf('#/') > -1; | ||
if (parent !== base || (resolve && obj.$ref.indexOf('#/') > -1)) { | ||
var fixed = find(obj.$ref, refs); | ||
if (local || (resolve && base !== parent)) { | ||
var fixed = find(id, refs); | ||
@@ -24,2 +26,8 @@ deepExtend(obj, fixed); | ||
} | ||
if (_[id]) { | ||
return obj; | ||
} | ||
_[id] = 1; | ||
} | ||
@@ -29,3 +37,3 @@ | ||
if (typeof obj[prop] === 'object' && obj[prop] !== null && !$.isKeyword(prop)) { | ||
target[prop] = copy(obj[prop], refs, parent, resolve); | ||
target[prop] = copy(_, obj[prop], refs, parent, resolve); | ||
} else { | ||
@@ -43,3 +51,3 @@ target[prop] = obj[prop]; | ||
return copy(obj, refs, parent, resolve); | ||
return copy({}, obj, refs, parent, resolve); | ||
}; |
{ | ||
"name": "deref", | ||
"version": "0.6.4", | ||
"version": "0.7.0", | ||
"description": "JSON-Schema $ref resolution", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
62516
10
287