2 module.exports = function generate_propertyNames(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);
13 var $closingBraces = '';
15 var $nextValid = 'valid' + $it.level;
16 out += 'var ' + ($errs) + ' = errors;';
17 if ((it.opts.strictKeywords ? (typeof $schema == 'object' && Object.keys($schema).length > 0) || $schema === false : it.util.schemaHasRules($schema, it.RULES.all))) {
19 $it.schemaPath = $schemaPath;
20 $it.errSchemaPath = $errSchemaPath;
21 var $key = 'key' + $lvl,
24 $invalidName = '\' + ' + $key + ' + \'',
25 $dataNxt = $it.dataLevel = it.dataLevel + 1,
26 $nextData = 'data' + $dataNxt,
27 $dataProperties = 'dataProperties' + $lvl,
28 $ownProperties = it.opts.ownProperties,
29 $currentBaseId = it.baseId;
31 out += ' var ' + ($dataProperties) + ' = undefined; ';
34 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
36 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
38 out += ' var startErrs' + ($lvl) + ' = errors; ';
40 var $wasComposite = it.compositeRule;
41 it.compositeRule = $it.compositeRule = true;
42 var $code = it.validate($it);
43 $it.baseId = $currentBaseId;
44 if (it.util.varOccurences($code, $nextData) < 2) {
45 out += ' ' + (it.util.varReplace($code, $nextData, $passData)) + ' ';
47 out += ' var ' + ($nextData) + ' = ' + ($passData) + '; ' + ($code) + ' ';
49 it.compositeRule = $it.compositeRule = $wasComposite;
50 out += ' if (!' + ($nextValid) + ') { for (var ' + ($i) + '=startErrs' + ($lvl) + '; ' + ($i) + '<errors; ' + ($i) + '++) { vErrors[' + ($i) + '].propertyName = ' + ($key) + '; } var err = '; /* istanbul ignore else */
51 if (it.createErrors !== false) {
52 out += ' { keyword: \'' + ('propertyNames') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { propertyName: \'' + ($invalidName) + '\' } ';
53 if (it.opts.messages !== false) {
54 out += ' , message: \'property name \\\'' + ($invalidName) + '\\\' is invalid\' ';
56 if (it.opts.verbose) {
57 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
63 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
64 if (!it.compositeRule && $breakOnError) {
65 /* istanbul ignore if */
67 out += ' throw new ValidationError(vErrors); ';
69 out += ' validate.errors = vErrors; return false; ';
78 out += ' ' + ($closingBraces) + ' if (' + ($errs) + ' == errors) {';