unicode lengths are used by default; tidy up
parent
b9b9affcf4
commit
f47d821418
|
@ -6,7 +6,6 @@
|
|||
- custom formats (via options)
|
||||
- schema validation before compilation
|
||||
- bundle compiled templates (doT will be dev dependency)
|
||||
- unicode option
|
||||
|
||||
|
||||
## Install
|
||||
|
@ -42,4 +41,4 @@ ajv compiles schemas to functions and caches them in both cases (using stringifi
|
|||
- _verbose_: include the reference to the validated data in the errors (false by default)
|
||||
- _format_: if false, the formats won't be validated (true by default)
|
||||
- _uniqueItems_: if false, `uniqueItems` keyword will be ignored (true by default, i.e. uniqueItems is checked)
|
||||
- _unicode_: if true, the lengths of strings with unicode pairs will be correct and each pair will be counted as one character (false by default, as it is slower).
|
||||
- _unicode_: if false, sting.length will be used and the string lengths with unicode pairs will be "incorrect" because each unicode pair will be counted as two characters (true by default - string lengths are calculated correctly but it is slower)
|
||||
|
|
|
@ -2,10 +2,10 @@
|
|||
{{# def.setup:'$ref' }}
|
||||
|
||||
{{? it.resolveRef($schema) }}
|
||||
var result{{=$lvl}} = validateRef('{{=$schema}}', data{{=$dataLvl}}, dataPath{{=$dataLvl}});
|
||||
var valid{{=$lvl}} = result{{=$lvl}}.valid;
|
||||
if (!valid{{=$lvl}}) validate.errors.push.apply(validate.errors, result{{=$lvl}}.errors);
|
||||
var result{{=$lvl}} = validateRef('{{=$schema}}', {{=$data}}, dataPath{{=$dataLvl}});
|
||||
var {{=$valid}} = result{{=$lvl}}.valid;
|
||||
if (!{{=$valid}}) validate.errors.push.apply(validate.errors, result{{=$lvl}}.errors);
|
||||
{{??}}
|
||||
{{# def.error:'$ref' }}
|
||||
var valid{{=$lvl}} = false;
|
||||
var {{=$valid}} = false;
|
||||
{{?}}
|
||||
|
|
|
@ -21,4 +21,4 @@
|
|||
- [ ] properties (+ patternProperties, additionalProperties)
|
||||
- [ ] required
|
||||
- [ ] type
|
||||
- [+] uniqueItems
|
||||
- [x] uniqueItems
|
|
@ -2,7 +2,7 @@
|
|||
{{# def.setup:'allOf' }}
|
||||
{{# def.setupNextLevel }}
|
||||
|
||||
var valid{{=$lvl}} = true;
|
||||
var {{=$valid}} = true;
|
||||
|
||||
{{~ $schema:$sch:$i }}
|
||||
{{? $i}} {{# def.ifValid }} {{?}}
|
||||
|
@ -15,7 +15,7 @@ var valid{{=$lvl}} = true;
|
|||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }}
|
||||
|
||||
valid{{=$lvl}} = valid{{=$lvl}} && valid{{=$it.level}};
|
||||
{{=$valid}} = {{=$valid}} && valid{{=$it.level}};
|
||||
{{~}}
|
||||
|
||||
{{= $closingBraces }}
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
{{# def.setupNextLevel }}
|
||||
|
||||
var errs{{=$lvl}} = validate.errors.length;
|
||||
var valid{{=$lvl}} = false;
|
||||
var {{=$valid}} = false;
|
||||
|
||||
{{~ $schema:$sch:$i }}
|
||||
{{? $i }}
|
||||
{{ $closingBraces += '}'; }}
|
||||
if (!valid{{=$lvl}}) {
|
||||
if (!{{=$valid}}) {
|
||||
{{?}}
|
||||
|
||||
{{
|
||||
|
@ -19,9 +19,9 @@ var valid{{=$lvl}} = false;
|
|||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }}
|
||||
|
||||
valid{{=$lvl}} = valid{{=$lvl}} || valid{{=$it.level}};
|
||||
{{=$valid}} = {{=$valid}} || valid{{=$it.level}};
|
||||
{{~}}
|
||||
|
||||
{{= $closingBraces }}
|
||||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
if ({{=$valid}}) validate.errors.length = errs{{=$lvl}};
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
, $dataLvl = it.dataLevel
|
||||
, $schema = it.schema[keyword]
|
||||
, $schemaPath = it.schemaPath + '.' + keyword;
|
||||
|
||||
var $data = 'data' + $dataLvl
|
||||
, $valid = 'valid' + $lvl;
|
||||
}}
|
||||
#}}
|
||||
|
||||
|
@ -20,7 +23,7 @@
|
|||
|
||||
{{## def.ifValid:
|
||||
{{? $breakOnError }}
|
||||
if (valid{{=$lvl}}) {
|
||||
if ({{=$valid}}) {
|
||||
{{ $closingBraces += '}'; }}
|
||||
{{?}}
|
||||
#}}
|
||||
|
@ -35,10 +38,10 @@
|
|||
|
||||
|
||||
{{## def.strLength:
|
||||
{{? it.opts.unicode }}
|
||||
ucs2length(data{{=$dataLvl}})
|
||||
{{? it.opts.unicode === false }}
|
||||
{{=$data}}.length
|
||||
{{??}}
|
||||
data{{=$dataLvl}}.length
|
||||
ucs2length({{=$data}})
|
||||
{{?}}
|
||||
#}}
|
||||
|
||||
|
@ -53,13 +56,13 @@
|
|||
keyword: '{{=rule}}',
|
||||
dataPath: dataPath{{=$dataLvl}},
|
||||
message: {{# def._errorMessages[rule] }}
|
||||
{{? it.opts.verbose }}, schema: {{# def._errorSchemas[rule] }}, data: data{{=$dataLvl}}{{?}}
|
||||
{{? it.opts.verbose }}, schema: {{# def._errorSchemas[rule] }}, data: {{=$data}}{{?}}
|
||||
});
|
||||
#}}
|
||||
|
||||
|
||||
{{## def.checkError:rule:
|
||||
if (!valid{{=$lvl}}) {
|
||||
if (!{{=$valid}}) {
|
||||
{{# def.error:rule }}
|
||||
}
|
||||
#}}
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
}}
|
||||
|
||||
var errs{{=$lvl}} = validate.errors.length;
|
||||
var valid{{=$lvl}};
|
||||
var {{=$valid}};
|
||||
|
||||
|
||||
{{ for ($property in $propertyDeps) { }}
|
||||
if (data{{=$dataLvl}}.hasOwnProperty('{{= $property }}')) {
|
||||
if ({{=$data}}.hasOwnProperty('{{= $property }}')) {
|
||||
{{ $deps = $propertyDeps[$property]; }}
|
||||
valid{{=$lvl}} = {{~ $deps:$dep:$i }}{{?$i}} && {{?}}data{{=$dataLvl}}.hasOwnProperty('{{= $dep}}'){{~}};
|
||||
{{=$valid}} = {{~ $deps:$dep:$i }}{{?$i}} && {{?}}{{=$data}}.hasOwnProperty('{{= $dep}}'){{~}};
|
||||
{{# def.checkError:'dependencies' }}
|
||||
{{# def.elseIfValid }}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ var valid{{=$lvl}};
|
|||
{{ for ($property in $schemaDeps) { }}
|
||||
{{ var $sch = $schemaDeps[$property]; }}
|
||||
{{? Object.keys($sch).length }}
|
||||
if (data{{=$dataLvl}}.hasOwnProperty('{{= $property }}')) {
|
||||
if ({{=$data}}.hasOwnProperty('{{= $property }}')) {
|
||||
{{
|
||||
$it.schema = $sch;
|
||||
$it.schemaPath = $schemaPath + '[\'' + it.escapeQuotes($property) + '\']';
|
||||
|
@ -40,7 +40,7 @@ var valid{{=$lvl}};
|
|||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }}
|
||||
|
||||
valid{{=$lvl}} = valid{{=$it.level}};
|
||||
{{=$valid}} = valid{{=$it.level}};
|
||||
}
|
||||
|
||||
{{# def.ifValid }}
|
||||
|
@ -49,6 +49,6 @@ var valid{{=$lvl}};
|
|||
|
||||
{{? $breakOnError }}{{= $closingBraces }}{{?}}
|
||||
|
||||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
{{=$valid}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
|
|
@ -6,6 +6,6 @@
|
|||
}}
|
||||
|
||||
var itemsHash{{=$lvl}} = {{= JSON.stringify($itemsHash) }};
|
||||
var valid{{=$lvl}} = itemsHash{{=$lvl}}[stableStringify(data{{=$dataLvl}})] || false;
|
||||
var {{=$valid}} = itemsHash{{=$lvl}}[stableStringify({{=$data}})] || false;
|
||||
|
||||
{{# def.checkError:'enum' }}
|
||||
|
|
|
@ -4,11 +4,11 @@
|
|||
{{# def.setup:'format' }}
|
||||
|
||||
var format{{=$lvl}} = formats['{{=$schema}}'];
|
||||
var valid{{=$lvl}} = typeof format{{=$lvl}} == 'function'
|
||||
? format{{=$lvl}}(data{{=$dataLvl}})
|
||||
: !format{{=$lvl}} || format{{=$lvl}}.test(data{{=$dataLvl}});
|
||||
var {{=$valid}} = typeof format{{=$lvl}} == 'function'
|
||||
? format{{=$lvl}}({{=$data}})
|
||||
: !format{{=$lvl}} || format{{=$lvl}}.test({{=$data}});
|
||||
|
||||
{{# def.checkError:'format' }}
|
||||
{{??}}
|
||||
var valid{{=$lvl}} = true;
|
||||
var {{=$valid}} = true;
|
||||
{{?}}
|
||||
|
|
|
@ -4,16 +4,16 @@
|
|||
|
||||
|
||||
{{## def.validateItems:startFrom:
|
||||
for (var i = {{= startFrom }}; i < data{{=$dataLvl}}.length; i++) {
|
||||
var data{{=$dataNxt}} = data{{=$dataLvl}}[i]
|
||||
for (var i = {{=startFrom}}; i < {{=$data}}.length; i++) {
|
||||
var data{{=$dataNxt}} = {{=$data}}[i]
|
||||
, dataPath{{=$dataNxt}} = dataPath{{=$dataLvl}} + '[' + i + ']';
|
||||
|
||||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }};
|
||||
|
||||
{{? $breakOnError }}
|
||||
valid{{=$lvl}} = valid{{=$it.level}};
|
||||
if (!valid{{=$lvl}}) break;
|
||||
{{=$valid}} = valid{{=$it.level}};
|
||||
if (!{{=$valid}}) break;
|
||||
{{?}}
|
||||
}
|
||||
#}}
|
||||
|
@ -21,33 +21,33 @@
|
|||
{{ var $dataNxt = $it.dataLevel = it.dataLevel + 1; }}
|
||||
|
||||
var errs{{=$lvl}} = validate.errors.length;
|
||||
var valid{{=$lvl}};
|
||||
var {{=$valid}};
|
||||
|
||||
{{? Array.isArray($schema) }}
|
||||
{{ /* 'items' is an array of schemas */}}
|
||||
{{ var $additionalItems = it.schema.additionalItems; }}
|
||||
{{? $additionalItems === false }}
|
||||
valid{{=$lvl}} = data{{=$dataLvl}}.length <= {{= $schema.length }};
|
||||
{{=$valid}} = {{=$data}}.length <= {{= $schema.length }};
|
||||
{{# def.checkError:'additionalItems' }}
|
||||
{{# def.elseIfValid}}
|
||||
{{?}}
|
||||
|
||||
{{~ $schema:$sch:$i }}
|
||||
{{? Object.keys($sch).length }}
|
||||
valid{{=$lvl}} = true;
|
||||
{{=$valid}} = true;
|
||||
|
||||
if (data{{=$dataLvl}}.length > {{=$i}}) {
|
||||
if ({{=$data}}.length > {{=$i}}) {
|
||||
{{
|
||||
$it.schema = $sch;
|
||||
$it.schemaPath = $schemaPath + '[' + $i + ']';
|
||||
}}
|
||||
|
||||
var data{{=$dataNxt}} = data{{=$dataLvl}}[{{= $i }}]
|
||||
var data{{=$dataNxt}} = {{=$data}}[{{= $i }}]
|
||||
, dataPath{{=$dataNxt}} = dataPath{{=$dataLvl}} + '[{{=$i}}]';
|
||||
|
||||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }}
|
||||
valid{{=$lvl}} = valid{{=$it.level}};
|
||||
{{=$valid}} = valid{{=$it.level}};
|
||||
}
|
||||
|
||||
{{# def.ifValid }}
|
||||
|
@ -60,7 +60,7 @@ var valid{{=$lvl}};
|
|||
$it.schemaPath = it.schemaPath + '.additionalItems';
|
||||
}}
|
||||
|
||||
if (data{{=$dataLvl}}.length > {{= $schema.length }}) {
|
||||
if ({{=$data}}.length > {{= $schema.length }}) {
|
||||
{{# def.validateItems: $schema.length }}
|
||||
}
|
||||
|
||||
|
@ -79,6 +79,6 @@ var valid{{=$lvl}};
|
|||
|
||||
{{? $breakOnError }} {{= $closingBraces }} {{?}}
|
||||
|
||||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
{{=$valid}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxItems' }}
|
||||
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length <= {{=$schema}};
|
||||
var {{=$valid}} = {{=$data}}.length <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxItems' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxLength' }}
|
||||
|
||||
var valid{{=$lvl}} = {{# def.strLength }} <= {{=$schema}};
|
||||
var {{=$valid}} = {{# def.strLength }} <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxLength' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'maxProperties' }}
|
||||
|
||||
var valid{{=$lvl}} = Object.keys(data{{=$dataLvl}}).length <= {{=$schema}};
|
||||
var {{=$valid}} = Object.keys({{=$data}}).length <= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maxProperties' }}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
, $op = $exclusive ? '<' : '<=';
|
||||
}}
|
||||
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
var {{=$valid}} = {{=$data}} {{=$op}} {{=$schema}};
|
||||
|
||||
{{# def.checkError:'maximum' }}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minItems' }}
|
||||
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}}.length >= {{=$schema}};
|
||||
var {{=$valid}} = {{=$data}}.length >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minItems' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minLength' }}
|
||||
|
||||
var valid{{=$lvl}} = {{# def.strLength }} >= {{=$schema}};
|
||||
var {{=$valid}} = {{# def.strLength }} >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minLength' }}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'minProperties' }}
|
||||
|
||||
var valid{{=$lvl}} = Object.keys(data{{=$dataLvl}}).length >= {{=$schema}};
|
||||
var {{=$valid}} = Object.keys({{=$data}}).length >= {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minProperties' }}
|
|
@ -6,6 +6,6 @@
|
|||
, $op = $exclusive ? '>' : '>=';
|
||||
}}
|
||||
|
||||
var valid{{=$lvl}} = data{{=$dataLvl}} {{=$op}} {{=$schema}};
|
||||
var {{=$valid}} = {{=$data}} {{=$op}} {{=$schema}};
|
||||
|
||||
{{# def.checkError:'minimum' }}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'multipleOf' }}
|
||||
|
||||
var division{{=$lvl}} = data{{=$dataLvl}} / {{=$schema}};
|
||||
var valid{{=$lvl}} = division{{=$lvl}} === parseInt(division{{=$lvl}});
|
||||
var division{{=$lvl}} = {{=$data}} / {{=$schema}};
|
||||
var {{=$valid}} = division{{=$lvl}} === parseInt(division{{=$lvl}});
|
||||
|
||||
{{# def.checkError:'multipleOf' }}
|
||||
|
|
|
@ -12,8 +12,8 @@ var errs{{=$lvl}} = validate.errors.length;
|
|||
|
||||
{{= it.validate($it) }}
|
||||
|
||||
var valid{{=$lvl}} = valid{{=$it.level}};
|
||||
valid{{=$lvl}} = !valid{{=$lvl}};
|
||||
var {{=$valid}} = valid{{=$it.level}};
|
||||
{{=$valid}} = !{{=$valid}};
|
||||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
if ({{=$valid}}) validate.errors.length = errs{{=$lvl}};
|
||||
else {{# def.error:'not' }}
|
||||
|
|
|
@ -20,13 +20,13 @@ var validCount{{=$lvl}} = 0;
|
|||
|
||||
{{= it.validate($it) }}
|
||||
|
||||
var valid{{=$lvl}} = valid{{=$it.level}};
|
||||
if (valid{{=$lvl}}) validCount{{=$lvl}}++;
|
||||
var {{=$valid}} = valid{{=$it.level}};
|
||||
if ({{=$valid}}) validCount{{=$lvl}}++;
|
||||
{{~}}
|
||||
|
||||
{{= $closingBraces }}
|
||||
|
||||
var valid{{=$lvl}} = validCount{{=$lvl}} == 1;
|
||||
var {{=$valid}} = validCount{{=$lvl}} == 1;
|
||||
|
||||
if (valid{{=$lvl}}) validate.errors.length = errs{{=$lvl}};
|
||||
if ({{=$valid}}) validate.errors.length = errs{{=$lvl}};
|
||||
else {{# def.error:'oneOf' }}
|
||||
|
|
|
@ -2,6 +2,6 @@
|
|||
{{# def.setup:'pattern' }}
|
||||
|
||||
{{ new RegExp($schema); /* test if regexp is valid to fail at compile time rather than in eval */}}
|
||||
var valid{{=$lvl}} = /{{=$schema}}/.test(data{{=$dataLvl}});
|
||||
var {{=$valid}} = /{{=$schema}}/.test({{=$data}});
|
||||
|
||||
{{# def.checkError:'pattern' }}
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
|
||||
|
||||
{{## def.validateProperty:useKey:
|
||||
var data{{=$dataNxt}} = data{{=$dataLvl}}[{{= useKey }}]
|
||||
var data{{=$dataNxt}} = {{=$data}}[{{= useKey }}]
|
||||
, dataPath{{=$dataNxt}} = dataPath{{=$dataLvl}} + '.' + {{= useKey }};
|
||||
|
||||
{{ $it.inline = true; }}
|
||||
{{= it.validate($it) }};
|
||||
valid{{=$lvl}} = valid{{=$it.level}};
|
||||
{{=$valid}} = valid{{=$it.level}};
|
||||
#}}
|
||||
|
||||
{{
|
||||
|
@ -26,14 +26,14 @@
|
|||
|
||||
|
||||
var errs{{=$lvl}} = validate.errors.length;
|
||||
var valid{{=$lvl}} = true;
|
||||
var {{=$valid}} = true;
|
||||
|
||||
{{? $checkAdditional }}
|
||||
var propertiesSchema{{=$lvl}} = validate.schema{{=$schemaPath}} || {};
|
||||
{{?}}
|
||||
|
||||
{{? $noAdditional }}
|
||||
var valid{{=$lvl}} = Object.keys(data{{=$dataLvl}}).length <= Object.keys(propertiesSchema{{=$lvl}}).length;
|
||||
var {{=$valid}} = Object.keys({{=$data}}).length <= Object.keys(propertiesSchema{{=$lvl}}).length;
|
||||
{{# def.checkError:'additionalProperties' }}
|
||||
{{# def.elseIfValid }}
|
||||
{{?}}
|
||||
|
@ -48,7 +48,7 @@ var valid{{=$lvl}} = true;
|
|||
|
||||
|
||||
{{? $checkAdditional }}
|
||||
for (var key{{=$lvl}} in data{{=$dataLvl}}) {
|
||||
for (var key{{=$lvl}} in {{=$data}}) {
|
||||
var isAdditional{{=$lvl}} = !propertiesSchema{{=$lvl}}.hasOwnProperty(key{{=$lvl}});
|
||||
|
||||
{{? $pPropertyKeys.length }}
|
||||
|
@ -65,7 +65,7 @@ var valid{{=$lvl}} = true;
|
|||
|
||||
if (isAdditional{{=$lvl}}) {
|
||||
{{? $noAdditional }}
|
||||
valid{{=$lvl}} = false;
|
||||
{{=$valid}} = false;
|
||||
{{# def.error:'additionalProperties' }}
|
||||
{{? $breakOnError }} break; {{?}}
|
||||
{{??}}
|
||||
|
@ -76,7 +76,7 @@ var valid{{=$lvl}} = true;
|
|||
|
||||
{{ var $useKey = 'key' + $lvl; }}
|
||||
{{# def.validateProperty:$useKey }}
|
||||
{{? $breakOnError }} if (!valid{{=$lvl}}) break; {{?}}
|
||||
{{? $breakOnError }} if (!{{=$valid}}) break; {{?}}
|
||||
{{?}}
|
||||
}
|
||||
}
|
||||
|
@ -94,8 +94,8 @@ var valid{{=$lvl}} = true;
|
|||
$it.schemaPath = $schemaPath + '["' + it.escapeQuotes($propertyKey) + '"]';
|
||||
}}
|
||||
|
||||
{{? $breakOnError }} valid{{=$lvl}} = true; {{?}}
|
||||
if (data{{=$dataLvl}}.hasOwnProperty('{{= $propertyKey }}')) {
|
||||
{{? $breakOnError }} {{=$valid}} = true; {{?}}
|
||||
if ({{=$data}}.hasOwnProperty('{{= $propertyKey }}')) {
|
||||
{{ /* TODO cache data types and paths by keys for patternProperties */ }}
|
||||
{{ var $useKey = '"' + $propertyKey + '"'; }}
|
||||
{{# def.validateProperty:$useKey }}
|
||||
|
@ -115,13 +115,13 @@ var valid{{=$lvl}} = true;
|
|||
$it.schemaPath = it.schemaPath + '.patternProperties.' + $propertyKey;
|
||||
}}
|
||||
|
||||
for (var key{{=$lvl}} in data{{=$dataLvl}}) {
|
||||
for (var key{{=$lvl}} in {{=$data}}) {
|
||||
var keyMatches{{=$lvl}} = pPropertiesRegexps{{=$lvl}}['{{= $propertyKey }}'].test(key{{=$lvl}});
|
||||
|
||||
if (keyMatches{{=$lvl}}) {
|
||||
{{ var $useKey = 'key' + $lvl; }}
|
||||
{{# def.validateProperty:$useKey }}
|
||||
{{? $breakOnError }} if (!valid{{=$lvl}}) break; {{?}}
|
||||
{{? $breakOnError }} if (!{{=$valid}}) break; {{?}}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -131,6 +131,6 @@ var valid{{=$lvl}} = true;
|
|||
|
||||
{{? $breakOnError }}{{= $closingBraces }}{{?}}
|
||||
|
||||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
{{=$valid}} = errs{{=$lvl}} == validate.errors.length;
|
||||
|
||||
{{# def.cleanUp }}
|
||||
|
|
|
@ -2,16 +2,16 @@
|
|||
{{# def.setup:'required' }}
|
||||
|
||||
{{? $schema.length <= 100 }}
|
||||
valid{{=$lvl}} = {{~ $schema:$property:$i }}
|
||||
{{=$valid}} = {{~ $schema:$property:$i }}
|
||||
{{? $i}} && {{?}}
|
||||
data{{=$dataLvl}}.hasOwnProperty('{{= it.escapeQuotes($property) }}')
|
||||
{{=$data}}.hasOwnProperty('{{= it.escapeQuotes($property) }}')
|
||||
{{~}};
|
||||
{{??}}
|
||||
var schema{{=$lvl}} = validate.schema{{=$schemaPath}};
|
||||
|
||||
for (var i{{=$lvl}} = 0; i{{=$lvl}} < schema{{=$lvl}}.length; i{{=$lvl}}++) {
|
||||
valid{{=$lvl}} = data.hasOwnProperty(schema{{=$lvl}}[i{{=$lvl}}]);
|
||||
if (!valid{{=$lvl}}) break;
|
||||
{{=$valid}} = data.hasOwnProperty(schema{{=$lvl}}[i{{=$lvl}}]);
|
||||
if (!{{=$valid}}) break;
|
||||
}
|
||||
{{?}}
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
{{ var $isArray = Array.isArray($schema); }}
|
||||
|
||||
{{? $isArray }}
|
||||
var valid{{=$lvl}} = {{= it.checkDataTypes($schema, $dataLvl) }};
|
||||
var {{=$valid}} = {{= it.checkDataTypes($schema, $dataLvl) }};
|
||||
{{??}}
|
||||
var valid{{=$lvl}} = {{= it.checkDataType($schema, $dataLvl) }};
|
||||
var {{=$valid}} = {{= it.checkDataType($schema, $dataLvl) }};
|
||||
{{?}}
|
||||
|
||||
{{# def.checkError:'type' }}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
{{# def.definitions }}
|
||||
{{# def.setup:'uniqueItems' }}
|
||||
|
||||
var valid{{=$lvl}} = true;
|
||||
var {{=$valid}} = true;
|
||||
|
||||
{{? $schema && it.opts.uniqueItems !== false }}
|
||||
if (data{{=$dataLvl}}.length > 1) {
|
||||
var i{{=$lvl}} = data{{=$dataLvl}}.length, j{{=$lvl}};
|
||||
if ({{=$data}}.length > 1) {
|
||||
var i{{=$lvl}} = {{=$data}}.length, j{{=$lvl}};
|
||||
outer:
|
||||
for (;i{{=$lvl}}--;) {
|
||||
for (j{{=$lvl}} = i{{=$lvl}}; j{{=$lvl}}--;) {
|
||||
if (equal(data{{=$dataLvl}}[i{{=$lvl}}], data{{=$dataLvl}}[j{{=$lvl}}])) {
|
||||
valid{{=$lvl}} = false;
|
||||
if (equal({{=$data}}[i{{=$lvl}}], {{=$data}}[j{{=$lvl}}])) {
|
||||
{{=$valid}} = false;
|
||||
break outer;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,12 +31,13 @@
|
|||
{{?}}
|
||||
|
||||
{{
|
||||
var $breakOnErrors = !it.opts.allErrors
|
||||
var $valid = 'valid' + $lvl
|
||||
, $breakOnErrors = !it.opts.allErrors
|
||||
, $closingBraces1 = ''
|
||||
, $closingBraces2 = '';
|
||||
}}
|
||||
|
||||
var valid{{=$lvl}} = true;
|
||||
var {{=$valid}} = true;
|
||||
|
||||
{{~ it.RULES:$rulesGroup }}
|
||||
{{? $shouldUseGroup($rulesGroup) }}
|
||||
|
@ -45,7 +46,7 @@ var valid{{=$lvl}} = true;
|
|||
{{? $shouldUseRule($rule) }}
|
||||
{{= $rule.code(it) }}
|
||||
{{? $breakOnErrors }}
|
||||
if (valid{{=$lvl}}) {
|
||||
if ({{=$valid}}) {
|
||||
{{ $closingBraces1 += '}'; }}
|
||||
{{?}}
|
||||
{{?}}
|
||||
|
@ -57,7 +58,7 @@ var valid{{=$lvl}} = true;
|
|||
{{? $rulesGroup.type }} } {{?}}
|
||||
|
||||
{{? $breakOnErrors }}
|
||||
if (valid{{=$lvl}}) {
|
||||
if ({{=$valid}}) {
|
||||
{{ $closingBraces2 += '}'; }}
|
||||
{{?}}
|
||||
{{?}}
|
||||
|
@ -69,7 +70,7 @@ var valid{{=$lvl}} = true;
|
|||
return errs{{=$lvl}} == validate.errors.length;
|
||||
}
|
||||
{{??}}
|
||||
valid{{=$lvl}} = errs{{=$lvl}} == validate.errors.length;
|
||||
{{=$valid}} = errs{{=$lvl}} == validate.errors.length;
|
||||
{{?}}
|
||||
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "ajv",
|
||||
"version": "0.2.1",
|
||||
"version": "0.2.2",
|
||||
"description": "Another JSON schema Validator",
|
||||
"main": "lib/ajv.js",
|
||||
"scripts": {
|
||||
|
|
|
@ -23,8 +23,8 @@ SKIP_RULES = [
|
|||
|
||||
|
||||
var Ajv = require('../lib/ajv')
|
||||
, ajv = Ajv({ unicode: true })
|
||||
, fullAjv = Ajv({ unicode: true, allErrors: true, verbose: true });
|
||||
, ajv = Ajv()
|
||||
, fullAjv = Ajv({ allErrors: true, verbose: true });
|
||||
|
||||
var remoteRefs = {
|
||||
'http://localhost:1234/integer.json': require('./JSON-Schema-Test-Suite/remotes/integer.json'),
|
||||
|
|
Loading…
Reference in New Issue