2015-06-03 03:36:59 +03:00
|
|
|
{{# def.definitions }}
|
|
|
|
{{# def.setup:'properties' }}
|
|
|
|
{{# 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';
|
|
|
|
$it.errorPath = it.errorPath;
|
|
|
|
var $passData = $data + '[key' + $lvl + ']';
|
|
|
|
}}
|
|
|
|
|
|
|
|
{{ var $code = it.validate($it); }}
|
|
|
|
{{# def.optimizeValidate }}
|
|
|
|
#}}
|
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
2015-10-11 02:08:58 +03:00
|
|
|
, $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
|
|
|
|
, $requiredProperties = it.util.toHash(it.schema.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;
|
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-05 02:42:34 +03:00
|
|
|
for (var key{{=$lvl}} in {{=$data}}) {
|
2015-08-24 02:30:49 +03:00
|
|
|
{{? $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}})
|
|
|
|
{{~}}
|
|
|
|
{{?}}
|
|
|
|
);
|
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' }}
|
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
|
|
|
{{??}}
|
|
|
|
{{
|
|
|
|
var $currentErrorPath = it.errorPath;
|
|
|
|
it.errorPath = it.util.getPathExpr(it.errorPath, 'key' + $lvl, it.opts.jsonPointers);
|
|
|
|
}}
|
|
|
|
{{? $noAdditional }}
|
|
|
|
{{? $removeAdditional }}
|
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
|
|
|
{{??}}
|
|
|
|
valid{{=$it.level}} = false;
|
|
|
|
{{# def.error:'additionalProperties' }}
|
|
|
|
{{? $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
|
|
|
|
|
|
|
if (!valid{{=$it.level}}) {
|
|
|
|
errors = {{=$errs}};
|
|
|
|
if (validate.errors !== null) {
|
|
|
|
if (errors) validate.errors.length = errors;
|
|
|
|
else validate.errors = null;
|
2015-07-31 21:23:35 +03:00
|
|
|
}
|
2015-10-11 02:08:58 +03:00
|
|
|
delete {{=$data}}[key{{=$lvl}}];
|
|
|
|
}
|
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 }}
|
2015-10-11 02:08:58 +03:00
|
|
|
{{? $breakOnError }} if (!valid{{=$it.level}}) 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
|
|
|
|
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
|
|
|
{{
|
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
|
|
|
{{?}}
|
|
|
|
|
2015-10-11 02:08:58 +03:00
|
|
|
{{? $requiredProperties[$propertyKey] }}
|
2015-06-13 21:59:08 +03:00
|
|
|
if ({{=$useData}} === undefined) {
|
2015-10-11 02:08:58 +03:00
|
|
|
valid{{=$it.level}} = false;
|
|
|
|
{{
|
|
|
|
var $currentErrorPath = it.errorPath
|
|
|
|
, $missingProperty = it.util.escapeQuotes($propertyKey);
|
|
|
|
it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
|
|
|
|
}}
|
|
|
|
{{# def.error:'required' }}
|
|
|
|
{{ it.errorPath = $currentErrorPath; }}
|
2015-06-13 21:59:08 +03:00
|
|
|
} else {
|
|
|
|
{{??}}
|
2015-10-11 02:08:58 +03:00
|
|
|
{{? $breakOnError }}
|
|
|
|
if ({{=$useData}} === undefined) {
|
|
|
|
valid{{=$it.level}} = true;
|
|
|
|
} else {
|
|
|
|
{{??}}
|
|
|
|
if ({{=$useData}} !== undefined) {
|
|
|
|
{{?}}
|
2015-06-13 21:59:08 +03:00
|
|
|
{{?}}
|
2015-10-11 02:08:58 +03:00
|
|
|
|
|
|
|
{{= $code }}
|
|
|
|
}
|
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
|
|
|
|
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-08-23 01:57:16 +03:00
|
|
|
if ({{= it.usePattern($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 }}
|