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

Support for own error messages #1

Open
lobodpav opened this issue Dec 14, 2013 · 2 comments
Open

Support for own error messages #1

lobodpav opened this issue Dec 14, 2013 · 2 comments

Comments

@lobodpav
Copy link
Contributor

Would be great to be able to specify custom error message for each property constraint so that jassi would use it as message instead of the default text.

This is handy when developing REST services and want to use custom messages being returned to the caller.

@iclanzan
Copy link
Owner

Sounds interesting and I’m open for pull requests. Do you want to implement this?

@lobodpav
Copy link
Contributor Author

Would be glad to implement this.

However, I've been thinking about this issue a bit now and I can see a showstopper.

To be able to specify an error message per each validation keyword, it would mean to extend validation keywords. Either it would contain a value so that default error message is returned, or it would contain an object with value and message to return in case of validation error.

Example:

{
    "type": "object",
    "properties": {
        "firstName": {
            "type": {
                "value": "string",
                "message": "STRING type required"
            },
            "minLength": {
                "value": "6",
                "message": "First name must be 6 characters long at least"
            }
        },
        "lastName": {
            "type": "string"
        },
    },
    "required": [
        {
            "value": "firstName",
            "message": "First name is required"
        },
        {
            "value": "lastName",
            "message": "Last name is mandatory"
        }
    ]
}

The problem is, that this is not a valid JSON schema according to v4 spec.

Any idea on how to overcome this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants