Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add information about format keyword behavior to README #172

Merged
merged 1 commit into from
Jul 31, 2024
Merged
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
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,26 @@ val valid = schema.validate(elementToValidate, errors::add)
The library supports `format` assertion.
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.

According to JSON schema specification the `format` keyword produces **assertion by default** for all drafts **before draft 2019-09**.
Starting **from draft 2019-09** the `format` keyword produces only **annotation by default**.

You can change the default behaviour by specifying the corresponding option in `JsonSchemaLoader`.
```kotlin
import io.github.optimumcode.json.schema.FormatBehavior.ANNOTATION_AND_ASSERTION
import io.github.optimumcode.json.schema.JsonSchemaLoader
import io.github.optimumcode.json.schema.SchemaOption

val schema = JsonSchemaLoader.create()
// option to change the default behavior
.withSchemaOption(SchemaOption.FORMAT_BEHAVIOR_OPTION, ANNOTATION_AND_ASSERTION)
// or
.withSchemaOption(SchemaOption.FORMAT_BEHAVIOR_OPTION, ANNOTATION_ONLY)
.fromDefinition(schemaDefinition)
```

Alternatively, for drafts starting from the draft 2019-09 you can either use a custom meta-schema with format-assertion vocabulary enabled
and use this meta-schema in `$schema` property or define `$vocabulary` block with enabled format assertion in your schema.

**_Implementation details:_**

+ **regex** - to implement regex format Kotlin `Regex` class is used.
Expand Down
Loading