Customize error messages (e.g. for translations)
Maintainers usually reply within 6 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
Research direction
Start with the ValidationError documentation and the additionalProperties handling in jsonschema/_validators.py, including its use of _utils.find_additional_properties. Review related issue #564 and the existing error context to determine the scope of a configurable message mechanism. Done should be a reviewed design with a clear way to support translated, error-specific messages without duplicating validator logic.
Written by the indexing model from the issue text.
Description
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 ValidationErrors 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 whether properties or patternProperties 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.
- Dominant language
- Python
- Stars
- 5k
- Forks
- 741
- Avg merge
- 4d 17h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from python-jsonschema/jsonschema
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
python-jsonschema/jsonschema#1610 · 1 comment ·
Maintainers usually reply within 6 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
python-jsonschema/jsonschema#1588 · 2 comments ·
Maintainers usually reply within 6 days
-
Iterator error contexts lose parent links and absolute pathsMay be free again @DawnofGenX claimed this 59 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
python-jsonschema/jsonschema#1584 · 3 comments ·
Maintainers usually reply within 6 days
-
regex format checker crashes with RecursionError on deeply nested patternsPossibly taken @DawnofGenX claimed this 59 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-jsonschema/jsonschema#1538 · 1 comment ·
Maintainers usually reply within 6 days
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentMay be free again A pull request for this issue was closed without being merged. OpenNeeds Test Upstream
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
python-jsonschema/jsonschema#1511 · 1 comment ·
Maintainers usually reply within 6 days
All issues in python-jsonschema/jsonschema
Similar issues
-
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
web-push-libs/pywebpush#216 · 1 comment ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AgriciDaniel/claude-seo#572 ·
Maintainers usually reply within 5 days
-
area:print-dispatch
Difficulty 2/5 1-3 hours Newbie friendliness 92/100
Maintainers usually reply within 1 day
-
area: docs domain: technical-writing good first issue type: documentation
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Deepak3699/Ai_Mentor#919 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day