Update jsonschema version
Fixes bug in `uniqueItems` property.
This commit is contained in:
parent
ece3cbc8ec
commit
ef88842204
11 changed files with 602 additions and 180 deletions
141
node_modules/jsonschema/lib/helpers.js
generated
vendored
141
node_modules/jsonschema/lib/helpers.js
generated
vendored
|
|
@ -2,21 +2,23 @@
|
|||
|
||||
var uri = require('url');
|
||||
|
||||
var ValidationError = exports.ValidationError = function ValidationError (message, instance, schema, propertyPath, name, argument) {
|
||||
if (propertyPath) {
|
||||
this.property = propertyPath;
|
||||
var ValidationError = exports.ValidationError = function ValidationError (message, instance, schema, path, name, argument) {
|
||||
if(Array.isArray(path)){
|
||||
this.path = path;
|
||||
this.property = path.reduce(function(sum, item){
|
||||
return sum + makeSuffix(item);
|
||||
}, 'instance');
|
||||
}else if(path !== undefined){
|
||||
this.property = path;
|
||||
}
|
||||
if (message) {
|
||||
this.message = message;
|
||||
}
|
||||
if (schema) {
|
||||
if (schema.id) {
|
||||
this.schema = schema.id;
|
||||
} else {
|
||||
this.schema = schema;
|
||||
}
|
||||
var id = schema.$id || schema.id;
|
||||
this.schema = id || schema;
|
||||
}
|
||||
if (instance) {
|
||||
if (instance !== undefined) {
|
||||
this.instance = instance;
|
||||
}
|
||||
this.name = name;
|
||||
|
|
@ -31,27 +33,33 @@ ValidationError.prototype.toString = function toString() {
|
|||
var ValidatorResult = exports.ValidatorResult = function ValidatorResult(instance, schema, options, ctx) {
|
||||
this.instance = instance;
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.path = ctx.path;
|
||||
this.propertyPath = ctx.propertyPath;
|
||||
this.errors = [];
|
||||
this.throwError = options && options.throwError;
|
||||
this.throwFirst = options && options.throwFirst;
|
||||
this.throwAll = options && options.throwAll;
|
||||
this.disableFormat = options && options.disableFormat === true;
|
||||
};
|
||||
|
||||
ValidatorResult.prototype.addError = function addError(detail) {
|
||||
var err;
|
||||
if (typeof detail == 'string') {
|
||||
err = new ValidationError(detail, this.instance, this.schema, this.propertyPath);
|
||||
err = new ValidationError(detail, this.instance, this.schema, this.path);
|
||||
} else {
|
||||
if (!detail) throw new Error('Missing error detail');
|
||||
if (!detail.message) throw new Error('Missing error message');
|
||||
if (!detail.name) throw new Error('Missing validator type');
|
||||
err = new ValidationError(detail.message, this.instance, this.schema, this.propertyPath, detail.name, detail.argument);
|
||||
err = new ValidationError(detail.message, this.instance, this.schema, this.path, detail.name, detail.argument);
|
||||
}
|
||||
|
||||
if (this.throwError) {
|
||||
this.errors.push(err);
|
||||
if (this.throwFirst) {
|
||||
throw new ValidatorResultError(this);
|
||||
}else if(this.throwError){
|
||||
throw err;
|
||||
}
|
||||
this.errors.push(err);
|
||||
return err;
|
||||
};
|
||||
|
||||
|
|
@ -59,7 +67,7 @@ ValidatorResult.prototype.importErrors = function importErrors(res) {
|
|||
if (typeof res == 'string' || (res && res.validatorType)) {
|
||||
this.addError(res);
|
||||
} else if (res && res.errors) {
|
||||
Array.prototype.push.apply(this.errors, res.errors);
|
||||
this.errors = this.errors.concat(res.errors);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -74,6 +82,20 @@ Object.defineProperty(ValidatorResult.prototype, "valid", { get: function() {
|
|||
return !this.errors.length;
|
||||
} });
|
||||
|
||||
module.exports.ValidatorResultError = ValidatorResultError;
|
||||
function ValidatorResultError(result) {
|
||||
if(Error.captureStackTrace){
|
||||
Error.captureStackTrace(this, ValidatorResultError);
|
||||
}
|
||||
this.instance = result.instance;
|
||||
this.schema = result.schema;
|
||||
this.options = result.options;
|
||||
this.errors = result.errors;
|
||||
}
|
||||
ValidatorResultError.prototype = new Error();
|
||||
ValidatorResultError.prototype.constructor = ValidatorResultError;
|
||||
ValidatorResultError.prototype.name = "Validation Error";
|
||||
|
||||
/**
|
||||
* Describes a problem with a Schema which prevents validation of an instance
|
||||
* @name SchemaError
|
||||
|
|
@ -86,14 +108,22 @@ var SchemaError = exports.SchemaError = function SchemaError (msg, schema) {
|
|||
Error.captureStackTrace(this, SchemaError);
|
||||
};
|
||||
SchemaError.prototype = Object.create(Error.prototype,
|
||||
{ constructor: {value: SchemaError, enumerable: false}
|
||||
, name: {value: 'SchemaError', enumerable: false}
|
||||
{
|
||||
constructor: {value: SchemaError, enumerable: false},
|
||||
name: {value: 'SchemaError', enumerable: false},
|
||||
});
|
||||
|
||||
var SchemaContext = exports.SchemaContext = function SchemaContext (schema, options, propertyPath, base, schemas) {
|
||||
var SchemaContext = exports.SchemaContext = function SchemaContext (schema, options, path, base, schemas) {
|
||||
this.schema = schema;
|
||||
this.options = options;
|
||||
this.propertyPath = propertyPath;
|
||||
if(Array.isArray(path)){
|
||||
this.path = path;
|
||||
this.propertyPath = path.reduce(function(sum, item){
|
||||
return sum + makeSuffix(item);
|
||||
}, 'instance');
|
||||
}else{
|
||||
this.propertyPath = path;
|
||||
}
|
||||
this.base = base;
|
||||
this.schemas = schemas;
|
||||
};
|
||||
|
|
@ -103,36 +133,60 @@ SchemaContext.prototype.resolve = function resolve (target) {
|
|||
};
|
||||
|
||||
SchemaContext.prototype.makeChild = function makeChild(schema, propertyName){
|
||||
var propertyPath = (propertyName===undefined) ? this.propertyPath : this.propertyPath+makeSuffix(propertyName);
|
||||
var base = uri.resolve(this.base, schema.id||'');
|
||||
var ctx = new SchemaContext(schema, this.options, propertyPath, base, Object.create(this.schemas));
|
||||
if(schema.id && !ctx.schemas[base]){
|
||||
var path = (propertyName===undefined) ? this.path : this.path.concat([propertyName]);
|
||||
var id = schema.$id || schema.id;
|
||||
var base = uri.resolve(this.base, id||'');
|
||||
var ctx = new SchemaContext(schema, this.options, path, base, Object.create(this.schemas));
|
||||
if(id && !ctx.schemas[base]){
|
||||
ctx.schemas[base] = schema;
|
||||
}
|
||||
return ctx;
|
||||
}
|
||||
};
|
||||
|
||||
var FORMAT_REGEXPS = exports.FORMAT_REGEXPS = {
|
||||
// 7.3.1. Dates, Times, and Duration
|
||||
'date-time': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])[tT ](2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])(\.\d+)?([zZ]|[+-]([0-5][0-9]):(60|[0-5][0-9]))$/,
|
||||
'date': /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-(3[01]|0[1-9]|[12][0-9])$/,
|
||||
'time': /^(2[0-4]|[01][0-9]):([0-5][0-9]):(60|[0-5][0-9])$/,
|
||||
'duration': /P(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S)|\d+(D|M(\d+D)?|Y(\d+M(\d+D)?)?)(T\d+(H(\d+M(\d+S)?)?|M(\d+S)?|S))?|\d+W)/i,
|
||||
|
||||
// 7.3.2. Email Addresses
|
||||
// TODO: fix the email production
|
||||
'email': /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/,
|
||||
'ip-address': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
||||
'ipv6': /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\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||
'color': /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,
|
||||
// 7.3.3. Hostnames
|
||||
|
||||
// 7.3.4. IP Addresses
|
||||
'ip-address': /^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/,
|
||||
// FIXME whitespace is invalid
|
||||
'ipv6': /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\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A-Za-z][+\-.0-9A-Za-z]*:?)?$/u,
|
||||
'uuid': /^[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}$/i,
|
||||
|
||||
// 7.3.6. uri-template
|
||||
'uri-template': /(%[0-9a-f]{2}|[!#$&(-;=?@\[\]_a-z~]|\{[!#&+,./;=?@|]?(%[0-9a-f]{2}|[0-9_a-z])(\.?(%[0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?(,(%[0-9a-f]{2}|[0-9_a-z])(\.?(%[0-9a-f]{2}|[0-9_a-z]))*(:[1-9]\d{0,3}|\*)?)*\})*/iu,
|
||||
|
||||
// 7.3.7. JSON Pointers
|
||||
'json-pointer': /^(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*$/iu,
|
||||
'relative-json-pointer': /^\d+(#|(\/([\x00-\x2e0-@\[-}\x7f]|~[01])*)*)$/iu,
|
||||
|
||||
// hostname regex from: http://stackoverflow.com/a/1420225/5628
|
||||
'hostname': /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,
|
||||
'host-name': /^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\.?$/,
|
||||
|
||||
'alpha': /^[a-zA-Z]+$/,
|
||||
'alphanumeric': /^[a-zA-Z0-9]+$/,
|
||||
'utc-millisec': function (input) {
|
||||
return (typeof input === 'string') && parseFloat(input) === parseInt(input, 10) && !isNaN(input);
|
||||
},
|
||||
|
||||
// 7.3.8. regex
|
||||
'regex': function (input) {
|
||||
var result = true;
|
||||
try {
|
||||
|
|
@ -142,8 +196,15 @@ var FORMAT_REGEXPS = exports.FORMAT_REGEXPS = {
|
|||
}
|
||||
return result;
|
||||
},
|
||||
'style': /\s*(.+?):\s*([^;]+);?/,
|
||||
'phone': /^\+(?:[0-9] ?){6,14}[0-9]$/
|
||||
|
||||
// Other definitions
|
||||
// "style" was removed from JSON Schema in draft-4 and is deprecated
|
||||
'style': /[\r\n\t ]*[^\r\n\t ][^:]*:[\r\n\t ]*[^\r\n\t ;]*[\r\n\t ]*;?/,
|
||||
// "color" was removed from JSON Schema in draft-4 and is deprecated
|
||||
'color': /^(#?([0-9A-Fa-f]{3}){1,2}\b|aqua|black|blue|fuchsia|gray|green|lime|maroon|navy|olive|orange|purple|red|silver|teal|white|yellow|(rgb\(\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*,\s*\b([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b\s*\))|(rgb\(\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*,\s*(\d?\d%|100%)+\s*\)))$/,
|
||||
'phone': /^\+(?:[0-9] ?){6,14}[0-9]$/,
|
||||
'alpha': /^[a-zA-Z]+$/,
|
||||
'alphanumeric': /^[a-zA-Z0-9]+$/,
|
||||
};
|
||||
|
||||
FORMAT_REGEXPS.regexp = FORMAT_REGEXPS.regex;
|
||||
|
|
@ -212,10 +273,10 @@ exports.deepCompareStrict = function deepCompareStrict (a, b) {
|
|||
|
||||
function deepMerger (target, dst, e, i) {
|
||||
if (typeof e === 'object') {
|
||||
dst[i] = deepMerge(target[i], e)
|
||||
dst[i] = deepMerge(target[i], e);
|
||||
} else {
|
||||
if (target.indexOf(e) === -1) {
|
||||
dst.push(e)
|
||||
dst.push(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -232,7 +293,7 @@ function copyistWithDeepMerge (target, src, dst, key) {
|
|||
if (!target[key]) {
|
||||
dst[key] = src[key];
|
||||
} else {
|
||||
dst[key] = deepMerge(target[key], src[key])
|
||||
dst[key] = deepMerge(target[key], src[key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -253,7 +314,7 @@ function deepMerge (target, src) {
|
|||
}
|
||||
|
||||
return dst;
|
||||
};
|
||||
}
|
||||
|
||||
module.exports.deepMerge = deepMerge;
|
||||
|
||||
|
|
@ -284,9 +345,9 @@ function pathEncoder (v) {
|
|||
* @return {String}
|
||||
*/
|
||||
exports.encodePath = function encodePointer(a){
|
||||
// ~ must be encoded explicitly because hacks
|
||||
// the slash is encoded by encodeURIComponent
|
||||
return a.map(pathEncoder).join('');
|
||||
// ~ must be encoded explicitly because hacks
|
||||
// the slash is encoded by encodeURIComponent
|
||||
return a.map(pathEncoder).join('');
|
||||
};
|
||||
|
||||
|
||||
|
|
@ -323,3 +384,7 @@ exports.getDecimalPlaces = function getDecimalPlaces(number) {
|
|||
return decimalPlaces;
|
||||
};
|
||||
|
||||
exports.isSchema = function isSchema(val){
|
||||
return (typeof val === 'object' && val) || (typeof val === 'boolean');
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue