Dialect details
Dialect registry
Each validator object contains an internal dialect registry which is used to recognize dialect based on $schema keyword value. By default, all official currently supported JSON Schema specification dialects are present in the registry. The registry can be updated:
Please note that overriding existing dialects in the registry is also possible. To do so, create a dialect implementation which returns the same value from getMetaSchema() as the one you want to override.
Default dialect
If schema does not contain a $schema keyword, a default dialect will be used. By default, the default dialect is Draft 2020-12. You can change it by calling:
Moreover, if you set disabledSchemaValidation to true, then the default dialect will be picked for any unknown (by dialect registry) $schema keyword values.
Dialect types
Depending on your needs, you might want to define only specific parts of a dialect.
Meta-schema only
This is the only official way to extend/create dialects, and it's implementation-agnostic.
You will need:
The actual meta-schema:
It can be provided either by
SchemaResolveror registered directly inValidatorinstance.It has to finally resolve to an actual concrete dialect (from dialect registry). It cannot be recursive, either directly or indirectly - it may reference (by
$schema) another "meta-schema only" dialect, but eventually the chain of references must point to a dialect from the dialect registry.
It allows you:
Changing active vocabularies (by
$vocabularykeyword). You can, for example, disable all validation keywords.Defining custom validation for your schemas.
You will not be able to:
Define custom keywords, as the logic cannot be expressed directly in JSON.
Make the dialect independent of another one. As mentioned before: it eventually needs to point to a registered dialect.
Change the supported, required and default vocabularies.
Dialect without meta-schema
This is not really recommended approach as such a dialect can only be used as a default dialect.
You will need:
The actual implementation of
Dialect.
It allows you (only for schemas lacking $schema keyword):
Defining custom keywords via
EvaluatorFactory.Defining custom validation for your schemas.
Changing active vocabularies (by
$vocabularykeyword). You can, for example, disable all validation keywords.Changing the supported, required and default vocabularies.
You will not be able to:
Define custom validation for your schemas.
Apply to schemas with resolvable
$schemavalues.
Full dialect
The combination of two previous approaches.
You will need:
The actual meta-schema:
It can be provided either by
SchemaResolveror registered directly inValidatorinstance.It can be recursive.
The actual implementation of
Dialect.
It allows you:
Defining custom keywords via
EvaluatorFactory.Changing the supported, required and default vocabularies.