diff options
Diffstat (limited to 'tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js')
-rw-r--r-- | tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js | 78 |
1 files changed, 57 insertions, 21 deletions
diff --git a/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js b/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js index 8dd7c83e32..286dc92a24 100644 --- a/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js +++ b/tools/node_modules/eslint/node_modules/ajv/dist/ajv.bundle.js @@ -989,7 +989,7 @@ module.exports = function rules() { var ALL = [ 'type', '$comment' ]; var KEYWORDS = [ - '$schema', '$id', 'id', '$data', 'title', + '$schema', '$id', 'id', '$data', '$async', 'title', 'description', 'default', 'definitions', 'examples', 'readOnly', 'writeOnly', 'contentMediaType', 'contentEncoding', @@ -1087,6 +1087,7 @@ module.exports = { finalCleanUpCode: finalCleanUpCode, schemaHasRules: schemaHasRules, schemaHasRulesExcept: schemaHasRulesExcept, + schemaUnknownRules: schemaUnknownRules, toQuotedString: toQuotedString, getPathExpr: getPathExpr, getPath: getPath, @@ -1253,6 +1254,12 @@ function schemaHasRulesExcept(schema, rules, exceptKeyword) { } +function schemaUnknownRules(schema, rules) { + if (typeof schema == 'boolean') return; + for (var key in schema) if (!rules[key]) return key; +} + + function toQuotedString(str) { return '\'' + escapeQuotes(str) + '\''; } @@ -4197,6 +4204,14 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { var $async = it.schema.$async === true, $refKeywords = it.util.schemaHasRulesExcept(it.schema, it.RULES.all, '$ref'), $id = it.self._getId(it.schema); + if (it.opts.strictKeywords) { + var $unknownKwd = it.util.schemaUnknownRules(it.schema, it.RULES.keywords); + if ($unknownKwd) { + var $keywordsMsg = 'unknown keyword: ' + $unknownKwd; + if (it.opts.strictKeywords === 'log') it.logger.warn($keywordsMsg); + else throw new Error($keywordsMsg); + } + } if (it.isTop) { out += ' var validate = '; if ($async) { @@ -4277,6 +4292,11 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { it.baseId = it.baseId || it.rootId; delete it.isTop; it.dataPathArr = [undefined]; + if (it.schema.default !== undefined && it.opts.useDefaults && it.opts.strictDefaults) { + var $defaultMsg = 'default is ignored in the schema root'; + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg); + else throw new Error($defaultMsg); + } out += ' var vErrors = null; '; out += ' var errors = 0; '; out += ' if (rootData === undefined) rootData = data; '; @@ -4484,7 +4504,7 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { if ($rulesGroup.type) { out += ' if (' + (it.util.checkDataType($rulesGroup.type, $data)) + ') { '; } - if (it.opts.useDefaults && !it.compositeRule) { + if (it.opts.useDefaults) { if ($rulesGroup.type == 'object' && it.schema.properties) { var $schema = it.schema.properties, $schemaKeys = Object.keys($schema); @@ -4497,17 +4517,25 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { var $sch = $schema[$propertyKey]; if ($sch.default !== undefined) { var $passData = $data + it.util.getProperty($propertyKey); - out += ' if (' + ($passData) + ' === undefined '; - if (it.opts.useDefaults == 'empty') { - out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' '; - } - out += ' ) ' + ($passData) + ' = '; - if (it.opts.useDefaults == 'shared') { - out += ' ' + (it.useDefault($sch.default)) + ' '; + if (it.compositeRule) { + if (it.opts.strictDefaults) { + var $defaultMsg = 'default is ignored for: ' + $passData; + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg); + else throw new Error($defaultMsg); + } } else { - out += ' ' + (JSON.stringify($sch.default)) + ' '; + out += ' if (' + ($passData) + ' === undefined '; + if (it.opts.useDefaults == 'empty') { + out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' '; + } + out += ' ) ' + ($passData) + ' = '; + if (it.opts.useDefaults == 'shared') { + out += ' ' + (it.useDefault($sch.default)) + ' '; + } else { + out += ' ' + (JSON.stringify($sch.default)) + ' '; + } + out += '; '; } - out += '; '; } } } @@ -4520,17 +4548,25 @@ module.exports = function generate_validate(it, $keyword, $ruleType) { $sch = arr4[$i += 1]; if ($sch.default !== undefined) { var $passData = $data + '[' + $i + ']'; - out += ' if (' + ($passData) + ' === undefined '; - if (it.opts.useDefaults == 'empty') { - out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' '; - } - out += ' ) ' + ($passData) + ' = '; - if (it.opts.useDefaults == 'shared') { - out += ' ' + (it.useDefault($sch.default)) + ' '; + if (it.compositeRule) { + if (it.opts.strictDefaults) { + var $defaultMsg = 'default is ignored for: ' + $passData; + if (it.opts.strictDefaults === 'log') it.logger.warn($defaultMsg); + else throw new Error($defaultMsg); + } } else { - out += ' ' + (JSON.stringify($sch.default)) + ' '; + out += ' if (' + ($passData) + ' === undefined '; + if (it.opts.useDefaults == 'empty') { + out += ' || ' + ($passData) + ' === null || ' + ($passData) + ' === \'\' '; + } + out += ' ) ' + ($passData) + ' = '; + if (it.opts.useDefaults == 'shared') { + out += ' ' + (it.useDefault($sch.default)) + ' '; + } else { + out += ' ' + (JSON.stringify($sch.default)) + ' '; + } + out += '; '; } - out += '; '; } } } @@ -6668,7 +6704,7 @@ Ajv.$dataMetaSchema = $dataMetaSchema; var META_SCHEMA_ID = 'http://json-schema.org/draft-07/schema'; -var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes' ]; +var META_IGNORE_OPTIONS = [ 'removeAdditional', 'useDefaults', 'coerceTypes', 'strictDefaults' ]; var META_SUPPORT_DATA = ['/properties']; /** |