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

Allow specifying custom message at the attribute level #563

Closed
Tim-fors opened this issue Apr 27, 2022 · 2 comments
Closed

Allow specifying custom message at the attribute level #563

Tim-fors opened this issue Apr 27, 2022 · 2 comments

Comments

@Tim-fors
Copy link

Continuation of discussion from #440 (comment)

The custom message feature allows a user to specify a custom validation message based on the type of validation. However, this is limited in that you can only have one message per type.

It would be nice if it was possible to specify this at each attribute, for example

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name.",
      "message": {
        "type": "Invalid type, should be string"}
    },
    "foo": {
      "type": "array",
      "maxItems": 3,
      "message": {
        "maxItems" : "MaxItem must be 3 only",
        "type" : "Invalid type, should be array"
      }
    }
  }
}
@stevehu
Copy link
Contributor

stevehu commented Apr 28, 2022

@Tim-fors While thinking about it, it is not easy to do to cover all the scenarios. Also, I think this should be a joint effort with the spec team. As of now, they don't want to define the messages in the schema but I think it would be a good option. Do you want to open a discussion over there to see what is the response from the spec team? Thanks.

@stevehu
Copy link
Contributor

stevehu commented Apr 30, 2023

We have some validators that support this feature. If this is not enough, please let us know. Thanks.

@stevehu stevehu closed this as completed Apr 30, 2023
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