Skip to content

Commit

Permalink
rjsf-team#838 return schemaPath in transformErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
epicfaace committed Jan 20, 2019
1 parent 7b87c82 commit 285d15b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ function transformAjvErrors(errors = []) {
}

return errors.map(e => {
const { dataPath, keyword, message, params } = e;
const { dataPath, keyword, message, params, schemaPath } = e;
let property = `${dataPath}`;

// put data in expected format
Expand All @@ -139,6 +139,7 @@ function transformAjvErrors(errors = []) {
message,
params, // specific to ajv
stack: `${property} ${message}`.trim(),
schemaPath,
};
});
}
Expand Down
4 changes: 4 additions & 0 deletions test/validate_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ describe("Validation", () => {
expect(errors).to.have.length.of(1);
expect(errors[0].name).eql("type");
expect(errors[0].property).eql(".properties['foo'].required");
expect(errors[0].schemaPath).eql("#/properties/foo/required");
expect(errors[0].message).eql("should be array");
});

Expand Down Expand Up @@ -319,6 +320,9 @@ describe("Validation", () => {

it("should validate a minLength field", () => {
expect(comp.state.errors).to.have.length.of(1);
expect(comp.state.errors[0].schemaPath).eql(
"#/properties/foo/minLength"
);
expect(comp.state.errors[0].message).eql(
"should NOT be shorter than 10 characters"
);
Expand Down

0 comments on commit 285d15b

Please sign in to comment.