2 module.exports = function generate__limitProperties(it, $keyword, $ruleType) {
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 $isData = it.opts.$data && $schema && $schema.$data,
15 out += ' var schema' + ($lvl) + ' = ' + (it.util.getData($schema.$data, $dataLvl, it.dataPathArr)) + '; ';
16 $schemaValue = 'schema' + $lvl;
18 $schemaValue = $schema;
20 if (!($isData || typeof $schema == 'number')) {
21 throw new Error($keyword + ' must be number');
23 var $op = $keyword == 'maxProperties' ? '>' : '<';
26 out += ' (' + ($schemaValue) + ' !== undefined && typeof ' + ($schemaValue) + ' != \'number\') || ';
28 out += ' Object.keys(' + ($data) + ').length ' + ($op) + ' ' + ($schemaValue) + ') { ';
29 var $errorKeyword = $keyword;
30 var $$outStack = $$outStack || [];
32 out = ''; /* istanbul ignore else */
33 if (it.createErrors !== false) {
34 out += ' { keyword: \'' + ($errorKeyword || '_limitProperties') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { limit: ' + ($schemaValue) + ' } ';
35 if (it.opts.messages !== false) {
36 out += ' , message: \'should NOT have ';
37 if ($keyword == 'maxProperties') {
44 out += '\' + ' + ($schemaValue) + ' + \'';
46 out += '' + ($schema);
48 out += ' properties\' ';
50 if (it.opts.verbose) {
53 out += 'validate.schema' + ($schemaPath);
55 out += '' + ($schema);
57 out += ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
64 out = $$outStack.pop();
65 if (!it.compositeRule && $breakOnError) {
66 /* istanbul ignore if */
68 out += ' throw new ValidationError([' + (__err) + ']); ';
70 out += ' validate.errors = [' + (__err) + ']; return false; ';
73 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';