Skip to content

Commit

Permalink
specialized error message generation for additionalProperties and enu…
Browse files Browse the repository at this point in the history
…m keyword validation failures
  • Loading branch information
rolando-ebi committed Aug 22, 2018
1 parent 6aaf169 commit 6d42992
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/model/error-report.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,21 @@ class ErrorReport {
if(this.absoluteDataPath === "") {
this.absoluteDataPath = "root of document";
}
this.userFriendlyMessage = this.message + " at " + this.absoluteDataPath;
// depending on the schema keyword that caused the validation error, may need to parse the AJV error obj differently
if(this.ajvError) {
const keyword = this.ajvError["keyword"];
if(keyword === "additionalProperties") {
const additionalProperty = this.ajvError["params"]["additionalProperty"];
this.userFriendlyMessage = "Found disallowed additional property " + additionalProperty + " at " + this.absoluteDataPath;
} else if(keyword === "enum") {
const allowedValues = this.ajvError["params"]["allowedValues"];
this.userFriendlyMessage = this.absoluteDataPath + " " + this.message + ": " + "[" + allowedValues + "]";
} else {
this.userFriendlyMessage = this.message + " at " + this.absoluteDataPath;
}
} else {
this.userFriendlyMessage = this.message + " at " + this.absoluteDataPath;
}
}
}

Expand Down

0 comments on commit 6d42992

Please sign in to comment.