Skip to content

Latest commit

 

History

History
62 lines (46 loc) · 1.33 KB

cust-msg.md

File metadata and controls

62 lines (46 loc) · 1.33 KB

This document explains how users can create their custom message for schema validation.

We can provide the custom message in the json schema itself.

Example of schema with default message:

{
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "foo": {
      "type": "array",
      "maxItems": 3
    }
  }
}

Example of schema with a custom message:

{
  "type": "object",
  "properties": {
    "firstName": {
      "type": "string",
      "description": "The person's first name."
    },
    "foo": {
      "type": "array",
      "maxItems": 3
    }
  },
  "message": {
    "maxItems" : "MaxItem must be 3 only",
    "type" : "Invalid type"
  }
}
"message": {
    [validationType] : [customMessage]
  }

In the message field users can declare their custom message. The key should be the validation type, and the value should be the custom message.

Also, we can make format the dynamic message with properties returned from ValidationMessage.java class such as arguments, path e.t.c.

Take a look at the PR