Skip to content

Commit

Permalink
Merge pull request #223 from kutyepov/master
Browse files Browse the repository at this point in the history
feat(schema): formats ajv error to include property names
  • Loading branch information
seriousme authored May 12, 2021
2 parents e534cb1 + 88ba7ea commit bea04e4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ function setValidatorCompiler(instance, ajvOpts, noAdditional) {
instance.setValidatorCompiler(({ schema, method, url, httpPart }) =>
ajv.compile(schema)
);

instance.setSchemaErrorFormatter(
(errors, dataVar) => new Error(ajv.errorsText(errors, { dataVar }))
);
}

function checkParserValidators(instance, contentTypes) {
Expand Down
2 changes: 1 addition & 1 deletion test/test-petstore-example.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("/v2/pet/myPet returns Fastify validation error", t => {
(err, res) => {
t.error(err);
t.equal(res.statusCode, 400);
t.equal(res.body, '{"statusCode":400,"error":"Bad Request","message":"params must be integer"}');
t.equal(res.body, '{"statusCode":400,"error":"Bad Request","message":"params/petId must be integer"}');
}
);
});
Expand Down

0 comments on commit bea04e4

Please sign in to comment.