is-my-json-valid
Advanced tools
Comparing version 2.11.0 to 2.12.0
19
index.js
@@ -27,3 +27,20 @@ var genobj = require('generate-object-property') | ||
} catch (err) { | ||
var other = additionalSchemas[ptr] || additionalSchemas[ptr.replace(/^#/, '')] | ||
var end = ptr.indexOf('#') | ||
var other | ||
// external reference | ||
if (end !== 0) { | ||
// fragment doesn't exist. | ||
if (end === -1) { | ||
other = additionalSchemas[ptr] | ||
} else { | ||
var ext = ptr.slice(0, end) | ||
other = additionalSchemas[ext] | ||
var fragment = ptr.slice(end).replace(/^#/, '') | ||
try { | ||
return jsonpointer.get(other, fragment) | ||
} catch (err) {} | ||
} | ||
} else { | ||
other = additionalSchemas[ptr] | ||
} | ||
return other || null | ||
@@ -30,0 +47,0 @@ } |
{ | ||
"name": "is-my-json-valid", | ||
"version": "2.11.0", | ||
"version": "2.12.0", | ||
"description": "A JSONSchema validator that uses code generation to be extremely fast", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -281,2 +281,32 @@ var tape = require('tape') | ||
tape('top-level external schema', function(t) { | ||
var defs = { | ||
"string": { | ||
type: "string" | ||
}, | ||
"sex": { | ||
type: "string", | ||
enum: ["male", "female", "other"] | ||
} | ||
} | ||
var schema = { | ||
type: "object", | ||
properties: { | ||
"name": { $ref: "definitions.json#/string" }, | ||
"sex": { $ref: "definitions.json#/sex" } | ||
}, | ||
required: ["name", "sex"] | ||
} | ||
var validate = validator(schema, { | ||
schemas: { | ||
"definitions.json": defs | ||
} | ||
}) | ||
t.ok(validate({name:"alice", sex:"female"}), 'is an object') | ||
t.notOk(validate({name:"alice", sex: "bob"}), 'recognizes external schema') | ||
t.notOk(validate({name:2, sex: "female"}), 'recognizes external schema') | ||
t.end() | ||
}) | ||
tape('nested required array decl', function(t) { | ||
@@ -283,0 +313,0 @@ var 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
102365
3272