Comparing version 0.3.0 to 0.4.0
'use strict'; | ||
var clone = module.exports = function(obj) { | ||
var clone = module.exports = function(obj, seen) { | ||
seen = seen || []; | ||
if (seen.indexOf(obj) > -1) { | ||
throw new Error('unable dereference circular structures'); | ||
} | ||
if (!obj || typeof obj !== 'object') { | ||
@@ -8,6 +14,8 @@ return obj; | ||
seen.push(obj); | ||
var target = Array.isArray(obj) ? [] : {}; | ||
function copy(key, value) { | ||
target[key] = clone(value); | ||
target[key] = clone(value, seen); | ||
} | ||
@@ -14,0 +22,0 @@ |
@@ -7,51 +7,31 @@ 'use strict'; | ||
function clone(obj, refs, child, expand) { | ||
var copy = {}; | ||
function copy(obj, refs, parent) { | ||
var target = Array.isArray(obj) ? [] : {}; | ||
if (Array.isArray(obj)) { | ||
copy = []; | ||
} | ||
if (typeof obj.$ref === 'string') { | ||
var base = $.getDocumentURI(obj.$ref); | ||
if ($.isURL(obj.$ref)) { | ||
var fixed = find(obj.$ref, refs); | ||
if (fixed && expand) { | ||
var id = typeof fixed.id === 'string' ? fixed.id : '#'; | ||
obj = fixed; | ||
if (obj.$ref !== id) { | ||
return clone(fixed, refs, true, expand); | ||
} | ||
delete obj.$ref; | ||
if (parent !== base) { | ||
obj = find(obj.$ref, refs); | ||
} | ||
} | ||
for (var key in obj) { | ||
var value = obj[key]; | ||
for (var prop in obj) { | ||
var value = obj[prop]; | ||
if (typeof value === 'object' && !(key === 'enum' || key === 'required')) { | ||
copy[key] = clone(value, refs, true, expand); | ||
if (typeof value === 'object' && !(prop === 'enum' || prop === 'required')) { | ||
target[prop] = copy(value, refs, parent); | ||
} else { | ||
copy[key] = value; | ||
target[prop] = value; | ||
} | ||
} | ||
// TODO: seriously are required or not? | ||
if (child) { | ||
if (typeof copy.$schema === 'string') { | ||
delete copy.$schema; | ||
} | ||
return target; | ||
} | ||
if (typeof copy.id === 'string') { | ||
delete copy.id; | ||
} | ||
} | ||
module.exports = function(obj, refs) { | ||
var fixedId = $.resolveURL(obj.$schema, obj.id), | ||
parent = $.getDocumentURI(fixedId); | ||
return copy; | ||
} | ||
module.exports = function(obj, refs, expand) { | ||
return clone(obj, refs, false, expand); | ||
return copy(obj, refs, parent); | ||
}; |
@@ -6,2 +6,5 @@ 'use strict'; | ||
function URLUtils(url, baseURL) { | ||
// remove leading ./ | ||
url = url.replace(/^\.\//, ''); | ||
var m = String(url).replace(/^\s+|\s+$/g, '').match(/^([^:\/?#]+:)?(?:\/\/(?:([^:@]*)(?::([^:@]*))?@)?(([^:\/?#]*)(?::(\d*))?))?([^?#]*)(\?[^#]*)?(#[\s\S]*)?/); | ||
@@ -8,0 +11,0 @@ if (!m) { |
{ | ||
"name": "deref", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "JSON-Schema $ref resolution", | ||
"main": "lib/index.js", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/gextech/deref" | ||
"url": "https://github.com/json-schema-faker/deref" | ||
}, | ||
"license": "MIT", | ||
"devDependencies": { | ||
@@ -14,6 +16,6 @@ "clone": "^0.1.19", | ||
"grunt": "^0.4.5", | ||
"grunt-parts": "^0.4.0", | ||
"grunt-parts": "^0.5.7", | ||
"is-my-json-valid": "^2.12.2", | ||
"jayschema": "^0.3.1", | ||
"tv4": "^1.1.9", | ||
"z-schema": "^3.9.5" | ||
"tv4": "^1.2.3" | ||
}, | ||
@@ -20,0 +22,0 @@ "publishConfig": { |
@@ -5,2 +5,4 @@ | ||
[![Build Status](https://travis-ci.org/json-schema-faker/deref.png?branch=master)](https://travis-ci.org/json-schema-faker/deref) [![NPM version](https://badge.fury.io/js/deref.png)](http://badge.fury.io/js/deref) [![Coverage Status](https://coveralls.io/repos/json-schema-faker/deref/badge.png?branch=master)](https://coveralls.io/r/json-schema-faker/deref?branch=master) | ||
A simple way for solving `$ref` values: | ||
@@ -151,3 +153,1 @@ | ||
Note that calling `$(schema)` will not read/download any local/remote files. | ||
[![Build Status](https://travis-ci.org/gextech/deref.png?branch=master)](https://travis-ci.org/gextech/deref) [![NPM version](https://badge.fury.io/js/deref.png)](http://badge.fury.io/js/deref) [![Coverage Status](https://coveralls.io/repos/gextech/deref/badge.png?branch=master)](https://coveralls.io/r/gextech/deref?branch=master) |
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
No License Found
License(Experimental) License information could not be found.
Found 1 instance in 1 package
12401
9
0
264