ajv/lib/dot/properties.jst

174 lines
5.0 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 $schemaKeys = Object.keys($schema || {})
, $pProperties = it.schema.patternProperties || {}
2015-06-01 03:59:58 +03:00
, $pPropertyKeys = Object.keys($pProperties)
, $aProperties = it.schema.additionalProperties
, $someProperties = $schemaKeys.length || $pPropertyKeys.length
2015-06-01 03:59:58 +03:00
, $noAdditional = $aProperties === false
, $additionalIsSchema = typeof $aProperties == 'object'
&& Object.keys($aProperties).length
, $removeAdditional = it.opts.removeAdditional
, $checkAdditional = $noAdditional || $additionalIsSchema || $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 }}
for (var key{{=$lvl}} in {{=$data}}) {
{{? $someProperties }}
var isAdditional{{=$lvl}} = !(false
{{? $schemaKeys.length }}
{{? $schemaKeys.length > 5 }}
|| validate.schema{{=$schemaPath}}[key{{=$lvl}}]
{{??}}
{{~ $schemaKeys:$propertyKey }}
|| key{{=$lvl}} == {{= it.util.toQuotedString($propertyKey) }}
{{~}}
{{?}}
{{?}}
{{? $pPropertyKeys.length }}
{{~ $pPropertyKeys:$pProperty:$i }}
|| {{= it.usePattern($pProperty) }}.test(key{{=$lvl}})
{{~}}
{{?}}
);
if (isAdditional{{=$lvl}}) {
2015-06-01 03:59:58 +03:00
{{?}}
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; {{?}}
{{?}}
{{?? $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
{{? $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
{{?}}
{{? $someProperties }}
}
{{?}}
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
{{?}}
{{? $schemaKeys.length }}
{{~ $schemaKeys:$propertyKey }}
{{ var $sch = $schema[$propertyKey]; }}
{{? {{# def.nonEmptySchema:$sch}} }}
{{
$it.schema = $sch;
var $prop = it.util.getProperty($propertyKey)
, $passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
2015-08-22 01:26:13 +03:00
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
}}
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.usePattern($pProperty) }}.test(key{{=$lvl}})) {
{{
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 + ']';
}}
{{ 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 }}