'use strict'; module.exports = function generate_anyOf(it, $keyword, $ruleType) { var out = ' '; var $lvl = it.level; var $dataLvl = it.dataLevel; var $schema = it.schema[$keyword]; var $schemaPath = it.schemaPath + it.util.getProperty($keyword); var $errSchemaPath = it.errSchemaPath + '/' + $keyword; var $breakOnError = !it.opts.allErrors; var $data = 'data' + ($dataLvl || ''); var $valid = 'valid' + $lvl; var $errs = 'errs__' + $lvl; var $it = it.util.copy(it); var $closingBraces = ''; $it.level++; var $nextValid = 'valid' + $it.level; var $noEmptySchema = $schema.every(function($sch) { return it.util.schemaHasRules($sch, it.RULES.all); }); if ($noEmptySchema) { var $currentBaseId = $it.baseId; out += ' var ' + ($errs) + ' = errors; var ' + ($valid) + ' = false; '; var $wasComposite = it.compositeRule; it.compositeRule = $it.compositeRule = true; var arr1 = $schema; if (arr1) { var $sch, $i = -1, l1 = arr1.length - 1; while ($i < l1) { $sch = arr1[$i += 1]; $it.schema = $sch; $it.schemaPath = $schemaPath + '[' + $i + ']'; $it.errSchemaPath = $errSchemaPath + '/' + $i; out += ' ' + (it.validate($it)) + ' '; $it.baseId = $currentBaseId; out += ' ' + ($valid) + ' = ' + ($valid) + ' || ' + ($nextValid) + '; if (!' + ($valid) + ') { '; $closingBraces += '}'; } } it.compositeRule = $it.compositeRule = $wasComposite; out += ' ' + ($closingBraces) + ' if (!' + ($valid) + ') { var err = '; /* istanbul ignore else */ if (it.createErrors !== false) { out += ' { keyword: \'' + ('anyOf') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} '; if (it.opts.messages !== false) { out += ' , message: \'should match some schema in anyOf\' '; } if (it.opts.verbose) { out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; } out += ' } '; } else { out += ' {} '; } out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ if (it.async) { out += ' throw new ValidationError(vErrors); '; } else { out += ' validate.errors = vErrors; return false; '; } } out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } '; if (it.opts.allErrors) { out += ' } '; } out = it.util.cleanUpCode(out); } else { if ($breakOnError) { out += ' if (true) { '; } } return out; }
Name | Type | Size | Permission | Actions |
---|---|---|---|---|
README.md | File | 149 B | 0644 |
|
_limit.js | File | 6.68 KB | 0644 |
|
_limitItems.js | File | 2.53 KB | 0644 |
|
_limitLength.js | File | 2.65 KB | 0644 |
|
_limitProperties.js | File | 2.57 KB | 0644 |
|
allOf.js | File | 1.25 KB | 0644 |
|
anyOf.js | File | 2.78 KB | 0644 |
|
const.js | File | 2.02 KB | 0644 |
|
contains.js | File | 3.21 KB | 0644 |
|
custom.js | File | 9.55 KB | 0644 |
|
dependencies.js | File | 7.42 KB | 0644 |
|
enum.js | File | 2.52 KB | 0644 |
|
format.js | File | 5.47 KB | 0644 |
|
items.js | File | 5.74 KB | 0644 |
|
multipleOf.js | File | 2.63 KB | 0644 |
|
not.js | File | 3.26 KB | 0644 |
|
oneOf.js | File | 2.74 KB | 0644 |
|
pattern.js | File | 2.52 KB | 0644 |
|
properties.js | File | 21.34 KB | 0644 |
|
propertyNames.js | File | 3.44 KB | 0644 |
|
ref.js | File | 4.57 KB | 0644 |
|
required.js | File | 11.96 KB | 0644 |
|
uniqueItems.js | File | 2.8 KB | 0644 |
|
validate.js | File | 18.04 KB | 0644 |
|