2 module.exports = function generate_patternRequired(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 $valid = 'valid' + $lvl;
12 var $key = 'key' + $lvl,
14 $matched = 'patternMatched' + $lvl,
15 $dataProperties = 'dataProperties' + $lvl,
17 $ownProperties = it.opts.ownProperties;
18 out += 'var ' + ($valid) + ' = true;';
20 out += ' var ' + ($dataProperties) + ' = undefined;';
24 var $pProperty, i1 = -1,
27 $pProperty = arr1[i1 += 1];
28 out += ' var ' + ($matched) + ' = false; ';
30 out += ' ' + ($dataProperties) + ' = ' + ($dataProperties) + ' || Object.keys(' + ($data) + '); for (var ' + ($idx) + '=0; ' + ($idx) + '<' + ($dataProperties) + '.length; ' + ($idx) + '++) { var ' + ($key) + ' = ' + ($dataProperties) + '[' + ($idx) + ']; ';
32 out += ' for (var ' + ($key) + ' in ' + ($data) + ') { ';
34 out += ' ' + ($matched) + ' = ' + (it.usePattern($pProperty)) + '.test(' + ($key) + '); if (' + ($matched) + ') break; } ';
35 var $missingPattern = it.util.escapeQuotes($pProperty);
36 out += ' if (!' + ($matched) + ') { ' + ($valid) + ' = false; var err = '; /* istanbul ignore else */
37 if (it.createErrors !== false) {
38 out += ' { keyword: \'' + ('patternRequired') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { missingPattern: \'' + ($missingPattern) + '\' } ';
39 if (it.opts.messages !== false) {
40 out += ' , message: \'should have property matching pattern \\\'' + ($missingPattern) + '\\\'\' ';
42 if (it.opts.verbose) {
43 out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
49 out += '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } ';
51 $closingBraces += '}';
56 out += '' + ($closingBraces);