Skip to content

Commit 50463d4

Browse files
committed
docs: validator config, early failure mode
1 parent 9bacceb commit 50463d4

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

README.md

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
* [Draft 4 or Draft 6?](#draft-4-or-draft-6)
1010
* [Investigating failures](#investigating-failures)
1111
* [JSON report of the failures](#json-report-of-the-failures)
12+
* [Configuring the validation](#validator-config)
13+
* [Eary failure mode](#validator-config-early-failure)
14+
* [Default value support](#validator-config-default-support)
1215
* [Format validators](#format-validators)
1316
* [Example](#example)
1417
* [Resolution scopes](#resolution-scopes)
@@ -40,7 +43,7 @@ Add the JitPack repository and the dependency to your `pom.xml` as follows:
4043
<dependency>
4144
<groupId>com.github.everit-org.json-schema</groupId>
4245
<artifactId>org.everit.json.schema</artifactId>
43-
<version>1.6.1</version>
46+
<version>1.7.0</version>
4447
</dependency>
4548
...
4649
<repositories>
@@ -208,6 +211,42 @@ following keys:
208211
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
209212
be obtained using `#getCausingExceptions()` .
210213

214+
## Configuring the validation
215+
216+
If you call the `Schema#validate(input)` method then the validation will happen with a convenient mode which should meet the
217+
needs of most users for common scenarios. Though there can be cases where the default behaviour doesn't fit your needs. Then you can
218+
set some configuration values explicitly by manually creating a `Validator` instance and toggling some features in its builder, so
219+
instead of calling `Schema.validate(input)`, your code will look something like this:
220+
221+
```
222+
import org.everit.json.schema.Validator;
223+
...
224+
Validator validator = Validator.builder()
225+
/* configuration comes here */
226+
.build();
227+
validator.performValidation(schema, input);
228+
```
229+
230+
_Note: the `Validator` class is immutable and thread-safe, so you don't have to create a new one for each validation, it is enough
231+
to configure it only once._
232+
233+
### Early failure mode
234+
235+
By default the validation error reporting in collecting mode (see the "Investigating failures" chapter). That is convenient for having a
236+
detailed error report, but under some circumstances it is more appropriate to stop the validation when a failure is found without
237+
checking the rest of the JSON document. To toggle this fast-failing validation mode you have to call the failEarly() method of
238+
ValidatorBuilder:
239+
240+
```
241+
import org.everit.json.schema.Validator;
242+
...
243+
Validator validator = Validator.builder()
244+
.failEarly()
245+
.build();
246+
validator.performValidation(schema, input);
247+
```
248+
249+
211250

212251
## Format validators
213252

0 commit comments

Comments
 (0)