Skip to content
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

Ensure extended validators can create keywords which override exception messages #1134

Open
ppaslan opened this issue Jul 18, 2023 · 1 comment
Labels
Dialects v2 Issues which will likely be addressed as part of reworked dialect support Enhancement Some new desired functionality

Comments

@ppaslan
Copy link

ppaslan commented Jul 18, 2023

Hi, first of all, thanks for all your work with this package.

All in all i think it works great and really does what it should and is supposed to do.
I think that if i should mention anything that i think could be better it would probably be better error messages, now i do understand that it is really hard to generate good error messages for all use cases but something that could be very useful is the option to add custom error messages.

Here is an example.

{
    "type": "object",
    "properties": {
        "templates": {
            "type": "object",
            "properties": {
                   "path": {"type": "string", "minLength": 1, "pattern": "^(/[^/]+)+$", "message": {"pattern": "You must use a valid full path with no trailing slashes"}}},
            "required": ["path"],
        },
    },
    "required": ["templates"],
}

I've read the documentation and haven't been able to find a way to define custom messages in the schema, but maybe i have missed something?

@Julian
Copy link
Member

Julian commented Jul 18, 2023

Thanks for the kind words, much appreciated.

Essentially this library implements the JSON Schema specification, and there exists no such keyword... yet!

But you can yourself invent one (in something called a "vocabulary"), and then add support for it to this library using the extension APIs (jsonschema.validators.extend) though I'm not sure the extension API is rich enough to allow you to change messages that come from other validators.

I'd say I do not want to expand the scope of this library beyond the specifications, but I do want to help create an ecosystem of such packages on top of this package such that folks can implement vocabularies and keywords that do all sorts of things beyond the spec.

So I can leave this open, but I don't plan on implementing such a vocabulary internally here, so I'll likely close as soon as I either confirm or implement being able to do this in a vocabulary on top of this library, but I definitely encourage you to consider writing such a package at that time, as this isn't an uncommon request and I certainly respect it's useful. Feel free to ask questions or otherwise follow-up.

@Julian Julian added the Enhancement Some new desired functionality label Jul 18, 2023
@Julian Julian changed the title Add option to add custom message for fields. Ensure extended validators can create keywords which override exception messages Jul 18, 2023
@Julian Julian added the Dialects v2 Issues which will likely be addressed as part of reworked dialect support label Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Dialects v2 Issues which will likely be addressed as part of reworked dialect support Enhancement Some new desired functionality
Projects
None yet
Development

No branches or pull requests

2 participants