Skip to content

Commit 33cabdd

Browse files
authored
Add information about format keyword behavior to README (#172)
Related to #171
1 parent 484e687 commit 33cabdd

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,26 @@ val valid = schema.validate(elementToValidate, errors::add)
354354
The library supports `format` assertion.
355355
All formats from [JSON schema draft 2020-12](https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-01#section-7.3) are supported.
356356

357+
According to JSON schema specification the `format` keyword produces **assertion by default** for all drafts **before draft 2019-09**.
358+
Starting **from draft 2019-09** the `format` keyword produces only **annotation by default**.
359+
360+
You can change the default behaviour by specifying the corresponding option in `JsonSchemaLoader`.
361+
```kotlin
362+
import io.github.optimumcode.json.schema.FormatBehavior.ANNOTATION_AND_ASSERTION
363+
import io.github.optimumcode.json.schema.JsonSchemaLoader
364+
import io.github.optimumcode.json.schema.SchemaOption
365+
366+
val schema = JsonSchemaLoader.create()
367+
// option to change the default behavior
368+
.withSchemaOption(SchemaOption.FORMAT_BEHAVIOR_OPTION, ANNOTATION_AND_ASSERTION)
369+
// or
370+
.withSchemaOption(SchemaOption.FORMAT_BEHAVIOR_OPTION, ANNOTATION_ONLY)
371+
.fromDefinition(schemaDefinition)
372+
```
373+
374+
Alternatively, for drafts starting from the draft 2019-09 you can either use a custom meta-schema with format-assertion vocabulary enabled
375+
and use this meta-schema in `$schema` property or define `$vocabulary` block with enabled format assertion in your schema.
376+
357377
**_Implementation details:_**
358378

359379
+ **regex** - to implement regex format Kotlin `Regex` class is used.

0 commit comments

Comments
 (0)