Comparing version 0.2.1 to 0.3.0
104
jjve.js
@@ -12,3 +12,4 @@ (function() { | ||
var leaf = keys.every(function(key) { | ||
return typeof o.validation[key] !== 'object'; | ||
return typeof o.validation[key] !== 'object' || | ||
isArray(o.validation[key]); | ||
}); | ||
@@ -38,3 +39,4 @@ | ||
message: 'Invalid type: ' + type + ' should be ' + | ||
o.validation[key], | ||
(isArray(o.validation[key]) ? 'one of ' : '') + | ||
o.validation[key] | ||
}; | ||
@@ -49,3 +51,3 @@ | ||
message: 'Missing required property: ' + | ||
properties[properties.length - 1], | ||
properties[properties.length - 1] | ||
}; | ||
@@ -58,3 +60,3 @@ | ||
message: 'Value ' + o.data + ' is less than minimum ' + | ||
o.schema.minimum, | ||
o.schema.minimum | ||
}; | ||
@@ -67,3 +69,3 @@ | ||
message: 'Value ' + o.data + ' is greater than maximum ' + | ||
o.schema.maximum, | ||
o.schema.maximum | ||
}; | ||
@@ -76,3 +78,3 @@ | ||
message: 'Value ' + o.data + ' is not a multiple of ' + | ||
o.schema.multipleOf, | ||
o.schema.multipleOf | ||
}; | ||
@@ -84,3 +86,3 @@ | ||
code: 'PATTERN', | ||
message: 'String does not match pattern: ' + o.schema.pattern, | ||
message: 'String does not match pattern: ' + o.schema.pattern | ||
}; | ||
@@ -93,3 +95,3 @@ | ||
message: 'String is too short (' + o.data.length + ' chars), ' + | ||
'minimum ' + o.schema.minLength, | ||
'minimum ' + o.schema.minLength | ||
}; | ||
@@ -102,3 +104,3 @@ | ||
message: 'String is too long (' + o.data.length + ' chars), ' + | ||
'maximum ' + o.schema.maxLength, | ||
'maximum ' + o.schema.maxLength | ||
}; | ||
@@ -111,3 +113,3 @@ | ||
message: 'Array is too short (' + o.data.length + '), ' + | ||
'minimum ' + o.schema.minItems, | ||
'minimum ' + o.schema.minItems | ||
}; | ||
@@ -120,3 +122,3 @@ | ||
message: 'Array is too long (' + o.data.length + '), maximum ' + | ||
o.schema.maxItems, | ||
o.schema.maxItems | ||
}; | ||
@@ -128,3 +130,3 @@ | ||
code: 'ARRAY_UNIQUE', | ||
message: 'Array items are not unique', | ||
message: 'Array items are not unique' | ||
}; | ||
@@ -138,3 +140,3 @@ | ||
Object.keys(o.data).length + '), minimum ' + | ||
o.schema.minProperties, | ||
o.schema.minProperties | ||
}; | ||
@@ -148,3 +150,3 @@ | ||
Object.keys(o.data).length + '), maximum ' + | ||
o.schema.maxProperties, | ||
o.schema.maxProperties | ||
}; | ||
@@ -157,3 +159,3 @@ | ||
message: 'No enum match (' + o.data + '), expects: ' + | ||
o.schema.enum.join(', '), | ||
o.schema['enum'].join(', ') | ||
}; | ||
@@ -165,3 +167,3 @@ | ||
code: 'NOT_PASSED', | ||
message: 'Data matches schema from "not"', | ||
message: 'Data matches schema from "not"' | ||
}; | ||
@@ -176,3 +178,3 @@ | ||
message: 'Additional properties not allowed: ' + | ||
properties[properties.length - 1], | ||
properties[properties.length - 1] | ||
}; | ||
@@ -190,3 +192,3 @@ | ||
code: 'FAILED', | ||
message: 'Validation error: ' + key, | ||
message: 'Validation error: ' + key | ||
}; | ||
@@ -227,30 +229,27 @@ | ||
if (o.schema && o.schema.type) { | ||
switch (o.schema.type) { | ||
case 'object': | ||
if (o.schema.properties && o.schema.properties[key]) { | ||
s = o.schema.properties[key]; | ||
} | ||
if (allowsType(o.schema, 'object')) { | ||
if (o.schema.properties && o.schema.properties[key]) { | ||
s = o.schema.properties[key]; | ||
} | ||
if (!s && o.schema.patternProperties) { | ||
Object.keys(o.schema.patternProperties).some(function(pkey) { | ||
if (key.match(new RegExp(pkey))) { | ||
s = o.schema.patternProperties[pkey]; | ||
return true; | ||
} | ||
}); | ||
} | ||
if (!s && o.schema.patternProperties) { | ||
Object.keys(o.schema.patternProperties).some(function(pkey) { | ||
if (key.match(new RegExp(pkey))) { | ||
s = o.schema.patternProperties[pkey]; | ||
return true; | ||
} | ||
}); | ||
} | ||
if (!s && o.schema.hasOwnProperty('additionalProperties')) { | ||
if (typeof o.schema.additionalProperties === 'boolean') { | ||
s = {}; | ||
} else { | ||
s = o.schema.additionalProperties; | ||
} | ||
if (!s && o.schema.hasOwnProperty('additionalProperties')) { | ||
if (typeof o.schema.additionalProperties === 'boolean') { | ||
s = {}; | ||
} else { | ||
s = o.schema.additionalProperties; | ||
} | ||
} | ||
} | ||
break; | ||
case 'array': | ||
s = o.schema.items; | ||
break; | ||
if (allowsType(o.schema, 'array')) { | ||
s = o.schema.items; | ||
} | ||
@@ -265,3 +264,3 @@ } | ||
ns: o.ns + (isArray ? '[' + key + ']' : (o.sep + key)), | ||
sep: o.sep, | ||
sep: o.sep | ||
}; | ||
@@ -296,2 +295,19 @@ | ||
function allowsType(schema, type) { | ||
if (typeof schema.type === 'string') { | ||
return schema.type === type; | ||
} | ||
if (isArray(schema.type)) { | ||
return schema.type.indexOf(type) !== -1; | ||
} | ||
return false; | ||
} | ||
function isArray(obj) { | ||
if (typeof Array.isArray === 'function') { | ||
return Array.isArray(obj); | ||
} | ||
return Object.prototype.toString.call(obj) === '[object Array]'; | ||
} | ||
function jjve(env) { | ||
@@ -314,3 +330,3 @@ return function jjve(schema, data, result, options) { | ||
ns: options.root, | ||
definitions: schema.definitions || {}, | ||
definitions: schema.definitions || {} | ||
}); | ||
@@ -317,0 +333,0 @@ }; |
{ | ||
"name": "jjve", | ||
"version": "0.2.1", | ||
"version": "0.3.0", | ||
"description": "Render JJV errors", | ||
@@ -11,3 +11,3 @@ "main": "jjve.js", | ||
"mocha": "^1.19.0", | ||
"should": "^3.3.1" | ||
"should": "^4.0.4" | ||
}, | ||
@@ -14,0 +14,0 @@ "scripts": { |
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
13280
274