5

Im using OpenAPI 3.0.1, and use components that have type/value validations. (i.e. type/enum/range).

When I access the relevant paths with wrong type/values, I get a default message which isn't human readable, such as:

"message": "request body has an error: doesn't match the schema: Error at <fieldName>: Doesn't match schema \"oneOf\"".

Instead I'd like to create a custom error message for each component, i.e.:

invalid argument: <fieldName>.
  • What library/framework do you use on the server side to validate the requests? – Helen Jul 15 '21 at 10:59
  • I use ngnix framework – user9131181 Jul 15 '21 at 14:49
  • nginx is an HTTP server. I mean your programming language and API framework/library, e.g. Java + Springfox, or .NET + Swashbuckle, or Node.js + express-openapi, or similar. – Helen Jul 15 '21 at 15:11
  • Oh, I use loopback4 (npm one). And write in golang. – user9131181 Jul 15 '21 at 22:53
  • Does this help? [LoopBack 4 - Customize validation errors](https://loopback.io/doc/en/lb4/Validation-REST-layer.html#customize-validation-errors) – Helen Jul 16 '21 at 07:44
  • thanks but not that much. For validating the schema I use e.Use(middleware.OapiRequestValidator(swagger)). Is there a way to update the yamls' components themselves with the relevant error message I would like to output? – user9131181 Jul 18 '21 at 08:23
  • Validation is done by middleware so any error messages would be changed at the middleware level. Check the documentation for your `OapiRequestValidator` and see what customization options it provides. – Helen Jul 19 '21 at 06:32

0 Answers0