'use strict'; module.exports = function generate__limitItems(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 $errorKeyword; var $data = 'data' + ($dataLvl || ''); var $isData = it.opts.$data && $schema && $schema.$data, $schemaValue; if ($isData) { out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; '; $schemaValue = 'schema' + $lvl; } else { $schemaValue = $schema; } var $op = $keyword == 'maxItems' ? '>' : '<'; out += 'if ( '; if ($isData) { out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || '; } out += ' ' + ($data) + '.length ' + ($op) + ' ' + ($schemaValue) + ') { '; var $errorKeyword = $keyword; var $$outStack = $$outStack || []; $$outStack.push(out); out = ''; /* istanbul ignore else */ if (it.createErrors !== false) { out += ' { keyword: \'' + ($errorKeyword || '_limitItems') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } '; if (it.opts.messages !== false) { out += ' , message: \'should NOT have '; if ($keyword == 'maxItems') { out += 'more'; } else { out += 'less'; } out += ' than '; if ($isData) { out += '\' + ' + ($schemaValue) + ' + \''; } else { out += '' + ($schema); } out += ' items\' '; } if (it.opts.verbose) { out += ' , schema: '; if ($isData) { out += 'validate.schema' + ($schemaPath); } else { out += '' + ($schema); } out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' '; } out += ' } '; } else { out += ' {} '; } var __err = out; out = $$outStack.pop(); if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */ if (it.async) { out += ' throw new ValidationError([' + (__err) + ']); '; } else { out += ' validate.errors = [' + (__err) + ']; return false; '; } } else { out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; '; } out += '} '; if ($breakOnError) { out += ' else { '; } 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 |
|