Comparing version 0.2.1 to 0.2.2
'use strict'; | ||
var $ = require('./uri-helpers'), | ||
jsptr = require('jsonpointer'); | ||
var $ = require('./uri-helpers'); | ||
function get(obj, path) { | ||
var hash = path.split('#')[1]; | ||
if (hash.charAt() === '/') { | ||
var parts = hash.replace(/~1/g, '/').replace(/~0/g, '~').split('/').slice(1); | ||
while (parts.length) { | ||
var key = parts.shift(); | ||
if (typeof obj[key] === 'undefined') { | ||
throw new Error('Reference not found: ' + path); | ||
} | ||
obj = obj[key]; | ||
} | ||
return obj; | ||
} | ||
} | ||
function clone(obj, refs, child, expand) { | ||
@@ -20,8 +39,4 @@ var copy = {}; | ||
if (obj.$ref.indexOf('#') > -1) { | ||
var hash = obj.$ref.split('#')[1]; | ||
fixed = get(refs[uri], obj.$ref) || fixed; | ||
if (hash.charAt() === '/') { | ||
fixed = jsptr.get(refs[uri], hash); | ||
} | ||
// TODO: otherwise? (i.e. http://example.com/schema#someId) | ||
@@ -28,0 +43,0 @@ // console.log('REF (find by?)', obj.$ref, typeof refs[uri], uri === obj.$ref); |
{ | ||
"name": "deref", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "JSON-Schema $ref resolution", | ||
@@ -17,6 +17,3 @@ "main": "lib/index.js", | ||
"z-schema": "^3.1.3" | ||
}, | ||
"dependencies": { | ||
"jsonpointer": "^1.1.0" | ||
} | ||
} |
9686
0
238
- Removedjsonpointer@^1.1.0
- Removedjsonpointer@1.1.0(transitive)