json-schema: Custom error message inside JSON Schema.
The problem is that it gives generic error messages that are not relevant to me. I want to send custom message to user.
Do we have any option like this:
"properties": {
"myKey": {
"type": "string"
**"errorMessage" : "My error message"**
},
}
Thanks.
About this issue
- Original URL
- State: open
- Created 7 years ago
- Reactions: 1
- Comments: 16
v6.0.0 has already overhauled the error structure in a way that allows you to fully customise the error messages. This work was done several months ago by @shmax.
There isn’t an official 6.0.0 release yet, but for most purposes it works fairly well, so you’re welcome to use the 6.0.0-dev branch for now until we get the release out.
@ravipxm That is what the
constraintfield of the error is for.Each error has a unique name - these are defined in
JsonSchema\ConstraintError. To customise the message, use something like the following:Note that you may also wish to consider the param types - they are provided to the user as-is, and some of them will not be scalar (the internal error messages handle this within the library, but the params presented to the user are not modified).