Closed nioc closed 3 years ago
I found a workaround but it is ugly... do not set beautifyErrors option on init and create a new InputValidationError with original errors and beautifyErrors option set to true.
const swaggerValidation = require('openapi-validator-middleware')
const localize = require('ajv-i18n')
(...)
// set beautifyErrors to false
swaggerValidation.init('swagger.yml', { beautifyErrors: false })
(...)
api.use((err, req, res, next) => {
localize.fr(err.errors)
// create a new InputValidationError with beautifyErrors set to true
const localizedErr = new swaggerValidation.InputValidationError(err.errors, { beautifyErrors: true })
console.log(localizedErr.errors) //-> in french
})
If there is a less ugly way to achieve it, let me know otherwise feel free to close the issue.
Thanks @nioc , that would be a nice feature to add.
feel free to submit a PR.
I close this issue since workaround is enough for me.
Hello, it is possible to set internationalized error messages like ajv-i18n combined with beautfy set to true?
I've tried to use it, but I have to choose between localized or beautified message: