summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js
diff options
context:
space:
mode:
authorMyles Borins <myles.borins@gmail.com>2017-10-26 22:35:25 -0400
committerMyles Borins <myles.borins@gmail.com>2017-10-29 21:32:15 -0400
commitace4fe566fc3af4876c7458f983feeb5eae3df26 (patch)
tree458d847e9bd56199cd0d8b34cec126c7410fb6ca /deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js
parent64168eb9b43e30e4c0b986c9b29c41be63e85df6 (diff)
downloadandroid-node-v8-ace4fe566fc3af4876c7458f983feeb5eae3df26.tar.gz
android-node-v8-ace4fe566fc3af4876c7458f983feeb5eae3df26.tar.bz2
android-node-v8-ace4fe566fc3af4876c7458f983feeb5eae3df26.zip
deps: update npm to 5.5.1
Closes: https://github.com/nodejs/node/pull/16280 PR-URL: https://github.com/nodejs/node/pull/16509 Fixes: https://github.com/nodejs/node/issues/14161 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Diffstat (limited to 'deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js')
-rw-r--r--deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js391
1 files changed, 237 insertions, 154 deletions
diff --git a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js
index 0c4112e1d4..0ff9eda426 100644
--- a/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js
+++ b/deps/npm/node_modules/request/node_modules/har-validator/node_modules/ajv/lib/dotjs/validate.js
@@ -1,27 +1,21 @@
'use strict';
-module.exports = function generate_validate(it, $keyword) {
+module.exports = function generate_validate(it, $keyword, $ruleType) {
var out = '';
- var $async = it.schema.$async === true;
+ var $async = it.schema.$async === true,
+ $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'),
+ $id = it.self._getId(it.schema);
if (it.isTop) {
- var $top = it.isTop,
- $lvl = it.level = 0,
- $dataLvl = it.dataLevel = 0,
- $data = 'data';
- it.rootId = it.resolve.fullPath(it.root.schema.id);
- it.baseId = it.baseId || it.rootId;
if ($async) {
it.async = true;
var $es7 = it.opts.async == 'es7';
it.yieldAwait = $es7 ? 'await' : 'yield';
}
- delete it.isTop;
- it.dataPathArr = [undefined];
out += ' var validate = ';
if ($async) {
if ($es7) {
out += ' (async function ';
} else {
- if (it.opts.async == 'co*') {
+ if (it.opts.async != '*') {
out += 'co.wrap';
}
out += '(function* ';
@@ -29,14 +23,87 @@ module.exports = function generate_validate(it, $keyword) {
} else {
out += ' (function ';
}
- out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; var vErrors = null; ';
+ out += ' (data, dataPath, parentData, parentDataProperty, rootData) { \'use strict\'; ';
+ if ($id && (it.opts.sourceCode || it.opts.processCode)) {
+ out += ' ' + ('/\*# sourceURL=' + $id + ' */') + ' ';
+ }
+ }
+ if (typeof it.schema == 'boolean' || !($refKeywords || it.schema.$ref)) {
+ var $keyword = 'false schema';
+ var $lvl = it.level;
+ var $dataLvl = it.dataLevel;
+ var $schema = it.schema[$keyword];
+ var $schemaPath = it.schemaPath + it.util.getProperty($keyword);
+ var $errSchemaPath = it.errSchemaPath + '/' + $keyword;
+ var $breakOnError = !it.opts.allErrors;
+ var $errorKeyword;
+ var $data = 'data' + ($dataLvl || '');
+ var $valid = 'valid' + $lvl;
+ if (it.schema === false) {
+ if (it.isTop) {
+ $breakOnError = true;
+ } else {
+ out += ' var ' + ($valid) + ' = false; ';
+ }
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'false schema') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: {} ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'boolean schema is false\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: false , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
+ }
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
+ } else {
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
+ }
+ } else {
+ if (it.isTop) {
+ if ($async) {
+ out += ' return data; ';
+ } else {
+ out += ' validate.errors = null; return true; ';
+ }
+ } else {
+ out += ' var ' + ($valid) + ' = true; ';
+ }
+ }
+ if (it.isTop) {
+ out += ' }); return validate; ';
+ }
+ return out;
+ }
+ if (it.isTop) {
+ var $top = it.isTop,
+ $lvl = it.level = 0,
+ $dataLvl = it.dataLevel = 0,
+ $data = 'data';
+ it.rootId = it.resolve.fullPath(it.self._getId(it.root.schema));
+ it.baseId = it.baseId || it.rootId;
+ delete it.isTop;
+ it.dataPathArr = [undefined];
+ out += ' var vErrors = null; ';
out += ' var errors = 0; ';
- out += ' if (rootData === undefined) rootData = data;';
+ out += ' if (rootData === undefined) rootData = data; ';
} else {
var $lvl = it.level,
$dataLvl = it.dataLevel,
$data = 'data' + ($dataLvl || '');
- if (it.schema.id) it.baseId = it.resolve.url(it.baseId, it.schema.id);
+ if ($id) it.baseId = it.resolve.url(it.baseId, $id);
if ($async && !it.async) throw new Error('async schema in sync schema');
out += ' var errs_' + ($lvl) + ' = errors;';
}
@@ -44,111 +111,160 @@ module.exports = function generate_validate(it, $keyword) {
$breakOnError = !it.opts.allErrors,
$closingBraces1 = '',
$closingBraces2 = '';
+ var $errorKeyword;
var $typeSchema = it.schema.type,
$typeIsArray = Array.isArray($typeSchema);
- if ($typeSchema && it.opts.coerceTypes) {
- var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
- if ($coerceToTypes) {
+ if ($typeIsArray && $typeSchema.length == 1) {
+ $typeSchema = $typeSchema[0];
+ $typeIsArray = false;
+ }
+ if (it.schema.$ref && $refKeywords) {
+ if (it.opts.extendRefs == 'fail') {
+ throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '" (see option extendRefs)');
+ } else if (it.opts.extendRefs !== true) {
+ $refKeywords = false;
+ console.warn('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
+ }
+ }
+ if ($typeSchema) {
+ if (it.opts.coerceTypes) {
+ var $coerceToTypes = it.util.coerceToTypes(it.opts.coerceTypes, $typeSchema);
+ }
+ var $rulesGroup = it.RULES.types[$typeSchema];
+ if ($coerceToTypes || $typeIsArray || $rulesGroup === true || ($rulesGroup && !$shouldUseGroup($rulesGroup))) {
+ var $schemaPath = it.schemaPath + '.type',
+ $errSchemaPath = it.errSchemaPath + '/type';
var $schemaPath = it.schemaPath + '.type',
$errSchemaPath = it.errSchemaPath + '/type',
$method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
- out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
- var $dataType = 'dataType' + $lvl,
- $coerced = 'coerced' + $lvl;
- out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; ';
- if (it.opts.coerceTypes == 'array') {
- out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; ';
- }
- out += ' var ' + ($coerced) + ' = undefined; ';
- var $bracesCoercion = '';
- var arr1 = $coerceToTypes;
- if (arr1) {
- var $type, $i = -1,
- l1 = arr1.length - 1;
- while ($i < l1) {
- $type = arr1[$i += 1];
- if ($i) {
- out += ' if (' + ($coerced) + ' === undefined) { ';
- $bracesCoercion += '}';
+ out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
+ if ($coerceToTypes) {
+ var $dataType = 'dataType' + $lvl,
+ $coerced = 'coerced' + $lvl;
+ out += ' var ' + ($dataType) + ' = typeof ' + ($data) + '; ';
+ if (it.opts.coerceTypes == 'array') {
+ out += ' if (' + ($dataType) + ' == \'object\' && Array.isArray(' + ($data) + ')) ' + ($dataType) + ' = \'array\'; ';
+ }
+ out += ' var ' + ($coerced) + ' = undefined; ';
+ var $bracesCoercion = '';
+ var arr1 = $coerceToTypes;
+ if (arr1) {
+ var $type, $i = -1,
+ l1 = arr1.length - 1;
+ while ($i < l1) {
+ $type = arr1[$i += 1];
+ if ($i) {
+ out += ' if (' + ($coerced) + ' === undefined) { ';
+ $bracesCoercion += '}';
+ }
+ if (it.opts.coerceTypes == 'array' && $type != 'array') {
+ out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } ';
+ }
+ if ($type == 'string') {
+ out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
+ } else if ($type == 'number' || $type == 'integer') {
+ out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
+ if ($type == 'integer') {
+ out += ' && !(' + ($data) + ' % 1)';
+ }
+ out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
+ } else if ($type == 'boolean') {
+ out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
+ } else if ($type == 'null') {
+ out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
+ } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
+ out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
+ }
}
- if (it.opts.coerceTypes == 'array' && $type != 'array') {
- out += ' if (' + ($dataType) + ' == \'array\' && ' + ($data) + '.length == 1) { ' + ($coerced) + ' = ' + ($data) + ' = ' + ($data) + '[0]; ' + ($dataType) + ' = typeof ' + ($data) + '; } ';
+ }
+ out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
}
- if ($type == 'string') {
- out += ' if (' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\') ' + ($coerced) + ' = \'\' + ' + ($data) + '; else if (' + ($data) + ' === null) ' + ($coerced) + ' = \'\'; ';
- } else if ($type == 'number' || $type == 'integer') {
- out += ' if (' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' === null || (' + ($dataType) + ' == \'string\' && ' + ($data) + ' && ' + ($data) + ' == +' + ($data) + ' ';
- if ($type == 'integer') {
- out += ' && !(' + ($data) + ' % 1)';
+ out += '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
}
- out += ')) ' + ($coerced) + ' = +' + ($data) + '; ';
- } else if ($type == 'boolean') {
- out += ' if (' + ($data) + ' === \'false\' || ' + ($data) + ' === 0 || ' + ($data) + ' === null) ' + ($coerced) + ' = false; else if (' + ($data) + ' === \'true\' || ' + ($data) + ' === 1) ' + ($coerced) + ' = true; ';
- } else if ($type == 'null') {
- out += ' if (' + ($data) + ' === \'\' || ' + ($data) + ' === 0 || ' + ($data) + ' === false) ' + ($coerced) + ' = null; ';
- } else if (it.opts.coerceTypes == 'array' && $type == 'array') {
- out += ' if (' + ($dataType) + ' == \'string\' || ' + ($dataType) + ' == \'number\' || ' + ($dataType) + ' == \'boolean\' || ' + ($data) + ' == null) ' + ($coerced) + ' = [' + ($data) + ']; ';
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
}
+ out += ' } ';
+ } else {
+ out += ' {} ';
}
- }
- out += ' ' + ($bracesCoercion) + ' if (' + ($coerced) + ' === undefined) { ';
- var $$outStack = $$outStack || [];
- $$outStack.push(out);
- out = ''; /* istanbul ignore else */
- if (it.createErrors !== false) {
- out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
- if ($typeIsArray) {
- out += '' + ($typeSchema.join(","));
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
} else {
- out += '' + ($typeSchema);
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
- out += '\' } ';
- if (it.opts.messages !== false) {
- out += ' , message: \'should be ';
+ out += ' } else { ';
+ var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
+ $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
+ out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
+ if (!$dataLvl) {
+ out += 'if (' + ($parentData) + ' !== undefined)';
+ }
+ out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } ';
+ } else {
+ var $$outStack = $$outStack || [];
+ $$outStack.push(out);
+ out = ''; /* istanbul ignore else */
+ if (it.createErrors !== false) {
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
if ($typeIsArray) {
out += '' + ($typeSchema.join(","));
} else {
out += '' + ($typeSchema);
}
- out += '\' ';
- }
- if (it.opts.verbose) {
- out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ out += '\' } ';
+ if (it.opts.messages !== false) {
+ out += ' , message: \'should be ';
+ if ($typeIsArray) {
+ out += '' + ($typeSchema.join(","));
+ } else {
+ out += '' + ($typeSchema);
+ }
+ out += '\' ';
+ }
+ if (it.opts.verbose) {
+ out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
+ }
+ out += ' } ';
+ } else {
+ out += ' {} ';
}
- out += ' } ';
- } else {
- out += ' {} ';
- }
- var __err = out;
- out = $$outStack.pop();
- if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
- if (it.async) {
- out += ' throw new ValidationError([' + (__err) + ']); ';
+ var __err = out;
+ out = $$outStack.pop();
+ if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
+ if (it.async) {
+ out += ' throw new ValidationError([' + (__err) + ']); ';
+ } else {
+ out += ' validate.errors = [' + (__err) + ']; return false; ';
+ }
} else {
- out += ' validate.errors = [' + (__err) + ']; return false; ';
+ out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
- } else {
- out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
}
- out += ' } else { ';
- var $parentData = $dataLvl ? 'data' + (($dataLvl - 1) || '') : 'parentData',
- $parentDataProperty = $dataLvl ? it.dataPathArr[$dataLvl] : 'parentDataProperty';
- out += ' ' + ($data) + ' = ' + ($coerced) + '; ';
- if (!$dataLvl) {
- out += 'if (' + ($parentData) + ' !== undefined)';
- }
- out += ' ' + ($parentData) + '[' + ($parentDataProperty) + '] = ' + ($coerced) + '; } } ';
- }
- }
- var $refKeywords;
- if (it.schema.$ref && ($refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'))) {
- if (it.opts.extendRefs == 'fail') {
- throw new Error('$ref: validation keywords used in schema at path "' + it.errSchemaPath + '"');
- } else if (it.opts.extendRefs == 'ignore') {
- $refKeywords = false;
- console.log('$ref: keywords ignored in schema at path "' + it.errSchemaPath + '"');
- } else if (it.opts.extendRefs !== true) {
- console.log('$ref: all keywords used in schema at path "' + it.errSchemaPath + '". It will change in the next major version, see issue #260. Use option { extendRefs: true } to keep current behaviour');
+ out += ' } ';
}
}
if (it.schema.$ref && !$refKeywords) {
@@ -164,6 +280,9 @@ module.exports = function generate_validate(it, $keyword) {
$closingBraces2 += '}';
}
} else {
+ if (it.opts.v5 && it.schema.patternGroups) {
+ console.warn('keyword "patternGroups" is deprecated and disabled. Use option patternGroups: true to enable.');
+ }
var arr2 = it.RULES;
if (arr2) {
var $rulesGroup, i2 = -1,
@@ -225,9 +344,12 @@ module.exports = function generate_validate(it, $keyword) {
while (i5 < l5) {
$rule = arr5[i5 += 1];
if ($shouldUseRule($rule)) {
- out += ' ' + ($rule.code(it, $rule.keyword)) + ' ';
- if ($breakOnError) {
- $closingBraces1 += '}';
+ var $code = $rule.code(it, $rule.keyword, $rulesGroup.type);
+ if ($code) {
+ out += ' ' + ($code) + ' ';
+ if ($breakOnError) {
+ $closingBraces1 += '}';
+ }
}
}
}
@@ -239,7 +361,6 @@ module.exports = function generate_validate(it, $keyword) {
if ($rulesGroup.type) {
out += ' } ';
if ($typeSchema && $typeSchema === $rulesGroup.type && !$coerceToTypes) {
- var $typeChecked = true;
out += ' else { ';
var $schemaPath = it.schemaPath + '.type',
$errSchemaPath = it.errSchemaPath + '/type';
@@ -247,7 +368,7 @@ module.exports = function generate_validate(it, $keyword) {
$$outStack.push(out);
out = ''; /* istanbul ignore else */
if (it.createErrors !== false) {
- out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
+ out += ' { keyword: \'' + ($errorKeyword || 'type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
if ($typeIsArray) {
out += '' + ($typeSchema.join(","));
} else {
@@ -298,57 +419,12 @@ module.exports = function generate_validate(it, $keyword) {
}
}
}
- if ($typeSchema && !$typeChecked && !$coerceToTypes) {
- var $schemaPath = it.schemaPath + '.type',
- $errSchemaPath = it.errSchemaPath + '/type',
- $method = $typeIsArray ? 'checkDataTypes' : 'checkDataType';
- out += ' if (' + (it.util[$method]($typeSchema, $data, true)) + ') { ';
- var $$outStack = $$outStack || [];
- $$outStack.push(out);
- out = ''; /* istanbul ignore else */
- if (it.createErrors !== false) {
- out += ' { keyword: \'' + ('type') + '\' , dataPath: (dataPath || \'\') + ' + (it.errorPath) + ' , schemaPath: ' + (it.util.toQuotedString($errSchemaPath)) + ' , params: { type: \'';
- if ($typeIsArray) {
- out += '' + ($typeSchema.join(","));
- } else {
- out += '' + ($typeSchema);
- }
- out += '\' } ';
- if (it.opts.messages !== false) {
- out += ' , message: \'should be ';
- if ($typeIsArray) {
- out += '' + ($typeSchema.join(","));
- } else {
- out += '' + ($typeSchema);
- }
- out += '\' ';
- }
- if (it.opts.verbose) {
- out += ' , schema: validate.schema' + ($schemaPath) + ' , parentSchema: validate.schema' + (it.schemaPath) + ' , data: ' + ($data) + ' ';
- }
- out += ' } ';
- } else {
- out += ' {} ';
- }
- var __err = out;
- out = $$outStack.pop();
- if (!it.compositeRule && $breakOnError) { /* istanbul ignore if */
- if (it.async) {
- out += ' throw new ValidationError([' + (__err) + ']); ';
- } else {
- out += ' validate.errors = [' + (__err) + ']; return false; ';
- }
- } else {
- out += ' var err = ' + (__err) + '; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; ';
- }
- out += ' }';
- }
if ($breakOnError) {
out += ' ' + ($closingBraces2) + ' ';
}
if ($top) {
if ($async) {
- out += ' if (errors === 0) return true; ';
+ out += ' if (errors === 0) return data; ';
out += ' else throw new ValidationError(vErrors); ';
} else {
out += ' validate.errors = vErrors; ';
@@ -359,17 +435,24 @@ module.exports = function generate_validate(it, $keyword) {
out += ' var ' + ($valid) + ' = errors === errs_' + ($lvl) + ';';
}
out = it.util.cleanUpCode(out);
- if ($top && $breakOnError) {
- out = it.util.cleanUpVarErrors(out, $async);
+ if ($top) {
+ out = it.util.finalCleanUpCode(out, $async);
}
function $shouldUseGroup($rulesGroup) {
- for (var i = 0; i < $rulesGroup.rules.length; i++)
- if ($shouldUseRule($rulesGroup.rules[i])) return true;
+ var rules = $rulesGroup.rules;
+ for (var i = 0; i < rules.length; i++)
+ if ($shouldUseRule(rules[i])) return true;
}
function $shouldUseRule($rule) {
- return it.schema[$rule.keyword] !== undefined || ($rule.keyword == 'properties' && (it.schema.additionalProperties === false || typeof it.schema.additionalProperties == 'object' || (it.schema.patternProperties && Object.keys(it.schema.patternProperties).length) || (it.opts.v5 && it.schema.patternGroups && Object.keys(it.schema.patternGroups).length)));
+ return it.schema[$rule.keyword] !== undefined || ($rule.implements && $ruleImlementsSomeKeyword($rule));
+ }
+
+ function $ruleImlementsSomeKeyword($rule) {
+ var impl = $rule.implements;
+ for (var i = 0; i < impl.length; i++)
+ if (it.schema[impl[i]] !== undefined) return true;
}
return out;
}