Customize error messages (e.g. for translations) #971
Labels
Enhancement
Some new desired functionality
Error Reporting
Issues related to clearer or more robust validation error reporting
Hi,
I would need to translate the error messages and it happens to be more complicated than I expected (or than it could be, I believe).
I started using information on
ValidationError
s to define custom messages, but all relevant information for the message is not always readily available. Found this related issue #564 but with not much follow-up so I thought I could ask again.For instance, for an "additionalProperties" keyword, looking at the code shows that there is some logic that needs to be reimplemented to make message translations (using internal
_utils.find_additional_properties
to find the offending properties, two different messages depending on whetherproperties
orpatternProperties
is used etc.).In addition to the overhead this introduces, I am afraid that it may drift out of sync with the logic in this package in case of improvements, bug fixes, or new draft support etc. or that internal functions may change without backward compatibility.
I am wondering if it would be possible to not hard-code messages, but use templates instead (e.g. Jinja2), that have access to error-specific contextual data (e.g. offending properties for "additionalProperties" errors), and that could be changed for a translation without touching at the logic. This is for instance the approach taken by xeipuuv/gojsonschema.
I think it would be worth a try, and I would be willing to contribute on this with a little help, if you think it is a good idea.
The text was updated successfully, but these errors were encountered: