2 module.exports = function generate_not(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 $errs = 'errs__' + $lvl;
13 var $it = it.util.copy(it);
15 var $nextValid = 'valid' + $it.level;
16 if (it.util.schemaHasRules($schema, it.RULES.all)) {
18 $it.schemaPath = $schemaPath;
19 $it.errSchemaPath = $errSchemaPath;
20 out += ' var ' + ($errs) + ' = errors; ';
21 var $wasComposite = it.compositeRule;
22 it.compositeRule = $it.compositeRule = true;
23 $it.createErrors = false;
25 if ($it.opts.allErrors) {
26 $allErrorsOption = $it.opts.allErrors;
27 $it.opts.allErrors = false;
29 out += ' ' + (it.validate($it)) + ' ';
30 $it.createErrors = true;
31 if ($allErrorsOption) $it.opts.allErrors = $allErrorsOption;
32 it.compositeRule = $it.compositeRule = $wasComposite;
33 out += ' if (' + ($nextValid) + ') { ';
34 var $$outStack = $$outStack || [];
36 out = ''; /* istanbul ignore else */
37 if (it.createErrors !== false) {
38 out += ' { keyword: \'' + ($errorKeyword || 'not') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
39 if (it.opts.messages !== false) {
40 out += ' , message: \'should NOT be valid\' ';
42 if (it.opts.verbose) {
43 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
50 out = $$outStack.pop();
51 if (!it.compositeRule && $breakOnError) { /* 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: \'' + ($errorKeyword || '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) { ';