Options
August 29, 2023 · View on GitHub
Regular options
-
mode—'default'by default invalidator(),'strong'by default inparser().
See also strong mode documentation.'lax'mode disables some default schema coherence checks.'spec'mode is the same as'lax'but also disables format assertion indraft2019-09and newer$schemaversions. -
useDefaults—falseby default. Applydefault:values from the schema to missing properties. -
removeAdditional—falseby default.
Removes additional properties instead of failing the validation on them.
SupportsadditionalProperties: falseandadditionalItems: false.
Note that it fails to compile the schema in case of uncertain paths with this option. -
includeErrors—falseby default.
Enable returning errors (without it, just a validaton flag is returned). -
allErrors—falseby default.
Return all errors, not just the first one. -
contentValidation—falseby default fordraft/2019-09and newer,
trueby default fordraft7and older.
EnablescontentEncoding,contentMediaType,contentSchemausage for validation and makes
failing those checks affect the boolean result of the validation.
By default they are no-op per spec sincedraft/2019-09, and hence are treated as an unused
keyword and raise an error at compile time unlessallowUnusedKeywordsoption is enabled. -
dryRun—falseby default.
Don't produce a validator, just verify the schema and throw on first error. -
lint—falseby default.
Don't produce a validator, just verify the schema and collect all errors. Same as Linter mode. -
$schemaDefault—nullby default.
Can not be used ifrequireSchemais on. -
formatAssertion—trueby default (falseby default whenmode = 'spec'and$schemaisdraft2019-09or later).Switching it to
falsewill disableformatassertions, essentially making them not affect the result of validation at all, i.e. validation would pass regardless of allformatstrings in the schema.That (
false) behaviour is specified as default in the upstream sincedraft2019-09, but not followed here, unlessmodeis set to'spec', due to being potentially dangereous/unsafe and missing expected validation.For more info, see upstream documentation and upstream changelog.
-
formats—{}by default.
Additional formats to use. -
weakFormats—truein'default'and'lax'/'spec'modes,falsein'strong'mode by default.
Add support for formats deemed potentially weak (currently, onlyRegExp). -
extraFormats—falseby default.
Enable extra built-in non-standard formats, see formats.js. -
schemas— empty by default.
Either aMap, anArray, or anObjectwith schemas to resolve external$refpointers.
Options for enforcing additional checks
All these options are false by default in 'default' and 'lax/'spec' modes and true by
default in 'strong' mode.
-
requireSchema— refuse to use schemas with missing$schema. -
requireValidation— refuse to use schemas which do not perform validation of all items or properties. -
requireStringValidation— refuse to use schemas which do not perform validation of all string properties against aformat,pattern, or acontentSchema. -
complexityChecks— refuse to use schemas that might be missing required checks to avoid potential DoS, e.g. requiremaxLengthon complex regexps andmaxItemson complexuniqueItems. Note that it will pass if those are present but have a very high value, the only intent is to prevent a mistake when those checks are missed. If they are present, it is assumed that the shema author chose an appropriate value corresponding to the regex complexity. -
forbidNoopValues— refuse to compile schemas with certain noop keywords that make no sense.
Currently, that is only$recursiveAnchor: false.
This option is overridable even in'strong'mode.
Options for relaxing coherence checks
-
allowUnusedKeywords—opts.mode === 'lax' || opts.mode === 'spec'by default.
Allows unused keywords to be present in the schema. -
allowUnreachable—opts.mode === 'lax' || opts.mode === 'spec'by default.
Allows unreachable checks to be present in the schema.
Options to pass assumptions about input
If certain assumptions about input are always true, that information can be used to optimize the generated validator.
-
unmodifiedPrototypes—falseby default. Assume no mangledObject/Arrayprototypes in runtime. -
isJSON—falseby default. Assume input to be JSON, which e.g. makesundefinedimpossible.