Comparing version 0.3.8 to 0.3.11
@@ -17,3 +17,6 @@ 'use strict'; | ||
var refVal = this._refs[ref]; | ||
if (typeof refVal == 'string') refVal = this._refs[refVal]; | ||
if (typeof refVal == 'string') { | ||
if (this._refs[refVal]) refVal = this._refs[refVal]; | ||
else return resolve.call(this, compile, rootSchema, refVal); | ||
} | ||
if (typeof refVal == 'function') return refVal; | ||
@@ -35,2 +38,6 @@ var refVal = this._schemas[ref]; | ||
if (typeof refVal == 'string') refVal = this._refs[refVal]; | ||
// { | ||
// if (this._refs[refVal]) refVal = this._refs[refVal]; | ||
// else refVal = resolve.call(this, rootSchema, refVal); | ||
// } | ||
if (typeof refVal == 'function') rootSchema = refVal.schema; | ||
@@ -37,0 +44,0 @@ else { |
@@ -6,3 +6,3 @@ {{# def.definitions }} | ||
{{? $breakOnError }} if ( {{?}} | ||
validate({{=$data}}, (dataPath || '') + {{= it.errorPath }}) | ||
validate({{=$data}}, (dataPath || '') + {{= it.errorPath }}, true) | ||
{{? $breakOnError }} ) { {{??}};{{?}} | ||
@@ -9,0 +9,0 @@ {{??}} |
@@ -6,12 +6,14 @@ {{# def.definitions }} | ||
{{~ $schema:$sch:$i }} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{? {{# def.nonEmptySchema:$sch }} }} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{= it.validate($it) }} | ||
{{= it.validate($it) }} | ||
{{? $breakOnError }} | ||
if (valid{{=$it.level}}) { | ||
{{ $closingBraces += '}'; }} | ||
{{? $breakOnError }} | ||
if (valid{{=$it.level}}) { | ||
{{ $closingBraces += '}'; }} | ||
{{?}} | ||
{{?}} | ||
@@ -18,0 +20,0 @@ {{~}} |
@@ -5,25 +5,36 @@ {{# def.definitions }} | ||
var {{=$errs}} = validate.errors.length; | ||
var {{=$valid}} = false; | ||
{{ | ||
var $noEmptySchema = $schema.every(function($sch) { | ||
return {{# def.nonEmptySchema:$sch }}; | ||
}); | ||
}} | ||
{{? $noEmptySchema }} | ||
var {{=$errs}} = validate.errors.length; | ||
var {{=$valid}} = false; | ||
{{~ $schema:$sch:$i }} | ||
{{? $i }} | ||
{{ $closingBraces += '}'; }} | ||
if (!{{=$valid}}) { | ||
{{?}} | ||
{{~ $schema:$sch:$i }} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{= it.validate($it) }} | ||
{{= it.validate($it) }} | ||
{{=$valid}} = {{=$valid}} || valid{{=$it.level}}; | ||
{{=$valid}} = {{=$valid}} || valid{{=$it.level}}; | ||
{{~}} | ||
if (!{{=$valid}}) { | ||
{{ $closingBraces += '}'; }} | ||
{{~}} | ||
{{= $closingBraces }} | ||
{{= $closingBraces }} | ||
if ({{=$valid}}) { | ||
validate.errors.length = {{=$errs}}; | ||
{{? it.opts.allErrors }} } {{?}} | ||
if ({{=$valid}}) { | ||
validate.errors.length = {{=$errs}}; | ||
{{? it.opts.allErrors }} } {{?}} | ||
{{# def.cleanUp }} | ||
{{??}} | ||
{{? $breakOnError }} | ||
if (true) { | ||
{{?}} | ||
{{?}} |
@@ -1,7 +0,7 @@ | ||
{{## def.setup:keyword: | ||
{{## def.setup:_keyword: | ||
{{ | ||
var $lvl = it.level | ||
, $dataLvl = it.dataLevel | ||
, $schema = it.schema[keyword] | ||
, $schemaPath = it.schemaPath + '.' + keyword | ||
, $schema = it.schema[_keyword] | ||
, $schemaPath = it.schemaPath + '.' + _keyword | ||
, $breakOnError = !it.opts.allErrors; | ||
@@ -14,2 +14,5 @@ | ||
}} | ||
{{? it.opts._debug }} | ||
console.log('Keyword {{= _keyword }}'); | ||
{{?}} | ||
#}} | ||
@@ -51,2 +54,7 @@ | ||
{{## def.nonEmptySchema:_schema: | ||
it.util.nonEmptySchema(_schema, it.RULES.hash) | ||
#}} | ||
{{## def.strLength: | ||
@@ -61,13 +69,33 @@ {{? it.opts.unicode === false }} | ||
{{## def.willOptimize: | ||
it.util.varOccurences($code, $nextData) < 2 | ||
#}} | ||
{{## def._optimizeValidate: | ||
{{= it.util.varReplace($code, $nextData, $passData) }} | ||
#}} | ||
{{## def.optimizeValidate: | ||
{{? {{# def.willOptimize}} }} | ||
{{# def._optimizeValidate }} | ||
{{??}} | ||
var {{=$nextData}} = {{=$passData}}; | ||
{{= $code }} | ||
{{?}} | ||
#}} | ||
{{## def.cleanUp: | ||
{{ out = out.replace(/if\s*\(valid[0-9]*\)\s*\{\s*\}/g, ''); }} | ||
{{ out = out.replace(/if\s*\([^)]+\)\s*\{\s*\}/g, ''); }} | ||
#}} | ||
{{## def.error:rule: | ||
{{## def.error:_rule: | ||
validate.errors.push({ | ||
keyword: '{{=rule}}', | ||
keyword: '{{=_rule}}', | ||
dataPath: {{= it.errorPath }}, | ||
message: {{# def._errorMessages[rule] }} | ||
{{? it.opts.verbose }}, schema: {{# def._errorSchemas[rule] }}, data: {{=$data}}{{?}} | ||
message: {{# def._errorMessages[_rule] }} | ||
{{? it.opts.verbose }}, schema: {{# def._errorSchemas[_rule] }}, data: {{=$data}}{{?}} | ||
}); | ||
@@ -77,4 +105,4 @@ #}} | ||
{{## def.checkError:rule: | ||
if (!{{=$valid}}) {{# def.error:rule }} | ||
{{## def.checkError:_rule: | ||
if (!{{=$valid}}) {{# def.error:_rule }} | ||
#}} | ||
@@ -81,0 +109,0 @@ |
@@ -22,3 +22,3 @@ {{# def.definitions }} | ||
{{?$i}} && {{?}} | ||
{{=$data}}['{{= $dep}}'] !== undefined | ||
{{=$data}}{{= it.util.getProperty($dep) }} !== undefined | ||
{{~}}) | ||
@@ -28,3 +28,3 @@ #}} | ||
{{ for ($property in $propertyDeps) { }} | ||
if ({{=$data}}['{{= $property }}'] !== undefined) { | ||
if ({{=$data}}{{= it.util.getProperty($property) }} !== undefined) { | ||
{{ $deps = $propertyDeps[$property]; }} | ||
@@ -40,3 +40,3 @@ if (! {{# def.checkPropertyDeps }} ) | ||
{{ var $sch = $schemaDeps[$property]; }} | ||
{{? Object.keys($sch).length }} | ||
{{? {{# def.nonEmptySchema:$sch }} }} | ||
valid{{=$it.level}} = true; | ||
@@ -43,0 +43,0 @@ |
@@ -20,5 +20,7 @@ 'use strict'; | ||
RULES.hash = { type: true }; | ||
RULES.forEach(function (group) { | ||
group.rules = group.rules.map(function (keyword) { | ||
RULES.hash[keyword] = true; | ||
var template = fs.readFileSync(__dirname + '/' + keyword + '.dot.js'); | ||
@@ -34,1 +36,2 @@ return { | ||
RULES.defs = defs; | ||
@@ -8,7 +8,10 @@ {{# def.definitions }} | ||
for (var i{{=$lvl}} = {{=startFrom}}; i{{=$lvl}} < {{=$data}}.length; i{{=$lvl}}++) { | ||
var data{{=$dataNxt}} = {{=$data}}[i{{=$lvl}}]; | ||
{{ | ||
$it.errorPath = (it.errorPath + ' + "[" + i' + $lvl + ' + "]"').replace('" + "', ''); | ||
$it.dataPath = it.dataPath + '[i' + $lvl + ']'; | ||
var $passData = $data + '[i' + $lvl + ']'; | ||
}} | ||
{{ $it.errorPath = (it.errorPath + ' + "[" + i' + $lvl + ' + "]"').replace('" + "', ''); }} | ||
{{ $it.dataPath = it.dataPath + '[i' + $lvl + ']'; }} | ||
{{= it.validate($it) }}; | ||
{{ var $code = it.validate($it); }} | ||
{{# def.optimizeValidate }} | ||
@@ -21,3 +24,6 @@ {{? $breakOnError }} | ||
{{ var $dataNxt = $it.dataLevel = it.dataLevel + 1; }} | ||
{{ | ||
var $dataNxt = $it.dataLevel = it.dataLevel + 1 | ||
, $nextData = 'data' + $dataNxt; | ||
}} | ||
@@ -37,3 +43,3 @@ var {{=$errs}} = validate.errors.length; | ||
{{~ $schema:$sch:$i }} | ||
{{? Object.keys($sch).length }} | ||
{{? {{# def.nonEmptySchema:$sch }} }} | ||
valid{{=$it.level}} = true; | ||
@@ -45,9 +51,9 @@ | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
$it.errorPath = (it.errorPath + ' + "[' + $i + ']"').replace('" + "', ''); | ||
$it.dataPath = it.dataPath + '[' + $i + ']'; | ||
var $passData = $data + '[' + $i + ']'; | ||
}} | ||
var data{{=$dataNxt}} = {{=$data}}[{{= $i }}]; | ||
{{ $it.errorPath = (it.errorPath + ' + "[' + $i + ']"').replace('" + "', ''); }} | ||
{{ $it.dataPath = it.dataPath + '[' + $i + ']'; }} | ||
{{= it.validate($it) }} | ||
{{ var $code = it.validate($it); }} | ||
{{# def.optimizeValidate }} | ||
} | ||
@@ -59,3 +65,3 @@ | ||
{{? typeof $additionalItems == 'object' && Object.keys($additionalItems).length }} | ||
{{? typeof $additionalItems == 'object' && {{# def.nonEmptySchema:$additionalItems }} }} | ||
{{ | ||
@@ -74,3 +80,3 @@ $it.schema = $additionalItems; | ||
{{?? Object.keys($schema).length }} | ||
{{?? {{# def.nonEmptySchema:$schema }} }} | ||
{{ /* 'items' is a single schema */}} | ||
@@ -77,0 +83,0 @@ {{ |
@@ -5,16 +5,23 @@ {{# def.definitions }} | ||
{{ | ||
$it.schema = $schema; | ||
$it.schemaPath = $schemaPath; | ||
}} | ||
{{? {{# def.nonEmptySchema:$schema }} }} | ||
{{ | ||
$it.schema = $schema; | ||
$it.schemaPath = $schemaPath; | ||
}} | ||
var {{=$errs}} = validate.errors.length; | ||
var {{=$errs}} = validate.errors.length; | ||
{{= it.validate($it) }} | ||
{{= it.validate($it) }} | ||
if (valid{{=$it.level}}) | ||
if (valid{{=$it.level}}) | ||
{{# def.error:'not' }} | ||
else { | ||
validate.errors.length = {{=$errs}}; | ||
{{? it.opts.allErrors }} } {{?}} | ||
{{??}} | ||
{{# def.error:'not' }} | ||
else { | ||
validate.errors.length = {{=$errs}}; | ||
{{? it.opts.allErrors }} } {{?}} | ||
{{? $breakOnError}} | ||
if (false) { | ||
{{?}} | ||
{{?}} |
@@ -11,10 +11,13 @@ {{# def.definitions }} | ||
{{~ $schema:$sch:$i }} | ||
{{? {{# def.nonEmptySchema:$sch }} }} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + '[' + $i + ']'; | ||
}} | ||
{{= it.validate($it) }} | ||
{{??}} | ||
var valid{{=$it.level}} = true; | ||
{{?}} | ||
{{= it.validate($it) }} | ||
{{? $i }} | ||
@@ -21,0 +24,0 @@ if (valid{{=$it.level}} && prevValid{{=$lvl}}) |
@@ -7,3 +7,4 @@ {{# def.definitions }} | ||
{{ | ||
var $dataNxt = $it.dataLevel = it.dataLevel + 1; | ||
var $dataNxt = $it.dataLevel = it.dataLevel + 1 | ||
, $nextData = 'data' + $dataNxt; | ||
@@ -59,10 +60,10 @@ var $pProperties = it.schema.patternProperties || {} | ||
$it.schemaPath = it.schemaPath + '.additionalProperties'; | ||
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
$it.dataPath = it.dataPath + '[key' + $lvl + ']'; | ||
var $passData = $data + '[key' + $lvl + ']'; | ||
}} | ||
var data{{=$dataNxt}} = {{=$data}}[key{{=$lvl}}]; | ||
{{ var $code = it.validate($it); }} | ||
{{# def.optimizeValidate }} | ||
{{ $it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); }} | ||
{{ $it.dataPath = it.dataPath + '[key' + $lvl + ']'; }} | ||
{{= it.validate($it) }}; | ||
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}} | ||
@@ -80,6 +81,10 @@ {{?}} | ||
{{? Object.keys($sch).length }} | ||
{{? {{# def.nonEmptySchema:$sch}} }} | ||
{{ | ||
$it.schema = $sch; | ||
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($propertyKey) + "']"; | ||
var $prop = it.util.getProperty($propertyKey) | ||
, $passData = $data + $prop; | ||
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', ''); | ||
$it.dataPath = it.dataPath + $prop; | ||
}} | ||
@@ -89,13 +94,16 @@ | ||
{{ var $prop = it.util.getProperty($propertyKey); }} | ||
{{ var $code = it.validate($it); }} | ||
var data{{=$dataNxt}} = {{=$data}}{{=$prop}}; | ||
{{? {{# def.willOptimize }} }} | ||
if ({{=$passData}} !== undefined) { | ||
{{# def._optimizeValidate }} | ||
} | ||
{{??}} | ||
var {{=$nextData}} = {{=$passData}}; | ||
if ({{=$nextData}} !== undefined) { | ||
{{= $code }} | ||
} | ||
{{?}} | ||
{{?}} {{ /* def.nonEmptySchema */ }} | ||
if (data{{=$dataNxt}} !== undefined) { | ||
{{ $it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', ''); }} | ||
{{ $it.dataPath = it.dataPath + $prop; }} | ||
{{= it.validate($it) }}; | ||
} | ||
{{?}} | ||
{{# def.ifResultValid }} | ||
@@ -108,3 +116,3 @@ {{ } }} | ||
{{? Object.keys($sch).length }} | ||
{{? {{# def.nonEmptySchema:$sch}} }} | ||
{{ | ||
@@ -119,7 +127,11 @@ $it.schema = $sch; | ||
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}})) { | ||
var data{{=$dataNxt}} = {{=$data}}[key{{=$lvl}}]; | ||
{{ | ||
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); | ||
$it.dataPath = it.dataPath + '[key' + $lvl + ']'; | ||
var $passData = $data + '[key' + $lvl + ']'; | ||
}} | ||
{{ $it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', ''); }} | ||
{{ $it.dataPath = it.dataPath + '[key' + $lvl + ']'; }} | ||
{{= it.validate($it) }}; | ||
{{ var $code = it.validate($it); }} | ||
{{# def.optimizeValidate }} | ||
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}} | ||
@@ -130,3 +142,3 @@ } | ||
{{# def.ifResultValid }} | ||
{{?}} | ||
{{?}} {{ /* def.nonEmptySchema */ }} | ||
{{~}} | ||
@@ -133,0 +145,0 @@ |
@@ -5,11 +5,14 @@ 'use strict'; | ||
module.exports = { | ||
copy: copy, | ||
checkDataType: checkDataType, | ||
checkDataTypes: checkDataTypes, | ||
toHash: toHash, | ||
getProperty: getProperty, | ||
escapeQuotes: escapeQuotes, | ||
escapeRegExp: escapeRegExp, | ||
ucs2length: ucs2length, | ||
stableStringify: require('json-stable-stringify') | ||
copy: copy, | ||
checkDataType: checkDataType, | ||
checkDataTypes: checkDataTypes, | ||
toHash: toHash, | ||
getProperty: getProperty, | ||
escapeQuotes: escapeQuotes, | ||
escapeRegExp: escapeRegExp, | ||
ucs2length: ucs2length, | ||
varOccurences: varOccurences, | ||
varReplace: varReplace, | ||
nonEmptySchema: nonEmptySchema, | ||
stableStringify: require('json-stable-stringify') | ||
}; | ||
@@ -108,1 +111,19 @@ | ||
} | ||
function varOccurences(str, dataVar) { | ||
dataVar += '[^0-9]'; | ||
var matches = str.match(new RegExp(dataVar, 'g')); | ||
return matches ? matches.length : 0; | ||
} | ||
function varReplace(str, dataVar, expr) { | ||
dataVar += '([^0-9])'; | ||
return str.replace(new RegExp(dataVar, 'g'), expr + '$1') | ||
} | ||
function nonEmptySchema(schema, rules) { | ||
for (var key in schema) if (rules[key]) return true; | ||
} |
@@ -24,5 +24,10 @@ {{# def.definitions }} | ||
validate = function (data, dataPath) { | ||
validate.errors.length = 0; | ||
validate = function (data, dataPath, recursive) { | ||
if (!recursive) validate.errors.length = 0; | ||
var errors{{=$lvl}} = validate.errors.length; | ||
{{??}} | ||
{{? it.opts._debug }} | ||
console.log('validate dataPath:', dataPath); | ||
{{?}} | ||
{{ | ||
@@ -36,3 +41,3 @@ var $lvl = it.level | ||
var errs{{=$lvl}} = validate.errors.length; | ||
var errors{{=$lvl}} = validate.errors.length; | ||
{{?}} | ||
@@ -49,3 +54,3 @@ | ||
var {{=$valid}} = true; | ||
var {{=$valid}} = true; {{ /* TODO can't remove this line, some rules depend on it*/ }} | ||
@@ -73,6 +78,4 @@ {{~ it.RULES:$rulesGroup }} | ||
{{ var $typeChecked = true; }} | ||
else { | ||
{{=$valid}} = false; | ||
else | ||
{{# def.error:'type' }} | ||
} | ||
{{?}} | ||
@@ -82,3 +85,3 @@ {{?}} | ||
{{? $breakOnErrors }} | ||
if ({{=$valid}}) { | ||
if (errors{{=$lvl}} === validate.errors.length) { | ||
{{ $closingBraces2 += '}'; }} | ||
@@ -102,6 +105,6 @@ {{?}} | ||
{{? $root }} | ||
return validate.errors.length === 0; | ||
return errors{{=$lvl}} === validate.errors.length; | ||
} | ||
{{??}} | ||
{{=$valid}} = errs{{=$lvl}} == validate.errors.length; | ||
{{=$valid}} = errors{{=$lvl}} === validate.errors.length; | ||
{{?}} | ||
@@ -108,0 +111,0 @@ |
{ | ||
"name": "ajv", | ||
"version": "0.3.8", | ||
"version": "0.3.11", | ||
"description": "Another JSON schema Validator", | ||
@@ -5,0 +5,0 @@ "main": "lib/ajv.js", |
@@ -110,3 +110,3 @@ # ajv - Another JSON Schema Validator | ||
- _verbose_: include the reference to the part of the schema and validated data in errors (false by default). | ||
- _format_: formats validation mode ('fast' by default). Pass 'full' for more correct and slow validation or `false` not to validate formats at all. E.g., 25:00:00 and 2015/14/33 won't be valid time and date in 'full' mode but it will be in 'fast' mode. | ||
- _format_: formats validation mode ('fast' by default). Pass 'full' for more correct and slow validation or `false` not to validate formats at all. E.g., 25:00:00 and 2015/14/33 will be invalid time and date in 'full' mode but it will be valid in 'fast' mode. | ||
- _meta_: add [meta-schema](http://json-schema.org/documentation.html) so it can be used by other schemas (true by default). | ||
@@ -113,0 +113,0 @@ - _uniqueItems_: validate `uniqueItems` keyword (true by default). |
@@ -9,3 +9,5 @@ 'use strict'; | ||
// ONLY_RULES = [ | ||
// 'type', 'not', 'allOf', 'anyOf', 'oneOf', 'enum', | ||
// 'type', 'not', | ||
// 'allOf', | ||
// 'anyOf', 'oneOf', 'enum', | ||
// 'maximum', 'minimum', 'multipleOf', 'maxLength', 'minLength', 'pattern', | ||
@@ -19,8 +21,8 @@ // 'properties', 'patternProperties', 'additionalProperties', | ||
// 'refRemote', | ||
// 'definitions' | ||
// 'schemas/complex' | ||
// 'definitions', | ||
// 'schemas/complex', | ||
// 'schemas/basic' | ||
// ]; | ||
SKIP_RULES = [ | ||
// 'refRemote', | ||
'optional/zeroTerminatedFloats', | ||
@@ -30,6 +32,8 @@ 'schemas/complex' | ||
var DEBUG = false; | ||
var Ajv = require('../lib/ajv') | ||
, ajv = Ajv({ beautify: true }) | ||
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true }); | ||
, ajv = Ajv({ beautify: true, _debug: DEBUG }) | ||
, fullAjv = Ajv({ allErrors: true, verbose: true, format: 'full', beautify: true, _debug: DEBUG }); | ||
@@ -76,7 +80,7 @@ var remoteRefs = { | ||
testSet.tests.forEach(function (test) { | ||
// if (test.description != 'changed scope ref valid') return; | ||
// if (test.description != 'valid array from z-schema benchmark') return; | ||
// console.log(testSet.schema, '\n\n***\n\n', validate.toString()); | ||
it(test.description, function() { | ||
var valid = validate(test.data); | ||
// console.log('result', valid, validate.errors); | ||
// console.log('result', valid, validate.errors, ajv._refs); | ||
assert.equal(valid, test.valid); | ||
@@ -83,0 +87,0 @@ if (valid) assert(validate.errors.length == 0); |
@@ -5,2 +5,3 @@ [ | ||
"schema": { | ||
"id": "http://example.com", | ||
"type": "array", | ||
@@ -7,0 +8,0 @@ "items": { "$ref": "#transaction" }, |
Sorry, the diff of this file is not supported yet
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
243674
7269
113