Protected
isProtected
preprocessorsA list of preprocessors associated with the Builder
Protected
typeProtected
validatorsA list of validators associated with the Builder
Fields not defined in properties
will not be validated
and will be passed through the validation.
Adds a preprocessor
to a preprocessors list
Adds a new property to the object schema. The new property will be validated according to the provided schema.
name of the new property
schema builder of the new property
Adds new properties to the object schema. The same as .addProp()
but
allows to add multiple properties with one call. The new properties
will be validated according to the provided schemas.
a key/schema object map.
Adds all properties from the schema
object schema to the current schema.
an instance of ObjectSchemaBuilder
Adds a validator
to validators list.
Remove all preprocessors for this schema.
Remove all validators for this schema.
Protected
createProtected method used to create an new instance of the Builder
defined by the props
object. Should be used to instanticate new
builders to keep builder's immutability.
arbitrary props object
Adds all properties from schema
to the current schema.
TSchema & TAnotherSchema
is a good example of the similar concept
in the TS type system.
an object schema to take properties from
Generates a serializable object describing the defined schema
If set to true
, schema validation will not
return errors if object contains fields which
are not defined in the schema properties
.
Set to false
by default
If set to false
, schema will be optional (null
or undefined
values
will be considered as valid).
Array of preprocessor functions
Properties defined in schema
String id
of schema type, e.g. string',
numberor
object`.
Array of validator functions
Partial<T>
would be a good example of the
same operation in the TS world.
Required<T>
would be a good example of the
same operation in the TS world.
An alias for .partial(prop: string)
name of the property
Marks prop
as required property.
If prop
does not exists in the current schema,
an error will be thrown.
name of the property
Modify schema for propName
and return a new schema.
Could be useful if you want to leave all schema intact, but
change a type of one property.
name of the property (string)
callback function returning a new schema fo the propName
. As a first parameter
you will receive an old schema for propName
.
Fields not defined in properties
will be considered
as schema violation. This is the default behavior.
Omits properties listed in properties
from the schema.
Consider Omit<Type, 'prop1'|'prop2'...>
as a good illustration
from the TS world.
array of property names (strings) to remove from the schema.
Removes propName
from the list of properties.
property name to remove. Schema should contain this property. An error will be thrown otherwise.
Removes all properties of schema
from the current schema.
Omit<TSchema, keyof TAnotherSchema>
as a good illustration
from the TS world.
schema builder to take properties from.
Marks all properties in the current schema as optional.
It is the same as call .optional('propname')
where propname
is the name
of every property in the schema.
Marks all properties from properties
as optional in the schema.
list of property names (string) to make optional
Marks property propName
as optional in the schema.
the name of the property (string).
Returns a new schema containing only properties listed in
properties
array.
array of property names (strings)
Returns new schema based on the current schema. This new schema
will consists only from properties which names are taken from the
schema
object schema.
schema to take property names list from
Returns a new schema consisting of only one property
(taken from the property
property name). If the property
does not exists in the current schema, an error will be thrown.
the name of the property (string).
Protected
prePerforms validion of object schema over the object
.
Optional
context: ValidationContextOptional ValidationContext
settings.
Static
createGenerated using TypeDoc
Object schema builder class. Similar to the
object
type in JS. Allows to define a schema forobject
value. Should be used to validate objects with specific properties. Properties should be defined as their own schema builders. You can use anySchemaBuilder
e.g.string()
,number()
,boolean()
,array()
,object()
, etc. to define properties. Which means that you can define nested objects and arrays of any complexity.NOTE this class is exported only to give opportunity to extend it by inheriting. It is not recommended to create an instance of this class directly. Use () function instead.
Example
Example
Example
Example
See
object