ajv
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -35,2 +35,3 @@ 'use strict'; | ||
validate.schema = schema; | ||
validate.errors = []; | ||
@@ -44,5 +45,6 @@ return validate; | ||
function validateRef(ref, data) { | ||
return ref == '#' | ||
? validate(data) | ||
: self._schemas[ref](data); | ||
var v = ref == '#' ? validate : self._schemas[ref]; | ||
var valid = v(data); | ||
return { valid: valid, errors: v.errors }; | ||
} | ||
@@ -49,0 +51,0 @@ } |
@@ -5,5 +5,8 @@ function (data, dataType, dataPath) { | ||
{{? it.resolveRef(it.schema) }} | ||
return validateRef('{{= it.schema }}', data, dataType, dataPath); | ||
var result = validateRef('{{= it.schema }}', data, dataType, dataPath); | ||
if (!result.valid) validate.errors.push.apply(validate.errors, result.errors); | ||
return result.valid; | ||
{{??}} | ||
return { valid: false, errors: [{ | ||
validate.errors.push({ | ||
keyword: '$ref', | ||
@@ -14,4 +17,5 @@ schema: '{{= it.schema }}', | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] }; | ||
}); | ||
return false; | ||
{{?}} | ||
} |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
var errors = []; | ||
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}} | ||
@@ -13,18 +13,9 @@ {{~ it.schema:$schema:$i }} | ||
var result = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
({{= it.validate($it) }})(data, dataType, dataPath); | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return result; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
{{~}} | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
} |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
var errors = []; | ||
var errs = validate.errors.length; | ||
@@ -13,12 +13,11 @@ {{~ it.schema:$schema:$i }} | ||
var result = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
var valid = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
if (result.valid) { | ||
return { valid: true, errors: [] }; | ||
} else { | ||
errors.push.apply(errors, result.errors); | ||
if (valid) { | ||
validate.errors.length = errs; | ||
return true; | ||
} | ||
{{~}} | ||
return { valid: false, errors: errors }; | ||
return false; | ||
} |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
var errors = []; | ||
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}} | ||
@@ -22,3 +22,3 @@ {{ | ||
if (!valid) { | ||
var error = { | ||
validate.errors.push({ | ||
keyword: 'dependencies', | ||
@@ -29,9 +29,5 @@ schema: validate.schema{{= it.schemaPath }}, | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}; | ||
}); | ||
{{? it.opts.allErrors }} | ||
errors.push(error); | ||
{{??}} | ||
return { valid: false, errors: [error] }; | ||
{{?}} | ||
{{? !it.opts.allErrors }} return false; {{?}} | ||
} | ||
@@ -50,19 +46,10 @@ } | ||
var result = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
({{= it.validate($it) }})(data, dataType, dataPath); | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return { valid: false, errors: result.errors }; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
} | ||
{{ } }} | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
} |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
/* TODO change to inline */ | ||
var errors = []; | ||
{{ | ||
@@ -16,12 +15,11 @@ var $itemsHash = {}; | ||
return { | ||
valid: valid || false, | ||
errors: valid ? [] : [{ | ||
keyword: 'enum', | ||
schema: validate.schema{{= it.schemaPath }}, | ||
dataPath: dataPath, | ||
message: 'should be equal to one of values' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'enum', | ||
schema: validate.schema{{= it.schemaPath }}, | ||
dataPath: dataPath, | ||
message: 'should be equal to one of values' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); | ||
return valid || false; | ||
} |
@@ -7,14 +7,11 @@ {{? it.opts.format !== false }} | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'format', | ||
schema: '{{= it.schema.format }}', | ||
dataPath: dataPath, | ||
message: 'should match format "{{= it.schema.format }}"' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'format', | ||
schema: '{{= it.schema.format }}', | ||
dataPath: dataPath, | ||
message: 'should match format "{{= it.schema.format }}"' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); | ||
{{??}} | ||
var result = { valid: true, errors: [] }; | ||
var valid = true; | ||
{{?}} |
@@ -5,12 +5,8 @@ {{## def.validateItems:startFrom: | ||
, _dataType = getDataType(_data) | ||
, _dataPath = dataPath + '[' + i + ']' | ||
, result = validateItems(_data, _dataType, _dataPath); | ||
, _dataPath = dataPath + '[' + i + ']'; | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return result; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
validateItems(_data, _dataType, _dataPath); | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
} | ||
@@ -22,3 +18,3 @@ #}} | ||
var errors = []; | ||
{{? it.opts.allErrors }} var errs = validate.errors.length; {{?}} | ||
@@ -29,3 +25,3 @@ {{? Array.isArray(it.schema) }} | ||
if (data.length > {{= it.schema.length }}) { | ||
errors.push({ | ||
validate.errors.push({ | ||
keyword: 'additionalItems', | ||
@@ -38,5 +34,3 @@ schema: false, | ||
{{? !it.opts.allErrors }} | ||
return { valid: false, errors: errors }; | ||
{{?}} | ||
{{? !it.opts.allErrors }} return false {{?}} | ||
} | ||
@@ -56,12 +50,8 @@ {{?}} | ||
, _dataType = getDataType(_data) | ||
, _dataPath = dataPath + '[{{= $index }}]' | ||
, result = ({{= it.validate($it) }})(_data, _dataType, _dataPath); | ||
, _dataPath = dataPath + '[{{= $index }}]'; | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return result; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
({{= it.validate($it) }})(_data, _dataType, _dataPath); | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
} | ||
@@ -88,7 +78,3 @@ {{?}} | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
} |
@@ -7,11 +7,9 @@ {{ | ||
var valid = data {{= $op }} {{= it.schema.maximum }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'maximum', | ||
schema: {{= it.schema.maximum }}, | ||
dataPath: dataPath, | ||
message: 'should be {{= $op }} {{= it.schema.maximum }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'maximum', | ||
schema: {{= it.schema.maximum }}, | ||
dataPath: dataPath, | ||
message: 'should be {{= $op }} {{= it.schema.maximum }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var valid = data.length <= {{= it.schema.maxItems }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'maxItems', | ||
schema: {{= it.schema.maxItems }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have more than {{= it.schema.maxItems }} items' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'maxItems', | ||
schema: {{= it.schema.maxItems }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have more than {{= it.schema.maxItems }} items' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var valid = data.length <= {{= it.schema.maxLength }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'maxLength', | ||
schema: {{= it.schema.maxLength }}, | ||
dataPath: dataPath, | ||
message: 'should NOT be longer than {{= it.schema.maxLength }} characters' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'maxLength', | ||
schema: {{= it.schema.maxLength }}, | ||
dataPath: dataPath, | ||
message: 'should NOT be longer than {{= it.schema.maxLength }} characters' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var propertiesNum = Object.keys(data).length; | ||
var valid = propertiesNum <= {{= it.schema.maxProperties }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'maxProperties', | ||
schema: {{= it.schema.maxProperties }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have more than {{= it.schema.maxProperties }} properties' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'maxProperties', | ||
schema: {{= it.schema.maxProperties }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have more than {{= it.schema.maxProperties }} properties' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
{{ | ||
var $schema = it.schema.minimum | ||
, $exclusive = it.schema.exclusiveMinimum === true | ||
var $exclusive = it.schema.exclusiveMinimum === true | ||
, $op = $exclusive ? '>' : '>='; | ||
}} | ||
var valid = data {{= $op }} {{= $schema }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'minimum', | ||
schema: {{= $schema }}, | ||
dataPath: dataPath, | ||
message: 'should be {{= $op }} {{= $schema }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
var valid = data {{= $op }} {{= it.schema.minimum }}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'minimum', | ||
schema: {{= it.schema.minimum }}, | ||
dataPath: dataPath, | ||
message: 'should be {{= $op }} {{= it.schema.minimum }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var valid = data.length >= {{= it.schema.minItems }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'minItems', | ||
schema: {{= it.schema.minItems }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have less than {{= it.schema.minItems }} items' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'minItems', | ||
schema: {{= it.schema.minItems }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have less than {{= it.schema.minItems }} items' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var valid = data.length >= {{= it.schema.minLength }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'minLength', | ||
schema: {{= it.schema.minLength }}, | ||
dataPath: dataPath, | ||
message: 'should NOT be shorter than {{= it.schema.minLength }} characters' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'minLength', | ||
schema: {{= it.schema.minLength }}, | ||
dataPath: dataPath, | ||
message: 'should NOT be shorter than {{= it.schema.minLength }} characters' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var propertiesNum = Object.keys(data).length; | ||
var valid = propertiesNum >= {{= it.schema.minProperties }}; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'minProperties', | ||
schema: {{= it.schema.minProperties }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have less than {{= it.schema.minProperties }} properties' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'minProperties', | ||
schema: {{= it.schema.minProperties }}, | ||
dataPath: dataPath, | ||
message: 'should NOT have less than {{= it.schema.minProperties }} properties' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
var division = data / {{= it.schema.multipleOf }}; | ||
var valid = division === parseInt(division); | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'multipleOf', | ||
schema: {{= it.schema.multipleOf }}, | ||
dataPath: dataPath, | ||
message: 'should be multiple of {{= it.schema.multipleOf }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'multipleOf', | ||
schema: {{= it.schema.multipleOf }}, | ||
dataPath: dataPath, | ||
message: 'should be multiple of {{= it.schema.multipleOf }}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
/* TODO change to inline ??? */ | ||
var result = ({{= it.validate(it) }})(data, dataType, dataPath); | ||
result.valid = !result.valid; | ||
result.errors = result.valid ? [] : [{ | ||
var errs = validate.errors.length; | ||
var valid = ({{= it.validate(it) }})(data, dataType, dataPath); | ||
valid = !valid; | ||
if (valid) validate.errors.length = errs; | ||
else validate.errors.push({ | ||
keyword: 'not', | ||
@@ -12,4 +17,5 @@ schema: validate.schema{{= it.schemaPath }}, | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}]; | ||
return result; | ||
}); | ||
return valid; | ||
} |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
var errors = [], foundValid = false; | ||
var foundValid = false | ||
, errs = validate.errors.length; | ||
@@ -13,19 +14,21 @@ {{~ it.schema:$schema:$i }} | ||
var result = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
var valid = ({{= it.validate($it) }})(data, dataType, dataPath); | ||
if (result.valid) { | ||
if (foundValid) return { valid: false, errors: [{ | ||
keyword: 'oneOf', | ||
schema: validate.schema{{= it.schemaPath }}, | ||
dataPath: dataPath, | ||
message: 'should match exactly one schema in oneOf' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] }; | ||
if (valid) { | ||
if (foundValid) { | ||
validate.errors.push({ | ||
keyword: 'oneOf', | ||
schema: validate.schema{{= it.schemaPath }}, | ||
dataPath: dataPath, | ||
message: 'should match exactly one schema in oneOf' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); | ||
return false; | ||
} | ||
foundValid = true; | ||
} else | ||
errors.push.apply(errors, result.errors); | ||
} | ||
{{~}} | ||
if (foundValid) errors = []; | ||
else errors.push({ | ||
if (foundValid) validate.errors.length = errs; | ||
else validate.errors.push({ | ||
keyword: 'oneOf', | ||
@@ -38,3 +41,3 @@ schema: validate.schema{{= it.schemaPath }}, | ||
return { valid: foundValid, errors: errors }; | ||
return foundValid; | ||
} |
{{ new RegExp(it.schema.pattern); /* test if regexp is valid to fail at compile time rather than in eval */}} | ||
var valid = /{{= it.schema.pattern }}/.test(data); | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'minimum', | ||
schema: '{{= it.schema.pattern }}', | ||
dataPath: dataPath, | ||
message: 'should match pattern "{{= it.schema.pattern }}"' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'minimum', | ||
schema: '{{= it.schema.pattern }}', | ||
dataPath: dataPath, | ||
message: 'should match pattern "{{= it.schema.pattern }}"' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
{{## def.validateProperty:useKey: | ||
var _data = data[{{= useKey }}] | ||
, _dataType = getDataType(_data) | ||
, _dataPath = dataPath + '.' + {{= useKey }} | ||
, result = ({{= it.validate($it) }})(_data, _dataType, _dataPath); | ||
, _dataPath = dataPath + '.' + {{= useKey }}; | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return result; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
({{= it.validate($it) }})(_data, _dataType, _dataPath); | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
#}} | ||
@@ -19,3 +15,3 @@ | ||
var errors = []; | ||
var errs = validate.errors.length; | ||
@@ -47,3 +43,3 @@ {{ | ||
if (notValid) { | ||
var error = { | ||
validate.errors.push({ | ||
keyword: 'properties', | ||
@@ -54,9 +50,5 @@ schema: propertiesSchema, | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}; | ||
}); | ||
{{? it.opts.allErrors }} | ||
errors.push(error); | ||
{{??}} | ||
return { valid: false, errors: [error] }; | ||
{{?}} | ||
{{? !it.opts.allErrors }} return false; {{?}} | ||
} | ||
@@ -96,3 +88,3 @@ {{?}} | ||
{{? $noAdditional }} | ||
var error = { | ||
validate.errors.push({ | ||
keyword: 'properties', | ||
@@ -103,9 +95,5 @@ schema: propertiesSchema, | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}; | ||
}); | ||
{{? it.opts.allErrors }} | ||
errors.push(error); | ||
{{??}} | ||
return { valid: false, errors: [error] }; | ||
{{?}} | ||
{{? !it.opts.allErrors }} return false; {{?}} | ||
{{??}} | ||
@@ -168,7 +156,3 @@ {{ | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
} |
@@ -23,11 +23,8 @@ var valid = true, missing = ''; | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'required', | ||
schema: req_schema, | ||
dataPath: dataPath, | ||
message: 'properties ' + missing + ' are missing' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'required', | ||
schema: req_schema, | ||
dataPath: dataPath, | ||
message: 'properties ' + missing + ' are missing' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
@@ -45,11 +45,9 @@ {{## def.isInteger: | ||
var result = { | ||
valid: valid, | ||
errors: valid ? [] : [{ | ||
keyword: 'type', | ||
schema: {{? $isArray }}validate.schema{{= it.schemaPath + '.type' }}{{??}}'{{= $schema }}'{{?}}, | ||
dataPath: dataPath, | ||
message: 'data' + dataPath + ' is not valid. Expected {{? $isArray }}{{= $schema.join(",") }}{{??}}{{= $schema }}{{?}}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}] | ||
}; | ||
if (!valid) validate.errors.push({ | ||
keyword: 'type', | ||
schema: {{? $isArray }}validate.schema{{= it.schemaPath + '.type' }}{{??}}'{{= $schema }}'{{?}}, | ||
dataPath: dataPath, | ||
message: 'data' + dataPath + ' is not valid. Expected {{? $isArray }}{{= $schema.join(",") }}{{??}}{{= $schema }}{{?}}' | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}); |
function (data, dataType, dataPath) { | ||
'use strict'; | ||
/* TODO change to inline ??? with break in the loop */ | ||
var errs = validate.errors.length; | ||
{{? it.schema && it.opts.uniqueItems !== false }} | ||
if (data.length <= 1) return { valid: true, errors: [] }; | ||
if (data.length <= 1) return true; | ||
var itemsHash = {}, errors = []; | ||
@@ -12,3 +16,3 @@ | ||
if (isDuplicate) { | ||
var error = { | ||
validate.errors.push({ | ||
keyword: 'uniqueItems', | ||
@@ -19,9 +23,5 @@ schema: {{= it.schema }}, | ||
{{? it.opts.verbose }}, data: data{{?}} | ||
}; | ||
}); | ||
{{? it.opts.allErrors }} | ||
errors.push(error); | ||
{{??}} | ||
return { valid: false, errors: [error] }; | ||
{{?}} | ||
{{? !it.opts.allErrors }} return false; {{?}} | ||
} else { | ||
@@ -32,10 +32,6 @@ itemsHash[itemStr] = true; | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
return true; | ||
{{?}} | ||
} |
@@ -26,8 +26,9 @@ {{ /** | ||
dataType = dataType || getDataType(data); | ||
dataPath = dataPath || ''; | ||
if (!dataType) { | ||
dataType = getDataType(data); | ||
validate.errors.length = 0; | ||
dataPath = ''; | ||
} | ||
{{? it.opts.allErrors }} | ||
var errors = []; | ||
{{?}} | ||
var errs = validate.errors.length; | ||
@@ -63,12 +64,7 @@ {{ | ||
}} | ||
var result = ({{= $rule.code($it) }})(data, dataType, dataPath); | ||
{{? !it.opts.allErrors }} var valid = {{?}} | ||
({{= $rule.code($it) }})(data, dataType, dataPath); | ||
{{?}} | ||
if (!result.valid) { | ||
{{? it.opts.allErrors }} | ||
errors.push.apply(errors, result.errors); | ||
{{??}} | ||
return result; | ||
{{?}} | ||
} | ||
{{? !it.opts.allErrors }} if (!valid) return false; {{?}} | ||
} | ||
@@ -78,7 +74,3 @@ {{?}} | ||
{{? it.opts.allErrors }} | ||
return { valid: !errors.length, errors: errors }; | ||
{{??}} | ||
return { valid: true, errors: [] }; | ||
{{?}} | ||
return {{? it.opts.allErrors }} errs == validate.errors.length {{??}} true {{?}}; | ||
} |
{ | ||
"name": "ajv", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"description": "Another JSON schema Validator", | ||
@@ -5,0 +5,0 @@ "main": "lib/ajv.js", |
@@ -23,3 +23,4 @@ # ajv - Another JSON schema Validator | ||
var validate = ajv.compile(schema); | ||
var result = validate(data); | ||
var valid = validate(data); | ||
if (!valid) console.log(validate.errors); | ||
``` | ||
@@ -30,3 +31,5 @@ | ||
``` | ||
var result = ajv.validate(schema, data); | ||
// ... | ||
var valid = ajv.validate(schema, data); | ||
// ... | ||
``` | ||
@@ -33,0 +36,0 @@ |
@@ -10,11 +10,14 @@ 'use strict'; | ||
// ONLY_RULES = [ | ||
// 'type', 'not', 'allOf', 'anyOf', 'oneOf', 'enum', | ||
// 'maximum', 'minimum', 'multipleOf', | ||
// 'maxLength', 'minLength', 'pattern', | ||
// 'properties', 'patternProperties', 'additionalProperties', | ||
// 'dependencies', | ||
// 'required', 'maxProperties', 'minProperties', | ||
// 'maxItems', 'minItems', 'items', 'additionalItems', 'uniqueItems', | ||
// 'optional/format', | ||
// 'optional/bignum', | ||
// // 'type', | ||
// // 'not', | ||
// // 'allOf', 'anyOf', 'oneOf', 'enum', | ||
// // 'maximum', 'minimum', 'multipleOf', | ||
// // 'maxLength', 'minLength', 'pattern', | ||
// // 'properties', 'patternProperties', 'additionalProperties', | ||
// // 'dependencies', | ||
// // 'required', | ||
// // 'maxProperties', 'minProperties', 'maxItems', 'minItems', | ||
// // 'items', 'additionalItems', | ||
// // 'uniqueItems', | ||
// // 'optional/format', 'optional/bignum', | ||
// 'ref' | ||
@@ -24,3 +27,3 @@ // ]; | ||
SKIP_RULES = [ | ||
'refRemote', | ||
// 'refRemote', | ||
'optional/zeroTerminatedFloats' | ||
@@ -57,3 +60,3 @@ ]; | ||
testSets.forEach(function (testSet) { | ||
// if (testSet.description != 'relative pointer ref to object') return; | ||
// if (testSet.description != 'not') return; | ||
describe(testSet.description, function() { | ||
@@ -65,15 +68,15 @@ // it(testSet.description, function() { | ||
testSet.tests.forEach(function (test) { | ||
// if (test.description != 'match') return; | ||
// if (test.description != 'allowed') return; | ||
it(test.description, function() { | ||
var result = validate(test.data); | ||
var valid = validate(test.data); | ||
// console.log('result', result); | ||
assert.equal(result.valid, test.valid); | ||
if (result.valid) assert(result.errors.length == 0); | ||
else assert(result.errors.length > 0); | ||
assert.equal(valid, test.valid); | ||
if (valid) assert(validate.errors.length == 0); | ||
else assert(validate.errors.length > 0); | ||
var result = fullValidate(test.data); | ||
var valid = fullValidate(test.data); | ||
// console.log('full result', result); | ||
assert.equal(result.valid, test.valid); | ||
if (result.valid) assert(result.errors.length == 0); | ||
else assert(result.errors.length > 0); | ||
assert.equal(valid, test.valid); | ||
if (valid) assert(validate.errors.length == 0); | ||
else assert(validate.errors.length > 0); | ||
}); | ||
@@ -80,0 +83,0 @@ }); |
44
190319
5871