2 module.exports = function generate_oneOf(it, $keyword) {
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;
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 = '';
17 var $nextValid = 'valid' + $it.level;
18 out += 'var ' + ($errs) + ' = errors;var prevValid' + ($lvl) + ' = false;var ' + ($valid) + ' = false;';
19 var $currentBaseId = $it.baseId;
20 var $wasComposite = it.compositeRule;
21 it.compositeRule = $it.compositeRule = true;
28 if (it.util.schemaHasRules($sch, it.RULES.all)) {
30 $it.schemaPath = $schemaPath + '[' + $i + ']';
31 $it.errSchemaPath = $errSchemaPath + '/' + $i;
32 out += ' ' + (it.validate($it)) + ' ';
33 $it.baseId = $currentBaseId;
35 out += ' var ' + ($nextValid) + ' = true; ';
38 out += ' if (' + ($nextValid) + ' && prevValid' + ($lvl) + ') ' + ($valid) + ' = false; else { ';
39 $closingBraces += '}';
41 out += ' if (' + ($nextValid) + ') ' + ($valid) + ' = prevValid' + ($lvl) + ' = true;';
44 it.compositeRule = $it.compositeRule = $wasComposite;
45 out += '' + ($closingBraces) + 'if (!' + ($valid) + ') { ';
46 var $$outStack = $$outStack || [];
48 out = ''; /* istanbul ignore else */
49 if (it.createErrors !== false) {
50 out += ' { keyword: \'' + ($errorKeyword || 'oneOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
51 if (it.opts.messages !== false) {
52 out += ' , message: \'should match exactly one schema in oneOf\' ';
54 if (it.opts.verbose) {
55 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
62 out = $$outStack.pop();
63 if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
65 out += ' throw new ValidationError([' + (__err) + ']); ';
67 out += ' validate.errors = [' + (__err) + ']; return false; ';
70 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
72 out += '} else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; }';
73 if (it.opts.allErrors) {