kin-openapi icon indicating copy to clipboard operation
kin-openapi copied to clipboard

openapi3filter.RequestError message customize

Open mpasokolov opened this issue 4 years ago • 3 comments

Hello everyone.

Can you help me. Can i change default message in error.

Example: "parameter "id" in query has an error: number must be most 1"

mpasokolov avatar Dec 18 '21 09:12 mpasokolov

Is this what you meant? https://github.com/getkin/kin-openapi/pull/466

fenollp avatar Dec 18 '21 12:12 fenollp

Thank you for answer, but i mean i want return other message. For example: as is: "parameter "id" in query has an error: number must be most 1" to be: "incorrect value"(for example, real message will be in russian).

mpasokolov avatar Dec 18 '21 12:12 mpasokolov

I see. There have been similar inquiries I think for the purpose of rewriting the error message and also to generally uniquely identify the returned error.

I see a few ways of going at this:

  1. using some i18n library and language files, so users could define their own file or use the default (today's) one
  2. define unique string types for each schema/filter error format so users can type-switch on them. Or export all format strings used in schema error reasons and create a function that finds the format string from the error's reason
  3. Do something similar to https://github.com/getkin/kin-openapi/blob/f13ef7f1c13bf20978f006d7002d0ea96c03cc14/openapi3filter/validation_error_encoder.go

A generic way of identifying / matching schema error messages would be useful to many users of this lib and so I am interested in helping move this forward.

Today error messages are not stabilized meaning the format string can change completely from one release to another. Especially considering the eventual rewrite of the data validation part: https://github.com/getkin/kin-openapi/pull/412

To me the first option in this list would be the more robust one, especially if there's a way of knowing whether a file's entry is missing or is unused.

fenollp avatar Dec 18 '21 13:12 fenollp