-
Notifications
You must be signed in to change notification settings - Fork 280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom error message #241
Comments
Hello, a) regarding internationalization: if you want to keep the structure of the errors but you just want to make the actual messages translated, then probably you would benefit from the The library itself won't provide direct support to i18n, because that would be followed by an unmanageable amount of library-integration & customization needs, so we are not going to do that. The approach is that the library gives programmer-friendly error description which can be turned by the caller into a human-readable form, if necessary. b) I'm a bit confused about what you mean by "ignoring additional keywords". Can you please elaborate? Thanks. |
Hello, Thank you for your response. For example I tried adding to schema property "message" to use it for storing error message for this schema and expected to see this property inside exception threw during validation:
But schema contained in ValidationException didn't have property "message". Thanks. |
Other implementations when they return the violated schema they will return the whole violatedschema and even elements they do not recognize. This way you can use the violated schema to get the unique validation message. So you can do Violatedschema -> messages -> minlength for example to do custom validation errors. My solution now is to put the custom validation errors in the file I have for generating the front-end. And couple it by the path.
Depending on your needs you can also create a simpler extra structure like this:
|
This is fixed in version |
Hi,
We need to have possibility to customize validation error message in order to make it more user friendly and also to make them multilingual. After learning documentation and source code we didn't find how to do it. Can you add example into documentation or develop this feature or explain if there is a workaround.
Or can you explain if it is possible to switch off ignoring of additional keywords in schema (in this extended keyword we could keep our custom error messages):
"Implementations MAY define additional keywords to JSON Schema. Save for explicit agreement, schema authors SHALL NOT expect these additional keywords to be supported by peer implementations. Implementations SHOULD ignore keywords they do not support."?
Thank you so much for your library!
The text was updated successfully, but these errors were encountered: