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

Adding custom message support in the schema #438

Merged
merged 1 commit into from
Aug 23, 2021
Merged

Adding custom message support in the schema #438

merged 1 commit into from
Aug 23, 2021

Conversation

adilath18
Copy link
Contributor

@adilath18 adilath18 commented Aug 20, 2021

We can create custom message, by adding another property in schema i.e message for e.g.

If our schema is like this:

"schema": {
      "properties": {
        "foo": {
          "type": "integer"
        },
        "bar": {
          "type": "string"
        }
      }
    },

Then to provide custom message, we have to modify it to:

"schema": {
      "properties": {
        "foo": {
          "type": "integer"
        },
        "bar": {
          "type": "string"
        }
      },
    **"message": {
        "type" : "Invalid type"
      }**
    },

Since we are getting arguments in ValidationMessage, we can make this message more illustrative using dynamic arguments.
e.g. {0} invalid type where , {0} will be path

@stevehu
Copy link
Contributor

stevehu commented Aug 23, 2021

This is a smart way to implement the customized error message with the schema. Could you please add a small doc on the feature so that other people will benefit from your work? Thanks.

@stevehu stevehu merged commit e8c9a2d into networknt:master Aug 23, 2021
@stevehu stevehu changed the title "Adding custom message support" Adding custom message support Aug 23, 2021
@stevehu stevehu changed the title Adding custom message support Adding custom message support in the schema Aug 23, 2021
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

3 participants