2 module.exports = function generate_not(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;
10 var $data = 'data' + ($dataLvl || '');
11 var $errs = 'errs__' + $lvl;
12 var $it = it.util.copy(it);
14 var $nextValid = 'valid' + $it.level;
15 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
17 $it.schemaPath = $schemaPath;
18 $it.errSchemaPath = $errSchemaPath;
19 out += ' var ' + ($errs) + ' = errors; ';
20 var $wasComposite = it.compositeRule;
21 it.compositeRule = $it.compositeRule = true;
22 $it.createErrors = false;
24 if ($it.opts.allErrors) {
25 $allErrorsOption = $it.opts.allErrors;
26 $it.opts.allErrors = false;
28 out += ' ' + (it.validate($it)) + ' ';
29 $it.createErrors = true;
30 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
31 it.compositeRule = $it.compositeRule = $wasComposite;
32 out += ' if (' + ($nextValid) + ') { ';
33 var $$outStack = $$outStack || [];
35 out = ''; /* istanbul ignore else */
36 if (it.createErrors !== false) {
37 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
38 if (it.opts.messages !== false) {
39 out += ' , message: \'should NOT be valid\' ';
41 if (it.opts.verbose) {
42 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
49 out = $$outStack.pop();
50 if (!it.compositeRule && $breakOnError) {
51 /* istanbul ignore if */
53 out += ' throw new ValidationError([' + (__err) + ']); ';
55 out += ' validate.errors = [' + (__err) + ']; return false; ';
58 out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
60 out += ' } else { errors = ' + ($errs) + '; if (vErrors !== null) { if (' + ($errs) + ') vErrors.length = ' + ($errs) + '; else vErrors = null; } ';
61 if (it.opts.allErrors) {
65 out += ' var err = '; /* istanbul ignore else */
66 if (it.createErrors !== false) {
67 out += ' { keyword: \'' + ('not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
68 if (it.opts.messages !== false) {
69 out += ' , message: \'should NOT be valid\' ';
71 if (it.opts.verbose) {
72 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
78 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
80 out += ' if (false) { ';