diff --git a/index.js b/index.js index b5d166c6..d34d70c6 100644 --- a/index.js +++ b/index.js @@ -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) { diff --git a/test/test-petstore-example.js b/test/test-petstore-example.js index f645d357..0c4c545b 100644 --- a/test/test-petstore-example.js +++ b/test/test-petstore-example.js @@ -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"}'); } ); });