ajv-validator / ajv-errors

Custom error messages in JSON Schemas for Ajv validator
https://ajv.js.org
MIT License
284 stars 18 forks source link

Be able to set custom keyword for error messages #141

Open davis90 opened 3 years ago

davis90 commented 3 years ago

Hi!

Thanks for your great libraries. It's cool to work with.

Being able to define the key for the error messages could be nice.

maybe something like:

import Ajv from 'ajv'
import ajvErrors from 'ajv-errors'

let ajv = new Ajv({ allErrors: true })
ajv = ajvErrors(ajv, { keyword: "myCustomErrorMessage" })

what is your opinion about that?

thank for all!

kamsar commented 2 years ago

This would be useful with OpenAPI-based schema inputs since OpenAPI expects all custom properties to start with x-, so being able to use x-errorMessage would be nice.

If this is something the maintainers like, I could look at implementing.