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