Abstract
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.
Validates a value against the schema, halting validation at the first
validation error with a ValidationException
. Does not clean values of
unrecognized properties.
ValidationException when the value is invalid, reporting only
the first validation error in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall eror message to report in the exception.
The substring {error}
, if present, will be replaced with a string
representation of the error. Defaults to "Invalid value".
Validates a value against the schema, halting validation at the first
validation error with a ValidationException
. On successful validation,
removes unrecognized properties from the provided value.
ValidationException when the value is invalid, reporting only
the first validation error in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall eror message to report in the exception.
The substring {error}
, if present, will be replaced with a string
representation of the error. Defaults to "Invalid value".
Validates a value against the schema, halting validation at the first
validation error with a ValidationException
. On successful validation,
returns a copy of the value with unrecognized properties removed, but
returns the original value if there are no unrecognized properties.
ValidationException when the value is invalid, reporting only
the first validation error in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall eror message to report in the exception.
The substring {error}
, if present, will be replaced with a string
representation of the error. Defaults to "Invalid value".
The provided value itself if the value is not an object or if the value is an object having no unrecognized properties. If the value is an object having at least one unrecognized property, returns a copy of the value with unrecognized properties removed.
Protected
Abstract
assertProtected
cleanProtected
cleanAbstract
errorsValidates a value against the schema and returns an iteratable whose
iterator yields the validation errors. The iterator tests the value for the
next error on each call to next()
, returning a ValueError
for the error
until done. It does not evaluate errors in advance of their being
requested, allowing you to short-circuit validation by stopping iteration
early. 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.
An iteratable yielding all validation errors. 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.
Validates 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
.
Abstract
testTests whether a value conforms to the schema. For performance reasons, it
is best to call this method before calling errors()
or firstError()
,
should you also need to information about the errors. This method does not
throw ValidationException
and does not clean values of unrecognized
properties.
Value to validate against the schema.
true
when the value conforms to the schema, false
otherwise.
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
uncompiledValidates a value against the schema, detecting all validation errors
and reporting them by throwing ValidationException
. Does not clean
values of unrecognized properties.
ValidationException when the value is invalid, reporting all
validation errors in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall error message to report in the exception.
Validates a value against the schema, detecting all validation errors
and reporting them by throwing ValidationException
. On successful
validation, removes unrecognized properties from the provided value.
ValidationException when the value is invalid, reporting all
validation errors in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall error message to report in the exception.=
Validates a value against the schema, detecting all validation errors
and reporting them with a ValidationException
. On successful validation,
returns a copy of the value with unrecognized properties removed, but
returns the original value if there are no unrecognized properties.
ValidationException when the value is invalid, reporting all
validation errors in the details
property. The errorMessage
parameter provides the exception's overall error message.
Value to validate against the schema.
Optional
overallError: stringOverall error message to report in the exception.
The provided value itself if the value is not an object or if the value is an object having no unrecognized properties. If the value is an object having at least one unrecognized property, returns a copy of the value with unrecognized properties removed.
Protected
Abstract
validateGenerated using TypeDoc
Abstract validator for values that are typed member unions of objects.