ajv/lib/dot/properties.jst

159 lines
4.5 KiB
Plaintext
Raw Normal View History

{{# def.definitions }}
{{# def.setup:'properties' }}
{{# def.setupNextLevel }}
2015-06-02 03:59:32 +03:00
2015-06-01 03:59:58 +03:00
{{
var $dataNxt = $it.dataLevel = it.dataLevel + 1
, $nextData = 'data' + $dataNxt;
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-30 11:21:36 +03:00
, $checkAdditional = $noAdditional || $additionalIsSchema
, $removeAdditional = it.opts.removeAdditional;
2015-06-01 03:59:58 +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 }}
var propertiesSchema{{=$lvl}} = validate.schema{{=$schemaPath}} || {};
2015-06-01 03:59:58 +03:00
{{?}}
2015-06-01 03:59:58 +03:00
{{? $checkAdditional }}
for (var key{{=$lvl}} in {{=$data}}) {
2015-06-06 04:07:50 +03:00
var isAdditional{{=$lvl}} = propertiesSchema{{=$lvl}}[key{{=$lvl}}] === undefined;
{{? $pPropertyKeys.length }}
if (isAdditional{{=$lvl}}) {
{{~ $pPropertyKeys:$pProperty:$i }}
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}}))
isAdditional{{=$lvl}} = false;
{{? $i < $pPropertyKeys.length-1 }}
else
{{?}}
{{~}}
}
2015-06-01 03:59:58 +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;
it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', '');
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; {{?}}
{{?}}
{{??}}
{{ /* additionalProperties is schema */
$it.schema = $aProperties;
$it.schemaPath = it.schemaPath + '.additionalProperties';
$it.errorPath = it.errorPath;
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
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-30 11:21:36 +03:00
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}}
{{?}}
{{ it.errorPath = $currentErrorPath; }}
2015-06-01 03:59:58 +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
{{?}}
{{? $schema }}
{{ for (var $propertyKey in $schema) { }}
{{ var $sch = $schema[$propertyKey]; }}
{{? {{# def.nonEmptySchema:$sch}} }}
{{
$it.schema = $sch;
var $prop = it.util.getProperty($propertyKey)
, $passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', '');
$it.dataPath = it.dataPath + $prop;
}}
2015-06-13 01:30:50 +03:00
{{ var $code = it.validate($it); }}
2015-06-06 04:07:50 +03:00
{{? {{# def.willOptimize }} }}
2015-06-13 21:59:08 +03:00
{{
$code = {{# def._optimizeValidate }};
var $useData = $passData;
}}
{{??}}
2015-06-13 21:59:08 +03:00
{{ var $useData = $nextData; }}
var {{=$nextData}} = {{=$passData}};
2015-06-13 21:59:08 +03:00
{{?}}
{{? $breakOnError }}
if ({{=$useData}} === undefined) {
valid{{=$it.level}} = true;
} else {
{{??}}
if ({{=$useData}} !== undefined) {
{{?}}
{{= $code }}
}
{{?}} {{ /* def.nonEmptySchema */ }}
2015-06-06 04:07:50 +03:00
{{# def.ifResultValid }}
2015-06-01 03:59:58 +03:00
{{ } }}
{{?}}
{{~ $pPropertyKeys:$pProperty }}
{{ var $sch = $pProperties[$pProperty]; }}
{{? {{# def.nonEmptySchema:$sch}} }}
2015-06-01 03:59:58 +03:00
{{
$it.schema = $sch;
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
2015-06-01 03:59:58 +03:00
}}
for (var key{{=$lvl}} in {{=$data}}) {
if (/{{= it.util.escapeRegExp($pProperty) }}/.test(key{{=$lvl}})) {
{{
$it.errorPath = (it.errorPath + ' + "[\'" + key' + $lvl + ' + "\']"').replace('" + "', '');
$it.dataPath = it.dataPath + '[key' + $lvl + ']';
2015-06-13 01:30:50 +03:00
var $passData = $data + '[key' + $lvl + ']';
}}
{{ var $code = it.validate($it); }}
{{# def.optimizeValidate }}
2015-06-06 04:07:50 +03:00
{{? $breakOnError }} if (!valid{{=$it.level}}) break; {{?}}
}
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 }}
{{?}} {{ /* def.nonEmptySchema */ }}
2015-06-01 03:59:58 +03:00
{{~}}
{{? $breakOnError }}
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}
2015-06-02 03:59:32 +03:00
{{# def.cleanUp }}