Skip to content

Commit

Permalink
Merge 8126b69 into c1c0ba7
Browse files Browse the repository at this point in the history
  • Loading branch information
nassiharel committed Feb 19, 2020
2 parents c1c0ba7 + 8126b69 commit 9f26a7d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -1079,7 +1079,7 @@ __Please note__: schemas compiled before the keyword is removed will continue to

Returns the text with all errors in a String.

Options can have properties `separator` (string used to separate errors, ", " by default) and `dataVar` (the variable name that dataPaths are prefixed with, "data" by default).
Options can have properties `separator` (string used to separate errors, ", " by default) `dataVar` (the variable name that dataPaths are prefixed with, "data" by default) and `extraInfo` (should the error message be more detailed).


## Options
Expand Down
14 changes: 12 additions & 2 deletions lib/ajv.js
Expand Up @@ -404,7 +404,7 @@ function _get$IdOrId(schema) {
* Convert array of error message objects to string
* @this Ajv
* @param {Array<Object>} errors optional array of validation errors, if not passed errors from the instance are used.
* @param {Object} options optional options with properties `separator` and `dataVar`.
* @param {Object} options optional options with properties `separator`, `dataVar` and `extraInfo`.
* @return {String} human readable string with all errors descriptions
*/
function errorsText(errors, options) {
Expand All @@ -413,11 +413,21 @@ function errorsText(errors, options) {
options = options || {};
var separator = options.separator === undefined ? ', ' : options.separator;
var dataVar = options.dataVar === undefined ? 'data' : options.dataVar;
var extraInfo = options.extraInfo === true;

var text = '';
var extraText = '';
for (var i=0; i<errors.length; i++) {
var e = errors[i];
if (e) text += dataVar + e.dataPath + ' ' + e.message + separator;
if (e) {
if(extraInfo) {
if (e.params && e.params.allowedValues)
extraText += ' (' + e.params.allowedValues.join(',') + ')';
else if (e.params && e.params.additionalProperty)
extraText += ' (' + e.params.additionalProperty + ')';
}
text += dataVar + e.dataPath + ' ' + e.message + extraText + separator;
}
}
return text.slice(0, -separator.length);
}
Expand Down

0 comments on commit 9f26a7d

Please sign in to comment.