optimized required keyword

master
Evgeny Poberezkin 2015-05-31 02:01:30 +01:00
parent 089ac03b1b
commit 46cf5f9930
4 changed files with 17 additions and 21 deletions

View File

@ -41,4 +41,5 @@ ajv compiles schemas to functions and caches them in both cases (using stringifi
- _allErrors_: if true, jv will continue validating all rules collecting all errors (false by default)
- _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)
- _unicode_: if true, the lengths of strings with unicode pairs will be correct (false by default) - not implemented yet.

View File

@ -1,6 +1,5 @@
function (data, dataType, dataPath) {
'use strict';
/* TODO change to inline ??? */
var errs = validate.errors.length;

View File

@ -1,28 +1,24 @@
var valid = true, missing = '';
var req_schema = validate.schema{{= it.schemaPath + '.required' }};
{{ var $req_schema = it.schema.required; }}
{{? $req_schema.length <= 100 }}
var valid = {{~ $req_schema:$req_property:$i }}
{{? $i}} && {{?}}
data.hasOwnProperty('{{= it.escapeQuotes($req_property) }}')
{{~}};
{{??}}
var valid = true;
var req_schema = validate.schema{{= it.schemaPath + '.required' }};
for (var i = 0; i < req_schema.length; i++) {
var property = req_schema[i]
, has = data.hasOwnProperty(req_schema[i])
, valid = valid && has;
for (var i = 0; i < req_schema.length; i++) {
var property = req_schema[i]
, valid = valid && data.hasOwnProperty(req_schema[i]);
if (!has) {
{{? it.opts.allErrors }}
missing += ', ' + property;
{{??}}
missing = property;
break;
{{?}}
{{? !it.opts.allErrors }} if (!valid) break; {{?}}
}
}
{{? it.opts.allErrors }}
missing = missing.slice(2);
{{?}}
if (!valid) validate.errors.push({
keyword: 'required',
dataPath: dataPath,
message: 'properties ' + missing + ' are missing'
{{? it.opts.verbose }}, schema: req_schema, data: data{{?}}
message: 'properties {{= $req_schema.slice(0, 7).join(",") }}{{? $req_schema.length > 7}}...{{?}} are required'
{{? it.opts.verbose }}, schema: validate.schema{{= it.schemaPath + '.required' }}, data: data{{?}}
});

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "0.1.2",
"version": "0.1.3",
"description": "Another JSON schema Validator",
"main": "lib/ajv.js",
"scripts": {