Initial commit
[yaffs-website] / node_modules / ajv / lib / dot / properties.jst
1 {{# def.definitions }}
2 {{# def.errors }}
3 {{# def.setupKeyword }}
4 {{# def.setupNextLevel }}
5
6
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
13                     ? it.errorPath
14                     : it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
15     var $passData = $data + '[' + $key + ']';
16     $it.dataPathArr[$dataNxt] = $key;
17   }}
18
19   {{# def.generateSubschemaCode }}
20   {{# def.optimizeValidate }}
21 #}}
22
23
24 {{
25   var $key = 'key' + $lvl
26     , $dataNxt = $it.dataLevel = it.dataLevel + 1
27     , $nextData = 'data' + $dataNxt;
28
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;
41
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);
45
46   if (it.opts.v5) {
47     var $pgProperties = it.schema.patternGroups || {}
48       , $pgPropertyKeys = Object.keys($pgProperties);
49   }
50 }}
51
52
53 var {{=$errs}} = errors;
54 var {{=$nextValid}} = true;
55
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}}]
64           {{??}}
65             {{~ $schemaKeys:$propertyKey }}
66               || {{=$key}} == {{= it.util.toQuotedString($propertyKey) }}
67             {{~}}
68           {{?}}
69         {{?}}
70         {{? $pPropertyKeys.length }}
71           {{~ $pPropertyKeys:$pProperty:$i }}
72             || {{= it.usePattern($pProperty) }}.test({{=$key}})
73           {{~}}
74         {{?}}
75         {{? it.opts.v5 && $pgPropertyKeys && $pgPropertyKeys.length }}
76           {{~ $pgPropertyKeys:$pgProperty:$i }}
77             || {{= it.usePattern($pgProperty) }}.test({{=$key}})
78           {{~}}
79         {{?}}
80       );
81
82       if (isAdditional{{=$lvl}}) {
83     {{?}}
84     {{? $removeAdditional == 'all' }}
85       delete {{=$data}}[{{=$key}}];
86     {{??}}
87       {{
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);
92         }
93       }}
94       {{? $noAdditional }}
95         {{? $removeAdditional }}
96           delete {{=$data}}[{{=$key}}];
97         {{??}}
98           {{=$nextValid}} = false;
99           {{
100             var $currErrSchemaPath = $errSchemaPath;
101             $errSchemaPath = it.errSchemaPath + '/additionalProperties';
102           }}
103           {{# def.error:'additionalProperties' }}
104           {{ $errSchemaPath = $currErrSchemaPath; }}
105           {{? $breakOnError }} break; {{?}}
106         {{?}}
107       {{?? $additionalIsSchema }}
108         {{? $removeAdditional == 'failing' }}
109           var {{=$errs}} = errors;
110           {{# def.setCompositeRule }}
111
112           {{# def.validateAdditional }}
113
114           if (!{{=$nextValid}}) {
115             errors = {{=$errs}};
116             if (validate.errors !== null) {
117               if (errors) validate.errors.length = errors;
118               else validate.errors = null;
119             }
120             delete {{=$data}}[{{=$key}}];
121           }
122
123           {{# def.resetCompositeRule }}
124         {{??}}
125           {{# def.validateAdditional }}
126           {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
127         {{?}}
128       {{?}}
129       {{ it.errorPath = $currentErrorPath; }}
130     {{?}}
131     {{? $someProperties }}
132       }
133     {{?}}
134   }
135
136   {{# def.ifResultValid }}
137 {{?}}
138
139 {{ var $useDefaults = it.opts.useDefaults && !it.compositeRule; }}
140
141 {{? $schemaKeys.length }}
142   {{~ $schemaKeys:$propertyKey }}
143     {{ var $sch = $schema[$propertyKey]; }}
144
145     {{? {{# def.nonEmptySchema:$sch}} }}
146       {{
147         var $prop = it.util.getProperty($propertyKey)
148           , $passData = $data + $prop
149           , $hasDefault = $useDefaults && $sch.default !== undefined;
150         $it.schema = $sch;
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);
155       }}
156
157       {{# def.generateSubschemaCode }}
158
159       {{? {{# def.willOptimize }} }}
160         {{
161           $code = {{# def._optimizeValidate }};
162           var $useData = $passData;
163         }}
164       {{??}}
165         {{ var $useData = $nextData; }}
166         var {{=$nextData}} = {{=$passData}};
167       {{?}}
168
169       {{? $hasDefault }}
170         {{= $code }}
171       {{??}}
172         {{? $requiredHash && $requiredHash[$propertyKey] }}
173           if ({{=$useData}} === undefined) {
174             {{=$nextValid}} = false;
175             {{
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);
181               }
182               $errSchemaPath = it.errSchemaPath + '/required';
183             }}
184             {{# def.error:'required' }}
185             {{ $errSchemaPath = $currErrSchemaPath; }}
186             {{ it.errorPath = $currentErrorPath; }}
187           } else {
188         {{??}}
189           {{? $breakOnError }}
190             if ({{=$useData}} === undefined) {
191               {{=$nextValid}} = true;
192             } else {
193           {{??}}
194             if ({{=$useData}} !== undefined) {
195           {{?}}
196         {{?}}
197
198           {{= $code }}
199         }
200       {{?}}  {{ /* $hasDefault */ }}
201     {{?}} {{ /* def.nonEmptySchema */ }}
202
203     {{# def.ifResultValid }}
204   {{~}}
205 {{?}}
206
207 {{~ $pPropertyKeys:$pProperty }}
208   {{ var $sch = $pProperties[$pProperty]; }}
209
210   {{? {{# def.nonEmptySchema:$sch}} }}
211     {{
212       $it.schema = $sch;
213       $it.schemaPath = it.schemaPath + '.patternProperties' + it.util.getProperty($pProperty);
214       $it.errSchemaPath = it.errSchemaPath + '/patternProperties/'
215                                            + it.util.escapeFragment($pProperty);
216     }}
217
218     for (var {{=$key}} in {{=$data}}) {
219       {{# def.checkOwnProperty }}
220       if ({{= it.usePattern($pProperty) }}.test({{=$key}})) {
221         {{
222           $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
223           var $passData = $data + '[' + $key + ']';
224           $it.dataPathArr[$dataNxt] = $key;
225         }}
226
227         {{# def.generateSubschemaCode }}
228         {{# def.optimizeValidate }}
229
230         {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
231       }
232       {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
233     }
234
235     {{# def.ifResultValid }}
236   {{?}} {{ /* def.nonEmptySchema */ }}
237 {{~}}
238
239
240 {{? it.opts.v5 }}
241   {{~ $pgPropertyKeys:$pgProperty }}
242     {{
243       var $pgSchema = $pgProperties[$pgProperty]
244         , $sch = $pgSchema.schema;
245     }}
246
247     {{? {{# def.nonEmptySchema:$sch}} }}
248       {{
249         $it.schema = $sch;
250         $it.schemaPath = it.schemaPath + '.patternGroups' + it.util.getProperty($pgProperty) + '.schema';
251         $it.errSchemaPath = it.errSchemaPath + '/patternGroups/'
252                                              + it.util.escapeFragment($pgProperty)
253                                              + '/schema';
254       }}
255
256       var pgPropCount{{=$lvl}} = 0;
257
258       for (var {{=$key}} in {{=$data}}) {
259         {{# def.checkOwnProperty }}
260         if ({{= it.usePattern($pgProperty) }}.test({{=$key}})) {
261           pgPropCount{{=$lvl}}++;
262
263           {{
264             $it.errorPath = it.util.getPathExpr(it.errorPath, $key, it.opts.jsonPointers);
265             var $passData = $data + '[' + $key + ']';
266             $it.dataPathArr[$dataNxt] = $key;
267           }}
268
269           {{# def.generateSubschemaCode }}
270           {{# def.optimizeValidate }}
271
272           {{? $breakOnError }} if (!{{=$nextValid}}) break; {{?}}
273         }
274         {{? $breakOnError }} else {{=$nextValid}} = true; {{?}}
275       }
276
277       {{# def.ifResultValid }}
278
279       {{
280         var $pgMin = $pgSchema.minimum
281           , $pgMax = $pgSchema.maximum;
282       }}
283       {{? $pgMin !== undefined || $pgMax !== undefined }}
284         var {{=$valid}} = true;
285
286         {{ var $currErrSchemaPath = $errSchemaPath; }}
287
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 }}
294             else
295           {{?}}
296         {{?}}
297
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' }}
303         {{?}}
304
305         {{ $errSchemaPath = $currErrSchemaPath; }}
306
307         {{# def.ifValid }}
308       {{?}}
309     {{?}} {{ /* def.nonEmptySchema */ }}
310   {{~}}
311 {{?}}
312
313
314 {{? $breakOnError }}
315   {{= $closingBraces }}
316   if ({{=$errs}} == errors) {
317 {{?}}
318
319 {{# def.cleanUp }}