diff options
Diffstat (limited to 'node_modules/ajv/lib/dotjs/ref.js')
-rw-r--r-- | node_modules/ajv/lib/dotjs/ref.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/node_modules/ajv/lib/dotjs/ref.js b/node_modules/ajv/lib/dotjs/ref.js index e07c70c3b..6fb950546 100644 --- a/node_modules/ajv/lib/dotjs/ref.js +++ b/node_modules/ajv/lib/dotjs/ref.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function generate_ref(it, $keyword) { +module.exports = function generate_ref(it, $keyword, $ruleType) { var out = ' '; var $lvl = it.level; var $dataLvl = it.dataLevel; @@ -20,9 +20,9 @@ module.exports = function generate_ref(it, $keyword) { } else { var $refVal = it.resolveRef(it.baseId, $schema, it.isRoot); if ($refVal === undefined) { - var $message = 'can\'t resolve reference ' + $schema + ' from id ' + it.baseId; + var $message = it.MissingRefError.message(it.baseId, $schema); if (it.opts.missingRefs == 'fail') { - console.log($message); + console.error($message); var $$outStack = $$outStack || []; $$outStack.push(out); out = ''; /* istanbul ignore else */ @@ -53,15 +53,12 @@ module.exports = function generate_ref(it, $keyword) { out += ' if (false) { '; } } else if (it.opts.missingRefs == 'ignore') { - console.log($message); + console.warn($message); if ($breakOnError) { out += ' if (true) { '; } } else { - var $error = new Error($message); - $error.missingRef = it.resolve.url(it.baseId, $schema); - $error.missingSchema = it.resolve.normalizeId(it.resolve.fullPath($error.missingRef)); - throw $error; + throw new it.MissingRefError(it.baseId, $schema, $message); } } else if ($refVal.inline) { var $it = it.util.copy(it); @@ -100,11 +97,18 @@ module.exports = function generate_ref(it, $keyword) { out = $$outStack.pop(); if ($async) { if (!it.async) throw new Error('async schema referenced by sync schema'); - out += ' try { '; if ($breakOnError) { - out += 'var ' + ($valid) + ' ='; + out += ' var ' + ($valid) + '; '; } - out += ' ' + (it.yieldAwait) + ' ' + (__callValidate) + '; } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; } '; + out += ' try { ' + (it.yieldAwait) + ' ' + (__callValidate) + '; '; + if ($breakOnError) { + out += ' ' + ($valid) + ' = true; '; + } + out += ' } catch (e) { if (!(e instanceof ValidationError)) throw e; if (vErrors === null) vErrors = e.errors; else vErrors = vErrors.concat(e.errors); errors = vErrors.length; '; + if ($breakOnError) { + out += ' ' + ($valid) + ' = false; '; + } + out += ' } '; if ($breakOnError) { out += ' if (' + ($valid) + ') { '; } |