2015-06-03 03:36:59 +03:00
|
|
|
{{# def.definitions }}
|
|
|
|
{{# def.setup:'properties' }}
|
|
|
|
{{# def.setupNextLevel }}
|
|
|
|
|
2015-06-02 03:59:32 +03:00
|
|
|
|
2015-06-01 03:59:58 +03:00
|
|
|
{{
|
2015-06-13 00:10:56 +03:00
|
|
|
var $dataNxt = $it.dataLevel = it.dataLevel + 1
|
|
|
|
, $nextData = 'data' + $dataNxt;
|
2015-06-03 03:36:59 +03:00
|
|
|
|
|
|
|
var $pProperties = it.schema.patternProperties || {}
|
2015-06-01 03:59:58 +03:00
|
|
|
, $pPropertyKeys = Object.keys($pProperties)
|
|
|
|
, $aProperties = it.schema.additionalProperties
|
|
|
|
, $noAdditional = $aProperties === false
|
|
|
|
, $additionalIsSchema = typeof $aProperties == 'object'
|
|
|
|
&& Object.keys($aProperties).length
|
2015-07-31 21:23:35 +03:00
|
|
|
, $removeAdditional = it.opts.removeAdditional
|
|
|
|
, $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional;
|
2015-06-01 03:59:58 +03:00
|
|
|
}}
|
|
|
|
|
2015-06-03 03:36:59 +03:00
|
|
|
|
2015-06-13 15:01:05 +03:00
|
|
|
var {{=$errs}} = errors;
|
2015-06-06 04:07:50 +03:00
|
|
|
var valid{{=$it.level}} = true;
|
2015-06-02 03:59:32 +03:00
|
|
|
|
2015-06-01 03:59:58 +03:00
|
|
|
{{? $checkAdditional }}
|
2015-06-03 03:36:59 +03:00
|
|
|
var propertiesSchema{{=$lvl}} = validate.schema{{=$schemaPath}} || {};
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-05 02:42:34 +03:00
|
|
|
for (var key{{=$lvl}} in {{=$data}}) {
|
2015-06-06 04:07:50 +03:00
|
|
|
var isAdditional{{=$lvl}} = propertiesSchema{{=$lvl}}[key{{=$lvl}}] === undefined;
|
2015-05-29 14:42:55 +03:00
|
|
|
|
|
|
|
{{? $pPropertyKeys.length }}
|
2015-06-03 03:36:59 +03:00
|
|
|
if (isAdditional{{=$lvl}}) {
|
2015-06-11 01:52:28 +03:00
|
|
|
{{~ $pPropertyKeys:$pProperty:$i }}
|
|
|
|
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}}))
|
2015-06-03 03:36:59 +03:00
|
|
|
isAdditional{{=$lvl}} = false;
|
2015-06-11 01:52:28 +03:00
|
|
|
{{? $i < $pPropertyKeys.length-1 }}
|
|
|
|
else
|
|
|
|
{{?}}
|
|
|
|
{{~}}
|
2015-05-28 03:24:42 +03:00
|
|
|
}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{?}}
|
|
|
|
|
2015-06-17 00:54:08 +03:00
|
|
|
if (isAdditional{{=$lvl}}) {
|
2015-07-30 11:21:36 +03:00
|
|
|
{{? $removeAdditional == 'all' }}
|
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
2015-06-01 03:59:58 +03:00
|
|
|
{{??}}
|
2015-07-30 11:21:36 +03:00
|
|
|
{{
|
|
|
|
var $currentErrorPath = it.errorPath;
|
2015-08-22 01:26:13 +03:00
|
|
|
it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
|
2015-06-01 03:59:58 +03:00
|
|
|
}}
|
2015-07-30 11:21:36 +03:00
|
|
|
{{? $noAdditional }}
|
|
|
|
{{? $removeAdditional }}
|
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
|
|
|
{{??}}
|
|
|
|
valid{{=$it.level}} = false;
|
|
|
|
{{# def.error:'additionalProperties' }}
|
|
|
|
{{? $breakOnError }} break; {{?}}
|
|
|
|
{{?}}
|
2015-07-31 21:23:35 +03:00
|
|
|
{{?? $additionalIsSchema }}
|
|
|
|
{{? $removeAdditional == 'failing' }}
|
|
|
|
var {{=$errs}} = errors;
|
|
|
|
{{?}}
|
2015-07-30 11:21:36 +03:00
|
|
|
{{ /* additionalProperties is schema */
|
|
|
|
$it.schema = $aProperties;
|
|
|
|
$it.schemaPath = it.schemaPath + '.additionalProperties';
|
|
|
|
$it.errorPath = it.errorPath;
|
|
|
|
var $passData = $data + '[key' + $lvl + ']';
|
|
|
|
}}
|
2015-06-01 03:59:58 +03:00
|
|
|
|
2015-07-30 11:21:36 +03:00
|
|
|
{{ var $code = it.validate($it); }}
|
|
|
|
{{# def.optimizeValidate }}
|
2015-06-06 04:07:50 +03:00
|
|
|
|
2015-07-31 21:23:35 +03:00
|
|
|
{{? $removeAdditional == 'failing' }}
|
|
|
|
if (!valid{{=$it.level}}) {
|
|
|
|
errors = {{=$errs}};
|
|
|
|
if (validate.errors !== null) {
|
|
|
|
if (errors) validate.errors.length = errors;
|
|
|
|
else validate.errors = null;
|
|
|
|
}
|
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
|
|
|
}
|
|
|
|
{{??}}
|
|
|
|
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}}
|
|
|
|
{{?}}
|
2015-07-30 11:21:36 +03:00
|
|
|
{{?}}
|
|
|
|
{{ it.errorPath = $currentErrorPath; }}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{?}}
|
2015-05-28 03:24:42 +03:00
|
|
|
}
|
2015-06-01 03:59:58 +03:00
|
|
|
}
|
|
|
|
|
2015-06-06 04:07:50 +03:00
|
|
|
{{# def.ifResultValid }}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{?}}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-03 03:36:59 +03:00
|
|
|
{{? $schema }}
|
|
|
|
{{ for (var $propertyKey in $schema) { }}
|
|
|
|
{{ var $sch = $schema[$propertyKey]; }}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-13 00:10:56 +03:00
|
|
|
{{? {{# def.nonEmptySchema:$sch}} }}
|
2015-05-29 14:42:55 +03:00
|
|
|
{{
|
2015-06-03 03:36:59 +03:00
|
|
|
$it.schema = $sch;
|
2015-06-13 00:10:56 +03:00
|
|
|
var $prop = it.util.getProperty($propertyKey)
|
|
|
|
, $passData = $data + $prop;
|
2015-06-24 02:43:52 +03:00
|
|
|
$it.schemaPath = $schemaPath + $prop;
|
2015-08-22 01:26:13 +03:00
|
|
|
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
|
2015-05-29 14:42:55 +03:00
|
|
|
}}
|
|
|
|
|
2015-06-13 01:30:50 +03:00
|
|
|
{{ var $code = it.validate($it); }}
|
2015-06-06 04:07:50 +03:00
|
|
|
|
2015-06-13 00:10:56 +03:00
|
|
|
{{? {{# def.willOptimize }} }}
|
2015-06-13 21:59:08 +03:00
|
|
|
{{
|
|
|
|
$code = {{# def._optimizeValidate }};
|
|
|
|
var $useData = $passData;
|
|
|
|
}}
|
2015-06-13 00:10:56 +03:00
|
|
|
{{??}}
|
2015-06-13 21:59:08 +03:00
|
|
|
{{ var $useData = $nextData; }}
|
2015-06-13 00:10:56 +03:00
|
|
|
var {{=$nextData}} = {{=$passData}};
|
2015-06-13 21:59:08 +03:00
|
|
|
{{?}}
|
|
|
|
|
|
|
|
{{? $breakOnError }}
|
|
|
|
if ({{=$useData}} === undefined) {
|
|
|
|
valid{{=$it.level}} = true;
|
|
|
|
} else {
|
|
|
|
{{??}}
|
|
|
|
if ({{=$useData}} !== undefined) {
|
|
|
|
{{?}}
|
2015-06-13 00:10:56 +03:00
|
|
|
{{= $code }}
|
|
|
|
}
|
|
|
|
{{?}} {{ /* def.nonEmptySchema */ }}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-06 04:07:50 +03:00
|
|
|
{{# def.ifResultValid }}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{ } }}
|
|
|
|
{{?}}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-11 01:52:28 +03:00
|
|
|
{{~ $pPropertyKeys:$pProperty }}
|
|
|
|
{{ var $sch = $pProperties[$pProperty]; }}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-13 00:10:56 +03:00
|
|
|
{{? {{# def.nonEmptySchema:$sch}} }}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{
|
2015-06-03 03:36:59 +03:00
|
|
|
$it.schema = $sch;
|
2015-06-23 19:25:50 +03:00
|
|
|
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
|
2015-06-01 03:59:58 +03:00
|
|
|
}}
|
2015-05-29 14:42:55 +03:00
|
|
|
|
2015-06-05 02:42:34 +03:00
|
|
|
for (var key{{=$lvl}} in {{=$data}}) {
|
2015-06-11 01:52:28 +03:00
|
|
|
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}})) {
|
2015-06-13 00:10:56 +03:00
|
|
|
{{
|
2015-08-22 01:26:13 +03:00
|
|
|
$it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
|
2015-06-13 01:30:50 +03:00
|
|
|
var $passData = $data + '[key' + $lvl + ']';
|
2015-06-13 00:10:56 +03:00
|
|
|
}}
|
|
|
|
|
|
|
|
{{ var $code = it.validate($it); }}
|
|
|
|
{{# def.optimizeValidate }}
|
2015-06-06 04:07:50 +03:00
|
|
|
|
|
|
|
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}}
|
2015-05-29 14:42:55 +03:00
|
|
|
}
|
2015-06-13 21:59:08 +03:00
|
|
|
{{? $breakOnError }} else valid{{=$it.level}} = true; {{?}}
|
2015-06-01 03:59:58 +03:00
|
|
|
}
|
|
|
|
|
2015-06-06 04:07:50 +03:00
|
|
|
{{# def.ifResultValid }}
|
2015-06-13 00:10:56 +03:00
|
|
|
{{?}} {{ /* def.nonEmptySchema */ }}
|
2015-06-01 03:59:58 +03:00
|
|
|
{{~}}
|
|
|
|
|
2015-06-12 13:43:41 +03:00
|
|
|
{{? $breakOnError }}
|
|
|
|
{{= $closingBraces }}
|
2015-06-13 15:01:05 +03:00
|
|
|
if ({{=$errs}} == errors) {
|
2015-06-12 13:43:41 +03:00
|
|
|
{{?}}
|
2015-06-02 03:59:32 +03:00
|
|
|
|
2015-06-03 03:36:59 +03:00
|
|
|
{{# def.cleanUp }}
|