3 {{# def.setupKeyword }}
4 {{# def.setupNextLevel }}
7 {{## def.validateAdditional:
8 {{ /* additionalProperties is schema */
9 $it.schema = $aProperties;
10 $it.schemaPath = it.schemaPath + '.additionalProperties';
11 $it.errSchemaPath = it.errSchemaPath + '/additionalProperties';
12 $it.errorPath = it.opts._errorDataPathProperty
14 : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
15 var $passData = $data + '[' + $key + ']';
16 $it.dataPathArr[$dataNxt] = $key;
19 {{# def.generateSubschemaCode }}
20 {{# def.optimizeValidate }}
25 var $key = 'key' + $lvl
27 , $dataNxt = $it.dataLevel = it.dataLevel + 1
28 , $nextData = 'data' + $dataNxt
29 , $dataProperties = 'dataProperties' + $lvl;
31 var $schemaKeys = Object.keys($schema || {}).filter(notProto)
32 , $pProperties = it.schema.patternProperties || {}
33 , $pPropertyKeys = Object.keys($pProperties).filter(notProto)
34 , $aProperties = it.schema.additionalProperties
35 , $someProperties = $schemaKeys.length || $pPropertyKeys.length
36 , $noAdditional = $aProperties === false
37 , $additionalIsSchema = typeof $aProperties == 'object'
38 && Object.keys($aProperties).length
39 , $removeAdditional = it.opts.removeAdditional
40 , $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
41 , $ownProperties = it.opts.ownProperties
42 , $currentBaseId = it.baseId;
44 var $required = it.schema.required;
45 if ($required && !(it.opts.$data && $required.$data) && $required.length < it.opts.loopRequired) {
46 var $requiredHash = it.util.toHash($required);
49 function notProto(p) { return p !== '__proto__'; }
53 var {{=$errs}} = errors;
54 var {{=$nextValid}} = true;
56 var {{=$dataProperties}} = undefined;
59 {{? $checkAdditional }}
60 {{# def.iterateProperties }}
61 {{? $someProperties }}
62 var isAdditional{{=$lvl}} = !(false
63 {{? $schemaKeys.length }}
64 {{? $schemaKeys.length > 8 }}
65 || validate.schema{{=$schemaPath}}.hasOwnProperty({{=$key}})
67 {{~ $schemaKeys:$propertyKey }}
68 || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
72 {{? $pPropertyKeys.length }}
73 {{~ $pPropertyKeys:$pProperty:$i }}
74 || {{= it.usePattern($pProperty) }}.test({{=$key}})
79 if (isAdditional{{=$lvl}}) {
81 {{? $removeAdditional == 'all' }}
82 delete {{=$data}}[{{=$key}}];
85 var $currentErrorPath = it.errorPath;
86 var $additionalProperty = '\' + ' + $key + ' + \'';
87 if (it.opts._errorDataPathProperty) {
88 it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
92 {{? $removeAdditional }}
93 delete {{=$data}}[{{=$key}}];
95 {{=$nextValid}} = false;
97 var $currErrSchemaPath = $errSchemaPath;
98 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
100 {{# def.error:'additionalProperties' }}
101 {{ $errSchemaPath = $currErrSchemaPath; }}
102 {{? $breakOnError }} break; {{?}}
104 {{?? $additionalIsSchema }}
105 {{? $removeAdditional == 'failing' }}
106 var {{=$errs}} = errors;
107 {{# def.setCompositeRule }}
109 {{# def.validateAdditional }}
111 if (!{{=$nextValid}}) {
113 if (validate.errors !== null) {
114 if (errors) validate.errors.length = errors;
115 else validate.errors = null;
117 delete {{=$data}}[{{=$key}}];
120 {{# def.resetCompositeRule }}
122 {{# def.validateAdditional }}
123 {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
126 {{ it.errorPath = $currentErrorPath; }}
128 {{? $someProperties }}
133 {{# def.ifResultValid }}
136 {{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
138 {{? $schemaKeys.length }}
139 {{~ $schemaKeys:$propertyKey }}
140 {{ var $sch = $schema[$propertyKey]; }}
142 {{? {{# def.nonEmptySchema:$sch}} }}
144 var $prop = it.util.getProperty($propertyKey)
145 , $passData = $data + $prop
146 , $hasDefault = $useDefaults && $sch.default !== undefined;
148 $it.schemaPath = $schemaPath + $prop;
149 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
150 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
151 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
154 {{# def.generateSubschemaCode }}
156 {{? {{# def.willOptimize }} }}
158 $code = {{# def._optimizeValidate }};
159 var $useData = $passData;
162 {{ var $useData = $nextData; }}
163 var {{=$nextData}} = {{=$passData}};
169 {{? $requiredHash && $requiredHash[$propertyKey] }}
170 if ({{# def.noPropertyInData }}) {
171 {{=$nextValid}} = false;
173 var $currentErrorPath = it.errorPath
174 , $currErrSchemaPath = $errSchemaPath
175 , $missingProperty = it.util.escapeQuotes($propertyKey);
176 if (it.opts._errorDataPathProperty) {
177 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
179 $errSchemaPath = it.errSchemaPath + '/required';
181 {{# def.error:'required' }}
182 {{ $errSchemaPath = $currErrSchemaPath; }}
183 {{ it.errorPath = $currentErrorPath; }}
187 if ({{# def.noPropertyInData }}) {
188 {{=$nextValid}} = true;
191 if ({{=$useData}} !== undefined
192 {{? $ownProperties }}
193 && {{# def.isOwnProperty }}
201 {{?}} {{ /* $hasDefault */ }}
202 {{?}} {{ /* def.nonEmptySchema */ }}
204 {{# def.ifResultValid }}
208 {{? $pPropertyKeys.length }}
209 {{~ $pPropertyKeys:$pProperty }}
210 {{ var $sch = $pProperties[$pProperty]; }}
212 {{? {{# def.nonEmptySchema:$sch}} }}
215 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
216 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
217 + it.util.escapeFragment($pProperty);
220 {{# def.iterateProperties }}
221 if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
223 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
224 var $passData = $data + '[' + $key + ']';
225 $it.dataPathArr[$dataNxt] = $key;
228 {{# def.generateSubschemaCode }}
229 {{# def.optimizeValidate }}
231 {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
233 {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
236 {{# def.ifResultValid }}
237 {{?}} {{ /* def.nonEmptySchema */ }}
243 {{= $closingBraces }}
244 if ({{=$errs}} == errors) {