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

Issue 426 custom message #440

Merged
merged 3 commits into from
Aug 24, 2021
Merged

Issue 426 custom message #440

merged 3 commits into from
Aug 24, 2021

Conversation

adilath18
Copy link
Contributor

@stevehu
#426 Documentation for Custom Error Message
PR: #438

@stevehu stevehu merged commit 8f9189b into networknt:master Aug 24, 2021
@stevehu
Copy link
Contributor

stevehu commented Aug 24, 2021

@adilath18 Thanks a lot for your help.

@adilath18
Copy link
Contributor Author

adilath18 commented Aug 24, 2021

@stevehu
Thanks a lot for this opportunity. This was my first open-source contribution and enjoyed the experience.

@stevehu
Copy link
Contributor

stevehu commented Aug 25, 2021

The first contribution is the hardest and I am glad you had an enjoyable experience. Again, thanks a lot for your help and welcome onboard.

@sambireddyg
Copy link

Hi, I am trying to use the custom message feature. I believe the message implementation should be moved to the attribute level.
In the test case of the pull request the message is at the top level. So, if we have to add a custom message to first name and custom message to foo it is not possible.
the implementation should be

{
"$id": "https://example.com/person.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Person",
"type": "object",
"properties": {
"firstName": {
"type": "string",
"description": "The person's first name.",
"maxLength":10,
"message": {
"maxLength" : "Name can be max of 10 characters",
"type" : "Invalid type"
}
},
"foo": {
"type": "array",
"maxItems": 3,
"message": {
"maxItems" : "MaxItem must be 3 only",
"type" : "Invalid type"
}
}
},

}

in the getMessageNode we should be using the schemanode directly and get the required message.

@initshdb
Copy link

@sambireddyg @stevehu @adilath18
Is it possible adding different message to the same validation type for different properties like @sambireddyg mentioned in his question above.

"prop1": {
      "type": "string",
      "maxLength": 5,
 },
"prop2": {
      "type": "string",
      "maxLength": 10,
 },

I need custom messages for both prop1 (message : "Max 5 chars") and prop2 (message : "Max 10 chars") , if both fail at the same time.

@stevehu
Copy link
Contributor

stevehu commented Mar 15, 2022

@everyone I think it is always a good idea to give users more options to customized the error messages. @sambireddyg @nitishborade would you like to try it out and submit a PR? Thanks.

@Tim-fors
Copy link

@everyone I think it is always a good idea to give users more options to customized the error messages. @sambireddyg @nitishborade would you like to try it out and submit a PR? Thanks.

@stevehu I would like to look into adding this functionality, should I create a new issue to track this or just open a PR to start a discussion?

@stevehu
Copy link
Contributor

stevehu commented Apr 27, 2022

Opening a new issue is always better than submitting a PR directly to encourage discussions. Thanks.

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

Successfully merging this pull request may close these issues.

None yet

6 participants