Skip to content

Commit 1468c8b

Browse files
committed
restructuring, and "default values" section
1 parent 50463d4 commit 1468c8b

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

README.md

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@
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)
12+
* [Eary failure mode](#early-failure-mode)
13+
* [Default values](#default-values)
1514
* [Format validators](#format-validators)
1615
* [Example](#example)
1716
* [Resolution scopes](#resolution-scopes)
@@ -194,6 +193,7 @@ This will print the following output:
194193
#/rectangle/a: -5.0 is not higher or equal to 0
195194
#/rectangle/b: expected type: Number, found: String
196195
```
196+
197197
### JSON report of the failures
198198

199199
Since version `1.4.0` it is possible to print the `ValidationException` instances as
@@ -211,43 +211,44 @@ following keys:
211211
Please take into account that the complete failure report is a *hierarchical tree structure*: sub-causes of a cause can
212212
be obtained using `#getCausingExceptions()` .
213213

214-
## Configuring the validation
214+
## Early failure mode
215215

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:
216+
By default the validation error reporting in collecting mode (see the "Investigating failures" chapter). That is convenient for having a
217+
detailed error report, but under some circumstances it is more appropriate to stop the validation when a failure is found without
218+
checking the rest of the JSON document. To toggle this fast-failing validation mode
219+
* you have to explicitly build a `Validator` instance for your schema instead of calling `Schema#validate(input)`
220+
* you have to call the `failEarly()` method of `ValidatorBuilder`
221+
222+
Example:
220223

221224
```
222225
import org.everit.json.schema.Validator;
223226
...
224227
Validator validator = Validator.builder()
225-
/* configuration comes here */
228+
.failEarly()
226229
.build();
227230
validator.performValidation(schema, input);
228-
```
231+
```
229232

230233
_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
231234
to configure it only once._
232235

233-
### Early failure mode
234236

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:
237+
## Default values
238+
239+
The JSON Schema specification defines the "default" keyword for denoting default values, though it doesn't explicitly state how it should
240+
affect the validation process. By default this library doesn't set the default values, but if you need this feature, you can turn it on
241+
by the `SchemaLoaderBuilder#useDefaults(boolean)` method, before loading the schema:
239242

240243
```
241-
import org.everit.json.schema.Validator;
242-
...
243-
Validator validator = Validator.builder()
244-
.failEarly()
245-
.build();
246-
validator.performValidation(schema, input);
244+
Schema schema = SchemaLoader.builder()
245+
.useDefaults(true)
246+
.schemaJson(rawSchema)
247+
.build()
248+
.load().build();
249+
schema.validate(input);
247250
```
248251

249-
250-
251252
## Format validators
252253

253254

0 commit comments

Comments
 (0)