Initial commit
[yaffs-website] / node_modules / ajv / lib / dotjs / anyOf.js
1 'use strict';
2 module.exports = function generate_anyOf(it, $keyword) {
3   var out = ' ';
4   var $lvl = it.level;
5   var $dataLvl = it.dataLevel;
6   var $schema = it.schema[$keyword];
7   var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
8   var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
9   var $breakOnError = !it.opts.allErrors;
10   var $errorKeyword;
11   var $data = 'data' + ($dataLvl || '');
12   var $valid = 'valid' + $lvl;
13   var $errs = 'errs__' + $lvl;
14   var $it = it.util.copy(it);
15   var $closingBraces = '';
16   $it.level++;
17   var $nextValid = 'valid' + $it.level;
18   var $noEmptySchema = $schema.every(function($sch) {
19     return it.util.schemaHasRules($sch, it.RULES.all);
20   });
21   if ($noEmptySchema) {
22     var $currentBaseId = $it.baseId;
23     out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false;  ';
24     var $wasComposite = it.compositeRule;
25     it.compositeRule = $it.compositeRule = true;
26     var arr1 = $schema;
27     if (arr1) {
28       var $sch, $i = -1,
29         l1 = arr1.length - 1;
30       while ($i < l1) {
31         $sch = arr1[$i += 1];
32         $it.schema = $sch;
33         $it.schemaPath = $schemaPath + '[' + $i + ']';
34         $it.errSchemaPath = $errSchemaPath + '/' + $i;
35         out += '  ' + (it.validate($it)) + ' ';
36         $it.baseId = $currentBaseId;
37         out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { ';
38         $closingBraces += '}';
39       }
40     }
41     it.compositeRule = $it.compositeRule = $wasComposite;
42     out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') {  var err =   '; /* istanbul ignore else */
43     if (it.createErrors !== false) {
44       out += ' { keyword: \'' + ($errorKeyword || 'anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
45       if (it.opts.messages !== false) {
46         out += ' , message: \'should match some schema in anyOf\' ';
47       }
48       if (it.opts.verbose) {
49         out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
50       }
51       out += ' } ';
52     } else {
53       out += ' {} ';
54     }
55     out += ';  if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else {  errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
56     if (it.opts.allErrors) {
57       out += ' } ';
58     }
59     out = it.util.cleanUpCode(out);
60   } else {
61     if ($breakOnError) {
62       out += ' if (true) { ';
63     }
64   }
65   return out;
66 }