1 |
|
2 |
|
3 |
|
4 | const self = {}
|
5 |
|
6 | 'use strict';
|
7 | var validate = (function() {
|
8 | var refVal = [];
|
9 | return function validate(data, dataPath, parentData, parentDataProperty, rootData) {
|
10 | 'use strict';
|
11 | var vErrors = null;
|
12 | var errors = 0;
|
13 | if (rootData === undefined) rootData = data;
|
14 | if ((data && typeof data === "object" && !Array.isArray(data))) {
|
15 | if (data.bodyLimit === undefined) data.bodyLimit = 1048576;
|
16 | if (data.caseSensitive === undefined) data.caseSensitive = true;
|
17 | if (data.ignoreTrailingSlash === undefined) data.ignoreTrailingSlash = false;
|
18 | if (data.maxParamLength === undefined) data.maxParamLength = 100;
|
19 | if (data.onProtoPoisoning === undefined) data.onProtoPoisoning = "error";
|
20 | if (data.pluginTimeout === undefined) data.pluginTimeout = 10000;
|
21 | if (data.requestIdHeader === undefined) data.requestIdHeader = "request-id";
|
22 | if (data.requestIdLogLabel === undefined) data.requestIdLogLabel = "reqId";
|
23 | var errs__0 = errors;
|
24 | var valid1 = true;
|
25 | for (var key0 in data) {
|
26 | var isAdditional0 = !(false || validate.schema.properties.hasOwnProperty(key0));
|
27 | if (isAdditional0) {
|
28 | delete data[key0];
|
29 | }
|
30 | }
|
31 | if (valid1) {
|
32 | var data1 = data.bodyLimit;
|
33 | var errs_1 = errors;
|
34 | if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
|
35 | var dataType1 = typeof data1;
|
36 | var coerced1 = undefined;
|
37 | if (dataType1 == 'boolean' || data1 === null || (dataType1 == 'string' && data1 && data1 == +data1 && !(data1 % 1))) coerced1 = +data1;
|
38 | if (coerced1 === undefined) {
|
39 | validate.errors = [{
|
40 | keyword: 'type',
|
41 | dataPath: (dataPath || '') + '.bodyLimit',
|
42 | schemaPath: '#/properties/bodyLimit/type',
|
43 | params: {
|
44 | type: 'integer'
|
45 | },
|
46 | message: 'should be integer'
|
47 | }];
|
48 | return false;
|
49 | } else {
|
50 | data1 = coerced1;
|
51 | data['bodyLimit'] = coerced1;
|
52 | }
|
53 | }
|
54 | var valid1 = errors === errs_1;
|
55 | if (valid1) {
|
56 | var data1 = data.caseSensitive;
|
57 | var errs_1 = errors;
|
58 | if (typeof data1 !== "boolean") {
|
59 | var dataType1 = typeof data1;
|
60 | var coerced1 = undefined;
|
61 | if (data1 === 'false' || data1 === 0 || data1 === null) coerced1 = false;
|
62 | else if (data1 === 'true' || data1 === 1) coerced1 = true;
|
63 | if (coerced1 === undefined) {
|
64 | validate.errors = [{
|
65 | keyword: 'type',
|
66 | dataPath: (dataPath || '') + '.caseSensitive',
|
67 | schemaPath: '#/properties/caseSensitive/type',
|
68 | params: {
|
69 | type: 'boolean'
|
70 | },
|
71 | message: 'should be boolean'
|
72 | }];
|
73 | return false;
|
74 | } else {
|
75 | data1 = coerced1;
|
76 | data['caseSensitive'] = coerced1;
|
77 | }
|
78 | }
|
79 | var valid1 = errors === errs_1;
|
80 | if (valid1) {
|
81 | var data1 = data.http2;
|
82 | if (data1 === undefined) {
|
83 | valid1 = true;
|
84 | } else {
|
85 | var errs_1 = errors;
|
86 | if (typeof data1 !== "boolean") {
|
87 | var dataType1 = typeof data1;
|
88 | var coerced1 = undefined;
|
89 | if (data1 === 'false' || data1 === 0 || data1 === null) coerced1 = false;
|
90 | else if (data1 === 'true' || data1 === 1) coerced1 = true;
|
91 | if (coerced1 === undefined) {
|
92 | validate.errors = [{
|
93 | keyword: 'type',
|
94 | dataPath: (dataPath || '') + '.http2',
|
95 | schemaPath: '#/properties/http2/type',
|
96 | params: {
|
97 | type: 'boolean'
|
98 | },
|
99 | message: 'should be boolean'
|
100 | }];
|
101 | return false;
|
102 | } else {
|
103 | data1 = coerced1;
|
104 | data['http2'] = coerced1;
|
105 | }
|
106 | }
|
107 | var valid1 = errors === errs_1;
|
108 | }
|
109 | if (valid1) {
|
110 | var data1 = data.https;
|
111 | if (data1 === undefined) {
|
112 | valid1 = true;
|
113 | } else {
|
114 | var errs_1 = errors;
|
115 | var errs__1 = errors;
|
116 | var valid1 = true;
|
117 | var errs_2 = errors;
|
118 | var errs__2 = errors;
|
119 | var errs_3 = errors;
|
120 | var errs__3 = errors,
|
121 | prevValid3 = false,
|
122 | valid3 = false,
|
123 | passingSchemas3 = null;
|
124 | var errs_4 = errors;
|
125 | if (typeof data1 !== "boolean") {
|
126 | var dataType4 = typeof data1;
|
127 | var coerced4 = undefined;
|
128 | if (data1 === 'false' || data1 === 0 || data1 === null) coerced4 = false;
|
129 | else if (data1 === 'true' || data1 === 1) coerced4 = true;
|
130 | if (coerced4 === undefined) {
|
131 | var err = {};
|
132 | if (vErrors === null) vErrors = [err];
|
133 | else vErrors.push(err);
|
134 | errors++;
|
135 | } else {
|
136 | data1 = coerced4;
|
137 | data['https'] = coerced4;
|
138 | }
|
139 | }
|
140 | var valid4 = errors === errs_4;
|
141 | if (valid4) {
|
142 | valid3 = prevValid3 = true;
|
143 | passingSchemas3 = 0;
|
144 | }
|
145 | var errs_4 = errors;
|
146 | if (data1 !== null) {
|
147 | var dataType4 = typeof data1;
|
148 | var coerced4 = undefined;
|
149 | if (data1 === '' || data1 === 0 || data1 === false) coerced4 = null;
|
150 | if (coerced4 === undefined) {
|
151 | var err = {};
|
152 | if (vErrors === null) vErrors = [err];
|
153 | else vErrors.push(err);
|
154 | errors++;
|
155 | } else {
|
156 | data1 = coerced4;
|
157 | data['https'] = coerced4;
|
158 | }
|
159 | }
|
160 | var valid4 = errors === errs_4;
|
161 | if (valid4 && prevValid3) {
|
162 | valid3 = false;
|
163 | passingSchemas3 = [passingSchemas3, 1];
|
164 | } else {
|
165 | if (valid4) {
|
166 | valid3 = prevValid3 = true;
|
167 | passingSchemas3 = 1;
|
168 | }
|
169 | var errs_4 = errors;
|
170 | if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) {
|
171 | if (true) {
|
172 | var errs__4 = errors;
|
173 | var valid5 = true;
|
174 | for (var key4 in data1) {
|
175 | var isAdditional4 = !(false || key4 == 'allowHTTP1');
|
176 | if (isAdditional4) {
|
177 | delete data1[key4];
|
178 | }
|
179 | }
|
180 | if (valid5) {
|
181 | var data2 = data1.allowHTTP1;
|
182 | if (data2 === undefined) {
|
183 | valid5 = false;
|
184 | var err = {};
|
185 | if (vErrors === null) vErrors = [err];
|
186 | else vErrors.push(err);
|
187 | errors++;
|
188 | } else {
|
189 | var errs_5 = errors;
|
190 | if (typeof data2 !== "boolean") {
|
191 | var dataType5 = typeof data2;
|
192 | var coerced5 = undefined;
|
193 | if (data2 === 'false' || data2 === 0 || data2 === null) coerced5 = false;
|
194 | else if (data2 === 'true' || data2 === 1) coerced5 = true;
|
195 | if (coerced5 === undefined) {
|
196 | var err = {};
|
197 | if (vErrors === null) vErrors = [err];
|
198 | else vErrors.push(err);
|
199 | errors++;
|
200 | } else {
|
201 | data2 = coerced5;
|
202 | data1['allowHTTP1'] = coerced5;
|
203 | }
|
204 | }
|
205 | var valid5 = errors === errs_5;
|
206 | }
|
207 | }
|
208 | }
|
209 | } else {
|
210 | var err = {};
|
211 | if (vErrors === null) vErrors = [err];
|
212 | else vErrors.push(err);
|
213 | errors++;
|
214 | }
|
215 | var valid4 = errors === errs_4;
|
216 | if (valid4 && prevValid3) {
|
217 | valid3 = false;
|
218 | passingSchemas3 = [passingSchemas3, 2];
|
219 | } else {
|
220 | if (valid4) {
|
221 | valid3 = prevValid3 = true;
|
222 | passingSchemas3 = 2;
|
223 | }
|
224 | }
|
225 | }
|
226 | if (!valid3) {
|
227 | var err = {};
|
228 | if (vErrors === null) vErrors = [err];
|
229 | else vErrors.push(err);
|
230 | errors++;
|
231 | } else {
|
232 | errors = errs__3;
|
233 | if (vErrors !== null) {
|
234 | if (errs__3) vErrors.length = errs__3;
|
235 | else vErrors = null;
|
236 | }
|
237 | }
|
238 | var valid3 = errors === errs_3;
|
239 | if (valid3) {
|
240 | var err = {};
|
241 | if (vErrors === null) vErrors = [err];
|
242 | else vErrors.push(err);
|
243 | errors++;
|
244 | } else {
|
245 | errors = errs__2;
|
246 | if (vErrors !== null) {
|
247 | if (errs__2) vErrors.length = errs__2;
|
248 | else vErrors = null;
|
249 | }
|
250 | }
|
251 | var valid2 = errors === errs_2;
|
252 | errors = errs__1;
|
253 | if (vErrors !== null) {
|
254 | if (errs__1) vErrors.length = errs__1;
|
255 | else vErrors = null;
|
256 | }
|
257 | if (valid2) {
|
258 | var errs_2 = errors;
|
259 | customRule0.errors = null;
|
260 | var errs__2 = errors;
|
261 | var valid2;
|
262 | valid2 = customRule0.call(self, validate.schema.properties.https.then.setDefaultValue, data1, validate.schema.properties.https.then, (dataPath || '') + '.https', data, 'https', rootData);
|
263 | if (data) data1 = data['https'];
|
264 | if (!valid2) {
|
265 | validate.errors = [{
|
266 | keyword: 'setDefaultValue',
|
267 | dataPath: (dataPath || '') + '.https',
|
268 | schemaPath: '#/properties/https/then/setDefaultValue',
|
269 | params: {
|
270 | keyword: 'setDefaultValue'
|
271 | },
|
272 | message: 'should pass "setDefaultValue" keyword validation'
|
273 | }];
|
274 | return false;
|
275 | }
|
276 | var valid2 = errors === errs_2;
|
277 | valid1 = valid2;
|
278 | }
|
279 | if (!valid1) {
|
280 | var err = {
|
281 | keyword: 'if',
|
282 | dataPath: (dataPath || '') + '.https',
|
283 | schemaPath: '#/properties/https/if',
|
284 | params: {
|
285 | failingKeyword: 'then'
|
286 | },
|
287 | message: 'should match "' + 'then' + '" schema'
|
288 | };
|
289 | if (vErrors === null) vErrors = [err];
|
290 | else vErrors.push(err);
|
291 | errors++;
|
292 | validate.errors = vErrors;
|
293 | return false;
|
294 | }
|
295 | var valid1 = errors === errs_1;
|
296 | }
|
297 | if (valid1) {
|
298 | var data1 = data.ignoreTrailingSlash;
|
299 | var errs_1 = errors;
|
300 | if (typeof data1 !== "boolean") {
|
301 | var dataType1 = typeof data1;
|
302 | var coerced1 = undefined;
|
303 | if (data1 === 'false' || data1 === 0 || data1 === null) coerced1 = false;
|
304 | else if (data1 === 'true' || data1 === 1) coerced1 = true;
|
305 | if (coerced1 === undefined) {
|
306 | validate.errors = [{
|
307 | keyword: 'type',
|
308 | dataPath: (dataPath || '') + '.ignoreTrailingSlash',
|
309 | schemaPath: '#/properties/ignoreTrailingSlash/type',
|
310 | params: {
|
311 | type: 'boolean'
|
312 | },
|
313 | message: 'should be boolean'
|
314 | }];
|
315 | return false;
|
316 | } else {
|
317 | data1 = coerced1;
|
318 | data['ignoreTrailingSlash'] = coerced1;
|
319 | }
|
320 | }
|
321 | var valid1 = errors === errs_1;
|
322 | if (valid1) {
|
323 | var data1 = data.maxParamLength;
|
324 | var errs_1 = errors;
|
325 | if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
|
326 | var dataType1 = typeof data1;
|
327 | var coerced1 = undefined;
|
328 | if (dataType1 == 'boolean' || data1 === null || (dataType1 == 'string' && data1 && data1 == +data1 && !(data1 % 1))) coerced1 = +data1;
|
329 | if (coerced1 === undefined) {
|
330 | validate.errors = [{
|
331 | keyword: 'type',
|
332 | dataPath: (dataPath || '') + '.maxParamLength',
|
333 | schemaPath: '#/properties/maxParamLength/type',
|
334 | params: {
|
335 | type: 'integer'
|
336 | },
|
337 | message: 'should be integer'
|
338 | }];
|
339 | return false;
|
340 | } else {
|
341 | data1 = coerced1;
|
342 | data['maxParamLength'] = coerced1;
|
343 | }
|
344 | }
|
345 | var valid1 = errors === errs_1;
|
346 | if (valid1) {
|
347 | var data1 = data.onProtoPoisoning;
|
348 | var errs_1 = errors;
|
349 | if (typeof data1 !== "string") {
|
350 | var dataType1 = typeof data1;
|
351 | var coerced1 = undefined;
|
352 | if (dataType1 == 'number' || dataType1 == 'boolean') coerced1 = '' + data1;
|
353 | else if (data1 === null) coerced1 = '';
|
354 | if (coerced1 === undefined) {
|
355 | validate.errors = [{
|
356 | keyword: 'type',
|
357 | dataPath: (dataPath || '') + '.onProtoPoisoning',
|
358 | schemaPath: '#/properties/onProtoPoisoning/type',
|
359 | params: {
|
360 | type: 'string'
|
361 | },
|
362 | message: 'should be string'
|
363 | }];
|
364 | return false;
|
365 | } else {
|
366 | data1 = coerced1;
|
367 | data['onProtoPoisoning'] = coerced1;
|
368 | }
|
369 | }
|
370 | var valid1 = errors === errs_1;
|
371 | if (valid1) {
|
372 | var data1 = data.pluginTimeout;
|
373 | var errs_1 = errors;
|
374 | if ((typeof data1 !== "number" || (data1 % 1) || data1 !== data1)) {
|
375 | var dataType1 = typeof data1;
|
376 | var coerced1 = undefined;
|
377 | if (dataType1 == 'boolean' || data1 === null || (dataType1 == 'string' && data1 && data1 == +data1 && !(data1 % 1))) coerced1 = +data1;
|
378 | if (coerced1 === undefined) {
|
379 | validate.errors = [{
|
380 | keyword: 'type',
|
381 | dataPath: (dataPath || '') + '.pluginTimeout',
|
382 | schemaPath: '#/properties/pluginTimeout/type',
|
383 | params: {
|
384 | type: 'integer'
|
385 | },
|
386 | message: 'should be integer'
|
387 | }];
|
388 | return false;
|
389 | } else {
|
390 | data1 = coerced1;
|
391 | data['pluginTimeout'] = coerced1;
|
392 | }
|
393 | }
|
394 | var valid1 = errors === errs_1;
|
395 | if (valid1) {
|
396 | var data1 = data.requestIdHeader;
|
397 | var errs_1 = errors;
|
398 | if (typeof data1 !== "string") {
|
399 | var dataType1 = typeof data1;
|
400 | var coerced1 = undefined;
|
401 | if (dataType1 == 'number' || dataType1 == 'boolean') coerced1 = '' + data1;
|
402 | else if (data1 === null) coerced1 = '';
|
403 | if (coerced1 === undefined) {
|
404 | validate.errors = [{
|
405 | keyword: 'type',
|
406 | dataPath: (dataPath || '') + '.requestIdHeader',
|
407 | schemaPath: '#/properties/requestIdHeader/type',
|
408 | params: {
|
409 | type: 'string'
|
410 | },
|
411 | message: 'should be string'
|
412 | }];
|
413 | return false;
|
414 | } else {
|
415 | data1 = coerced1;
|
416 | data['requestIdHeader'] = coerced1;
|
417 | }
|
418 | }
|
419 | var valid1 = errors === errs_1;
|
420 | if (valid1) {
|
421 | var data1 = data.requestIdLogLabel;
|
422 | var errs_1 = errors;
|
423 | if (typeof data1 !== "string") {
|
424 | var dataType1 = typeof data1;
|
425 | var coerced1 = undefined;
|
426 | if (dataType1 == 'number' || dataType1 == 'boolean') coerced1 = '' + data1;
|
427 | else if (data1 === null) coerced1 = '';
|
428 | if (coerced1 === undefined) {
|
429 | validate.errors = [{
|
430 | keyword: 'type',
|
431 | dataPath: (dataPath || '') + '.requestIdLogLabel',
|
432 | schemaPath: '#/properties/requestIdLogLabel/type',
|
433 | params: {
|
434 | type: 'string'
|
435 | },
|
436 | message: 'should be string'
|
437 | }];
|
438 | return false;
|
439 | } else {
|
440 | data1 = coerced1;
|
441 | data['requestIdLogLabel'] = coerced1;
|
442 | }
|
443 | }
|
444 | var valid1 = errors === errs_1;
|
445 | }
|
446 | }
|
447 | }
|
448 | }
|
449 | }
|
450 | }
|
451 | }
|
452 | }
|
453 | }
|
454 | }
|
455 | } else {
|
456 | validate.errors = [{
|
457 | keyword: 'type',
|
458 | dataPath: (dataPath || '') + "",
|
459 | schemaPath: '#/type',
|
460 | params: {
|
461 | type: 'object'
|
462 | },
|
463 | message: 'should be object'
|
464 | }];
|
465 | return false;
|
466 | }
|
467 | validate.errors = vErrors;
|
468 | return errors === 0;
|
469 | };
|
470 | })();
|
471 | validate.schema = {
|
472 | "type": "object",
|
473 | "additionalProperties": false,
|
474 | "properties": {
|
475 | "bodyLimit": {
|
476 | "type": "integer",
|
477 | "default": 1048576
|
478 | },
|
479 | "caseSensitive": {
|
480 | "type": "boolean",
|
481 | "default": true
|
482 | },
|
483 | "http2": {
|
484 | "type": "boolean"
|
485 | },
|
486 | "https": {
|
487 | "if": {
|
488 | "not": {
|
489 | "oneOf": [{
|
490 | "type": "boolean"
|
491 | }, {
|
492 | "type": "null"
|
493 | }, {
|
494 | "type": "object",
|
495 | "additionalProperties": false,
|
496 | "required": ["allowHTTP1"],
|
497 | "properties": {
|
498 | "allowHTTP1": {
|
499 | "type": "boolean"
|
500 | }
|
501 | }
|
502 | }]
|
503 | }
|
504 | },
|
505 | "then": {
|
506 | "setDefaultValue": true
|
507 | }
|
508 | },
|
509 | "ignoreTrailingSlash": {
|
510 | "type": "boolean",
|
511 | "default": false
|
512 | },
|
513 | "maxParamLength": {
|
514 | "type": "integer",
|
515 | "default": 100
|
516 | },
|
517 | "onProtoPoisoning": {
|
518 | "type": "string",
|
519 | "default": "error"
|
520 | },
|
521 | "pluginTimeout": {
|
522 | "type": "integer",
|
523 | "default": 10000
|
524 | },
|
525 | "requestIdHeader": {
|
526 | "type": "string",
|
527 | "default": "request-id"
|
528 | },
|
529 | "requestIdLogLabel": {
|
530 | "type": "string",
|
531 | "default": "reqId"
|
532 | }
|
533 | }
|
534 | };
|
535 | validate.errors = null;
|
536 | module.exports = validate;
|
537 |
|
538 | function customRule0 (schemaParamValue, validatedParamValue, validationSchemaObject, currentDataPath, validatedParamObject, validatedParam) {
|
539 | validatedParamObject[validatedParam] = schemaParamValue
|
540 | return true
|
541 | }
|
542 |
|
543 | module.exports.defaultInitOptions = {"bodyLimit":1048576,"caseSensitive":true,"ignoreTrailingSlash":false,"maxParamLength":100,"onProtoPoisoning":"error","pluginTimeout":10000,"requestIdHeader":"request-id","requestIdLogLabel":"reqId"}
|