Comparing version 0.1.1 to 0.1.2
@@ -77,2 +77,16 @@ 'use strict'; | ||
function refFromId(obj, ref) { | ||
if (obj && typeof obj === 'object') { | ||
if (obj.id === ref) { | ||
return obj; | ||
} | ||
return Object.keys(obj).reduce(function (resolved, key) { | ||
return resolved || refFromId(obj[key], ref); | ||
}, undefined); | ||
} | ||
return undefined; | ||
} | ||
function SchemaResolver(rootSchema) { | ||
@@ -97,3 +111,8 @@ this.rootSchema = rootSchema; | ||
} | ||
else { | ||
if (!dest) { | ||
dest = refFromId(root, ref); | ||
} | ||
if (!dest) { | ||
path = refToPath(ref); | ||
@@ -100,0 +119,0 @@ |
{ | ||
"name": "jsen", | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"description": "JSON-Schema validator built for speed.", | ||
@@ -5,0 +5,0 @@ "author": "Veli Pehlivanov <bugventure@gmail.com>", |
@@ -36,2 +36,3 @@ JSEN | ||
- [Changelog](#changelog) | ||
- [v0.1.2](#v012) | ||
- [v0.1.1](#v011) | ||
@@ -506,2 +507,6 @@ - [v0.1.0](#v010) | ||
### v0.1.2 | ||
* Fix cannot dereference schema when ids change resolution scope (#14) | ||
### v0.1.1 | ||
@@ -508,0 +513,0 @@ |
@@ -35,2 +35,41 @@ 'use strict'; | ||
}); | ||
it('Fix cannot dereference schema when ids change resolution scope (#14)', function () { | ||
var schema = { | ||
$ref: '#child', | ||
definitions: { | ||
child: { | ||
id: '#child', | ||
type: 'string' | ||
} | ||
} | ||
}, | ||
validate; | ||
assert.doesNotThrow(function () { | ||
validate = jsen(schema); | ||
}); | ||
assert(validate('abc')); | ||
assert(!validate(123)); | ||
schema = { | ||
$ref: '#child/definitions/subchild', | ||
definitions: { | ||
child: { | ||
id: '#child', | ||
definitions: { | ||
subchild: { | ||
type: 'number' | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
assert.throws(function () { | ||
// cannot dereference a URI, part of which is an ID | ||
validate = jsen(schema); | ||
}); | ||
}); | ||
}); |
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
172055
4870
551