Skip to content

Interface: ValidationOptions ​

The options of a validation, given to DTO.validate(), DTO.validateAsync(), DTO.isValid() or to a schema (prefs(), which overrides the options of the validation for that schema). Unset options take the defaults of lakutata: abortEarly, allowUnknown, stripUnknown and convert true, cache false; the schemas built by DTO are strict nonetheless (see AnySchema.strict()).

Extends ​

  • BaseValidationOptions

Properties ​

abortEarly? ​

optional abortEarly?: boolean

when true, stops validation on the first error, otherwise returns all the errors found.

Default ​

ts
true

Inherited from ​

BaseValidationOptions.abortEarly


allowUnknown? ​

optional allowUnknown?: boolean

When true, the objects may contain unknown keys; when false, they are rejected, unless stripUnknown removes them. ObjectSchema.unknown() overrides it for an object.

Default ​

ts
true (lakutata)

Inherited from ​

BaseValidationOptions.allowUnknown


artifacts? ​

optional artifacts?: boolean

when true, return artifacts alongside the value.

Default ​

ts
false

Inherited from ​

BaseValidationOptions.artifacts


cache? ​

optional cache?: boolean

when true, schema caching is enabled (for schemas with explicit caching rules).

Default ​

ts
false

Inherited from ​

BaseValidationOptions.cache


context? ​

optional context?: Context

provides an external data set to be used in references

Inherited from ​

BaseValidationOptions.context


convert? ​

optional convert?: boolean

when true, attempts to cast values to the required types (e.g. a string to a number).

Default ​

ts
true

Inherited from ​

BaseValidationOptions.convert


dateFormat? ​

optional dateFormat?: "string" | "date" | "iso" | "time" | "utc"

sets the string format used when converting dates to strings in error messages and casting.

Default ​

ts
'iso'

Inherited from ​

BaseValidationOptions.dateFormat


debug? ​

optional debug?: boolean

when true, valid results and throw errors are decorated with a debug property which includes an array of the validation steps used to generate the returned result.

Default ​

ts
false

Inherited from ​

BaseValidationOptions.debug


errors? ​

optional errors?: ErrorFormattingOptions

error formatting settings.

Inherited from ​

BaseValidationOptions.errors


externals? ​

optional externals?: boolean

if false, the external rules set with any.external() are ignored, which is required to ignore any external validations in synchronous mode (or an exception is thrown).

Default ​

ts
true

Inherited from ​

BaseValidationOptions.externals


messages? ​

optional messages?: LanguageMessages

Error message templates overriding the default ones, by error code ({'string.min': '…'}) or by language then error code. The variables in double braces ({{#label}}) are HTML-escaped when errors.escapeHtml is true.

Default ​

ts
{}

noDefaults? ​

optional noDefaults?: boolean

when true, do not apply default values.

Default ​

ts
false

Inherited from ​

BaseValidationOptions.noDefaults


nonEnumerables? ​

optional nonEnumerables?: boolean

when true, inputs are shallow cloned to include non-enumerable properties.

Default ​

ts
false

Inherited from ​

BaseValidationOptions.nonEnumerables


presence? ​

optional presence?: PresenceMode

sets the default presence requirements. Supported modes: 'optional', 'required', and 'forbidden'.

Default ​

ts
'optional'

Inherited from ​

BaseValidationOptions.presence


skipFunctions? ​

optional skipFunctions?: boolean

when true, ignores unknown keys with a function value.

Default ​

ts
false

Inherited from ​

BaseValidationOptions.skipFunctions


stripUnknown? ​

optional stripUnknown?: boolean | { arrays?: boolean; objects?: boolean; }

Remove the unknown elements instead of rejecting them: true (or {objects: true}) removes the unknown keys of the objects, {arrays: true} the array items matching none of the item schemas. The keys an object allows with unknown() are kept.

Default ​

ts
true (lakutata)

Inherited from ​

BaseValidationOptions.stripUnknown


targetName? ​

optional targetName?: string | symbol

The name of the validated value in the error messages and paths: the value is validated as the key of that name of an object.

Released under the MIT License.