Custom Error Messages for Schema Failures #147
Labels
enhancement
New feature or request
status: help wanted
This issue is tentatively accepted pending a volunteer committed to its implementation
Environment
It would be great to have the option of custom error messages for schema failures and not just custom validation failures. For example when using the pattern keyword in a schema the error message returned contains the regular expression used which for some users may not be that helpful (if they are not familiar with regex for example). Instead having the option to define a custom error message in the schema itself for a property would be great.
Proposed Functionality
Currently a user can construct a schema using the pattern keyword and a regular expression:
If a value is supplied that does not match the regular expression, the error message returned is:
However if a key was introduced to define a custom message for this property, the schema could look like this:
Schema Enforcer could then return the message as such:
Use Case
A good example would be a regex for an FQDN as descried above. Regex can be long and complicated and overwhelming to a user who is not familiar with its syntax. Instead a custom error message that refers the user to documentation would be a good way to encourage best practice and good docs.
EDIT: I'm aware that a custom validator could be written to do the regex check and return the custom error message however the added overhead could be avoided by introducing this feature.
It seems to be a fairly common requirement and the following Stack Overflow link contains one example of how this was implemented: https://stackoverflow.com/questions/25902635/python-jsonschema-package-to-validate-schema-and-custom-error-messages
The text was updated successfully, but these errors were encountered: