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
26 , $dataNxt = $it.dataLevel = it.dataLevel + 1
27 , $nextData = 'data' + $dataNxt;
29 var $schemaKeys = Object.keys($schema || {})
30 , $pProperties = it.schema.patternProperties || {}
31 , $pPropertyKeys = Object.keys($pProperties)
32 , $aProperties = it.schema.additionalProperties
33 , $someProperties = $schemaKeys.length || $pPropertyKeys.length
34 , $noAdditional = $aProperties === false
35 , $additionalIsSchema = typeof $aProperties == 'object'
36 && Object.keys($aProperties).length
37 , $removeAdditional = it.opts.removeAdditional
38 , $checkAdditional = $noAdditional || $additionalIsSchema || $removeAdditional
39 , $ownProperties = it.opts.ownProperties
40 , $currentBaseId = it.baseId;
42 var $required = it.schema.required;
43 if ($required && !(it.opts.v5 && $required.$data) && $required.length < it.opts.loopRequired)
44 var $requiredHash = it.util.toHash($required);
47 var $pgProperties = it.schema.patternGroups || {}
48 , $pgPropertyKeys = Object.keys($pgProperties);
53 var {{=$errs}} = errors;
54 var {{=$nextValid}} = true;
56 {{? $checkAdditional }}
57 for (var {{=$key}} in {{=$data}}) {
58 {{# def.checkOwnProperty }}
59 {{? $someProperties }}
60 var isAdditional{{=$lvl}} = !(false
61 {{? $schemaKeys.length }}
62 {{? $schemaKeys.length > 5 }}
63 || validate.schema{{=$schemaPath}}[{{=$key}}]
65 {{~ $schemaKeys:$propertyKey }}
66 || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
70 {{? $pPropertyKeys.length }}
71 {{~ $pPropertyKeys:$pProperty:$i }}
72 || {{= it.usePattern($pProperty) }}.test({{=$key}})
75 {{? it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length }}
76 {{~ $pgPropertyKeys:$pgProperty:$i }}
77 || {{= it.usePattern($pgProperty) }}.test({{=$key}})
82 if (isAdditional{{=$lvl}}) {
84 {{? $removeAdditional == 'all' }}
85 delete {{=$data}}[{{=$key}}];
88 var $currentErrorPath = it.errorPath;
89 var $additionalProperty = '\' + ' + $key + ' + \'';
90 if (it.opts._errorDataPathProperty) {
91 it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
95 {{? $removeAdditional }}
96 delete {{=$data}}[{{=$key}}];
98 {{=$nextValid}} = false;
100 var $currErrSchemaPath = $errSchemaPath;
101 $errSchemaPath = it.errSchemaPath + '/additionalProperties';
103 {{# def.error:'additionalProperties' }}
104 {{ $errSchemaPath = $currErrSchemaPath; }}
105 {{? $breakOnError }} break; {{?}}
107 {{?? $additionalIsSchema }}
108 {{? $removeAdditional == 'failing' }}
109 var {{=$errs}} = errors;
110 {{# def.setCompositeRule }}
112 {{# def.validateAdditional }}
114 if (!{{=$nextValid}}) {
116 if (validate.errors !== null) {
117 if (errors) validate.errors.length = errors;
118 else validate.errors = null;
120 delete {{=$data}}[{{=$key}}];
123 {{# def.resetCompositeRule }}
125 {{# def.validateAdditional }}
126 {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
129 {{ it.errorPath = $currentErrorPath; }}
131 {{? $someProperties }}
136 {{# def.ifResultValid }}
139 {{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
141 {{? $schemaKeys.length }}
142 {{~ $schemaKeys:$propertyKey }}
143 {{ var $sch = $schema[$propertyKey]; }}
145 {{? {{# def.nonEmptySchema:$sch}} }}
147 var $prop = it.util.getProperty($propertyKey)
148 , $passData = $data + $prop
149 , $hasDefault = $useDefaults && $sch.default !== undefined;
151 $it.schemaPath = $schemaPath + $prop;
152 $it.errSchemaPath = $errSchemaPath + '/' + it.util.escapeFragment($propertyKey);
153 $it.errorPath = it.util.getPath(it.errorPath, $propertyKey, it.opts.jsonPointers);
154 $it.dataPathArr[$dataNxt] = it.util.toQuotedString($propertyKey);
157 {{# def.generateSubschemaCode }}
159 {{? {{# def.willOptimize }} }}
161 $code = {{# def._optimizeValidate }};
162 var $useData = $passData;
165 {{ var $useData = $nextData; }}
166 var {{=$nextData}} = {{=$passData}};
172 {{? $requiredHash && $requiredHash[$propertyKey] }}
173 if ({{=$useData}} === undefined) {
174 {{=$nextValid}} = false;
176 var $currentErrorPath = it.errorPath
177 , $currErrSchemaPath = $errSchemaPath
178 , $missingProperty = it.util.escapeQuotes($propertyKey);
179 if (it.opts._errorDataPathProperty) {
180 it.errorPath = it.util.getPath($currentErrorPath, $propertyKey, it.opts.jsonPointers);
182 $errSchemaPath = it.errSchemaPath + '/required';
184 {{# def.error:'required' }}
185 {{ $errSchemaPath = $currErrSchemaPath; }}
186 {{ it.errorPath = $currentErrorPath; }}
190 if ({{=$useData}} === undefined) {
191 {{=$nextValid}} = true;
194 if ({{=$useData}} !== undefined) {
200 {{?}} {{ /* $hasDefault */ }}
201 {{?}} {{ /* def.nonEmptySchema */ }}
203 {{# def.ifResultValid }}
207 {{~ $pPropertyKeys:$pProperty }}
208 {{ var $sch = $pProperties[$pProperty]; }}
210 {{? {{# def.nonEmptySchema:$sch}} }}
213 $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
214 $it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
215 + it.util.escapeFragment($pProperty);
218 for (var {{=$key}} in {{=$data}}) {
219 {{# def.checkOwnProperty }}
220 if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
222 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
223 var $passData = $data + '[' + $key + ']';
224 $it.dataPathArr[$dataNxt] = $key;
227 {{# def.generateSubschemaCode }}
228 {{# def.optimizeValidate }}
230 {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
232 {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
235 {{# def.ifResultValid }}
236 {{?}} {{ /* def.nonEmptySchema */ }}
241 {{~ $pgPropertyKeys:$pgProperty }}
243 var $pgSchema = $pgProperties[$pgProperty]
244 , $sch = $pgSchema.schema;
247 {{? {{# def.nonEmptySchema:$sch}} }}
250 $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
251 $it.errSchemaPath = it.errSchemaPath + '/patternGroups/'
252 + it.util.escapeFragment($pgProperty)
256 var pgPropCount{{=$lvl}} = 0;
258 for (var {{=$key}} in {{=$data}}) {
259 {{# def.checkOwnProperty }}
260 if ({{= it.usePattern($pgProperty) }}.test({{=$key}})) {
261 pgPropCount{{=$lvl}}++;
264 $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
265 var $passData = $data + '[' + $key + ']';
266 $it.dataPathArr[$dataNxt] = $key;
269 {{# def.generateSubschemaCode }}
270 {{# def.optimizeValidate }}
272 {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
274 {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
277 {{# def.ifResultValid }}
280 var $pgMin = $pgSchema.minimum
281 , $pgMax = $pgSchema.maximum;
283 {{? $pgMin !== undefined || $pgMax !== undefined }}
284 var {{=$valid}} = true;
286 {{ var $currErrSchemaPath = $errSchemaPath; }}
288 {{? $pgMin !== undefined }}
289 {{ var $limit = $pgMin, $reason = 'minimum', $moreOrLess = 'less'; }}
290 {{=$valid}} = pgPropCount{{=$lvl}} >= {{=$pgMin}};
291 {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/minimum'; }}
292 {{# def.checkError:'patternGroups' }}
293 {{? $pgMax !== undefined }}
298 {{? $pgMax !== undefined }}
299 {{ var $limit = $pgMax, $reason = 'maximum', $moreOrLess = 'more'; }}
300 {{=$valid}} = pgPropCount{{=$lvl}} <= {{=$pgMax}};
301 {{ $errSchemaPath = it.errSchemaPath + '/patternGroups/maximum'; }}
302 {{# def.checkError:'patternGroups' }}
305 {{ $errSchemaPath = $currErrSchemaPath; }}
309 {{?}} {{ /* def.nonEmptySchema */ }}
315 {{= $closingBraces }}
316 if ({{=$errs}} == errors) {