Readonly
schemaJSON schema against which to validate values. When a schema
provides an errorMessage
string option, all errors occurring for that
schema (but not for nested schemas) collapse into a single error having
this message. The errorMessage
option allows you to provide a custom
error message for a schema. For example, an errorMessage
on a schema
for a property of an object replaces TypeBox's built-in error messages
for errors that occur on that property.
Protected
assertProtected
cleanProtected
cleanProtected
compiledProtected
compiledValidates a value against the schema and returns the first error,
returning null
if there is no error. No validation is performed beyond
the first error, allowing you to protect the server from wasting time and
memory validating excessively long strings. It is equivalent to calling
next()
exactly once on the iterator returned by errors()
, serving
only as a convenience method. For performance reasons, it is best to call
test()
before calling this method. This method does not throw
ValidationException
and does not clean values of unrecognized properties.
Value to validate against the schema.
The first validation error, if there is a validation error,
otherwise null
.
Tests whether a value conforms to the schema, returning an iterable whose
iterator yields the validation errors, or returning null
if there are no
validation errors. This method is equivalent to calling test()
and then
errors()
and exists only for convenience. The method does not throw
ValidationException
and does not clean values of unrecognized properties.
Value to validate against the schema.
An iteratable yielding all validation errors, if any, otherwise
null
. Upon detecting one or more errors for a particular schema
(possibly a nested schema), if the schema provides an errorMessage
property, only a single error is reported for the schema, and the
message
property of this error is set to errorMessage
's value. Also,
the TypeBox error "Expected required property" is dropped when at least
one other error is reported for the property. Consequently, only the
Type.Any
and Type.Unknown
schemas can yield "Expected required
property" errors.
Tests whether a value conforms to the schema, returning the first error,
or returning null
if there is no error. This method is equivalent to
calling test()
and then firstError()
and exists only for convenience.
The method does not throw ValidationException
and does not clean values
of unrecognized properties.
Value to validate against the schema.
The first validation error, if there is a validation error,
otherwise null
.
Protected
toProtected
uncompiledProtected
uncompiledProtected
validateGenerated using TypeDoc
Lazily compiled validator for heterogeneous unions of objects. To improve performance, list the more frequently used types earlier in the union, and list each object's unique key first in its properties.