ajv/lib/dot/properties.jst

245 lines
7.5 KiB
Plaintext
Raw Normal View History

{{# def.definitions }}
2015-12-12 16:41:51 +03:00
{{# def.errors }}
2015-12-22 20:03:09 +03:00
{{# def.setupKeyword }}
{{# def.setupNextLevel }}
2015-06-02 03:59:32 +03:00
{{## def.validateAdditional:
{{ /* additionalProperties is schema */
$it.schema = $aProperties;
$it.schemaPath = it.schemaPath + '.additionalProperties';
2015-12-19 13:52:39 +03:00
$it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
$it.errorPath = it.opts._errorDataPathProperty
? it.errorPath
2016-12-24 01:02:41 +03:00
: it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
var $passData = $data + '[' + $key + ']';
$it.dataPathArr[$dataNxt] = $key;
}}
{{# def.generateSubschemaCode }}
{{# def.optimizeValidate }}
#}}
2016-05-27 23:21:11 +03:00
2015-06-01 03:59:58 +03:00
{{
2016-05-27 23:21:11 +03:00
var $key = 'key' + $lvl
, $idx = 'idx' + $lvl
2016-05-27 23:21:11 +03:00
, $dataNxt = $it.dataLevel = it.dataLevel + 1
, $nextData = 'data' + $dataNxt
, $dataProperties = 'dataProperties' + $lvl;
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
, $ownProperties = it.opts.ownProperties
, $currentBaseId = it.baseId;
2015-12-26 02:23:42 +03:00
var $required = it.schema.required;
if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired)
var $requiredHash = it.util.toHash($required);
2015-06-01 03:59:58 +03:00
}}
var {{=$errs}} = errors;
2016-12-24 01:02:41 +03:00
var {{=$nextValid}} = true;
{{? $ownProperties }}
var {{=$dataProperties}} = undefined;
{{?}}
2015-06-02 03:59:32 +03:00
2015-06-01 03:59:58 +03:00
{{? $checkAdditional }}
{{# def.iterateProperties }}
{{? $someProperties }}
var isAdditional{{=$lvl}} = !(false
{{? $schemaKeys.length }}
{{? $schemaKeys.length > 5 }}
2016-05-27 23:21:11 +03:00
|| validate.schema{{=$schemaPath}}[{{=$key}}]
{{??}}
{{~ $schemaKeys:$propertyKey }}
2016-05-27 23:21:11 +03:00
|| {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
{{~}}
{{?}}
{{?}}
{{? $pPropertyKeys.length }}
{{~ $pPropertyKeys:$pProperty:$i }}
2016-05-27 23:21:11 +03:00
|| {{= it.usePattern($pProperty) }}.test({{=$key}})
{{~}}
{{?}}
);
if (isAdditional{{=$lvl}}) {
2015-06-01 03:59:58 +03:00
{{?}}
{{? $removeAdditional == 'all' }}
2016-05-27 23:21:11 +03:00
delete {{=$data}}[{{=$key}}];
{{??}}
{{
var $currentErrorPath = it.errorPath;
2016-12-24 01:02:41 +03:00
var $additionalProperty = '\' + ' + $key + ' + \'';
if (it.opts._errorDataPathProperty) {
2016-12-24 01:02:41 +03:00
it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
}
}}
{{? $noAdditional }}
{{? $removeAdditional }}
2016-05-27 23:21:11 +03:00
delete {{=$data}}[{{=$key}}];
{{??}}
2016-12-24 01:02:41 +03:00
{{=$nextValid}} = false;
2015-12-19 13:52:39 +03:00
{{
var $currErrSchemaPath = $errSchemaPath;
$errSchemaPath = it.errSchemaPath + '/additionalProperties';
}}
{{# def.error:'additionalProperties' }}
2015-12-19 13:52:39 +03:00
{{ $errSchemaPath = $currErrSchemaPath; }}
{{? $breakOnError }} break; {{?}}
{{?}}
{{?? $additionalIsSchema }}
{{? $removeAdditional == 'failing' }}
var {{=$errs}} = errors;
{{# def.setCompositeRule }}
2015-06-01 03:59:58 +03:00
{{# def.validateAdditional }}
2016-12-24 01:02:41 +03:00
if (!{{=$nextValid}}) {
errors = {{=$errs}};
if (validate.errors !== null) {
if (errors) validate.errors.length = errors;
else validate.errors = null;
}
2016-05-27 23:21:11 +03:00
delete {{=$data}}[{{=$key}}];
}
{{# def.resetCompositeRule }}
{{??}}
{{# def.validateAdditional }}
2016-12-24 01:02:41 +03:00
{{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
2015-07-30 11:21:36 +03:00
{{?}}
2015-06-01 03:59:58 +03:00
{{?}}
{{ it.errorPath = $currentErrorPath; }}
{{?}}
{{? $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
{{?}}
{{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
{{? $schemaKeys.length }}
{{~ $schemaKeys:$propertyKey }}
{{ var $sch = $schema[$propertyKey]; }}
{{? {{# def.nonEmptySchema:$sch}} }}
{{
var $prop = it.util.getProperty($propertyKey)
, $passData = $data + $prop
, $hasDefault = $useDefaults && $sch.default !== undefined;
$it.schema = $sch;
$it.schemaPath = $schemaPath + $prop;
2015-12-19 13:52:39 +03:00
$it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
2015-08-22 01:26:13 +03:00
$it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
2016-01-17 04:05:06 +03:00
$it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
}}
{{# def.generateSubschemaCode }}
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
{{?}}
{{? $hasDefault }}
{{= $code }}
2015-06-13 21:59:08 +03:00
{{??}}
{{? $requiredHash && $requiredHash[$propertyKey] }}
if ({{# def.noPropertyInData }}) {
2016-12-24 01:02:41 +03:00
{{=$nextValid}} = false;
{{
var $currentErrorPath = it.errorPath
, $currErrSchemaPath = $errSchemaPath
, $missingProperty = it.util.escapeQuotes($propertyKey);
if (it.opts._errorDataPathProperty) {
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
}
$errSchemaPath = it.errSchemaPath + '/required';
}}
{{# def.error:'required' }}
{{ $errSchemaPath = $currErrSchemaPath; }}
{{ it.errorPath = $currentErrorPath; }}
} else {
{{??}}
{{? $breakOnError }}
if ({{# def.noPropertyInData }}) {
2016-12-24 01:02:41 +03:00
{{=$nextValid}} = true;
} else {
{{??}}
if ({{=$useData}} !== undefined
{{? $ownProperties }}
&& {{# def.isOwnProperty }}
{{?}}
) {
{{?}}
{{?}}
{{= $code }}
}
{{?}} {{ /* $hasDefault */ }}
{{?}} {{ /* def.nonEmptySchema */ }}
2015-06-06 04:07:50 +03:00
{{# def.ifResultValid }}
{{~}}
2015-06-01 03:59:58 +03:00
{{?}}
{{? $pPropertyKeys.length }}
{{~ $pPropertyKeys:$pProperty }}
{{ var $sch = $pProperties[$pProperty]; }}
{{? {{# def.nonEmptySchema:$sch}} }}
{{
$it.schema = $sch;
$it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
$it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
+ it.util.escapeFragment($pProperty);
}}
{{# def.iterateProperties }}
if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
{{
2016-12-24 01:18:36 +03:00
$it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
var $passData = $data + '[' + $key + ']';
$it.dataPathArr[$dataNxt] = $key;
}}
{{# def.generateSubschemaCode }}
{{# def.optimizeValidate }}
2015-06-06 04:07:50 +03:00
2016-12-24 01:18:36 +03:00
{{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
}
2016-12-24 01:18:36 +03:00
{{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
}
2015-06-01 03:59:58 +03:00
{{# def.ifResultValid }}
{{?}} {{ /* def.nonEmptySchema */ }}
{{~}}
{{?}}
2015-06-01 03:59:58 +03:00
2015-11-28 17:59:08 +03:00
{{? $breakOnError }}
{{= $closingBraces }}
if ({{=$errs}} == errors) {
{{?}}
2015-06-02 03:59:32 +03:00
{{# def.cleanUp }}