Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ For the latest version, please check the [release](https://github.com/networknt/

## [ECMA-262 Regex](doc/ecma-262.md)

## [Custom Message](doc/cust-msg.md)

## Known issues

I have just updated the test suites from the [official website](https://github.com/json-schema-org/JSON-Schema-Test-Suite) as the old ones were copied from another Java validator. Now there are several issues that need to be addressed. All of them are edge cases, in my opinion, but need to be investigated. As my old test suites were inherited from another Java JSON Schema Validator, I guess other Java Validator would have the same issues as these issues are in the Java language itself.
Expand Down
62 changes: 62 additions & 0 deletions doc/cust-msg.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
This document explains how users can create their custom message for schema validation.


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

<b> Example of schema with default message: </b>

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


<b> Example of schema with a custom message: </b>

````
{
"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 <b>validation type</b>, and the value should be the <b>custom message</b>.


Also, we can make format the dynamic message with properties returned from [ValidationMessage.java](https://github.com/networknt/json-schema-validator/blob/master/src/main/java/com/networknt/schema/ValidationMessage.java) class such as <b>arguments, path e.t.c.</b>



Take a look at the [PR](https://github.com/networknt/json-schema-validator/pull/438)