Interface: Root
Properties
| Property | Type | Description |
|---|---|---|
cache | CacheConfiguration | - |
override | symbol | A special value used with any.allow(), any.invalid(), and any.valid() as the first value to reset any previously set values. |
ValidationError | (message: string, details: ValidationErrorItem_2[], original: any) => ValidationError_2 | - |
version | string | Current version of the joi package. |
Methods
allow()
allow(...values: any[]): Schema_2;Whitelists a value
Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
alt()
Call Signature
alt<A, B>(params: [SchemaLike_2<A>, SchemaLike_2<B>]): AlternativesSchema_2<A | B>;Alias for alternatives
Type Parameters
| Type Parameter |
|---|
A |
B |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>] |
Returns
AlternativesSchema_2<A | B>
Call Signature
alt<A, B, C>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>]): AlternativesSchema_2<A | B | C>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>] |
Returns
AlternativesSchema_2<A | B | C>
Call Signature
alt<A, B, C, D>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>]): AlternativesSchema_2<A | B | C | D>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>] |
Returns
AlternativesSchema_2<A | B | C | D>
Call Signature
alt<A, B, C, D, E>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>, SchemaLike_2<E>]): AlternativesSchema_2<A | B | C | D | E>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
E |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>, SchemaLike_2<E>] |
Returns
AlternativesSchema_2<A | B | C | D | E>
Call Signature
alt<A, B>(a: SchemaLike_2<A>, b: SchemaLike_2<B>): AlternativesSchema_2<A | B>;Type Parameters
| Type Parameter |
|---|
A |
B |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
Returns
AlternativesSchema_2<A | B>
Call Signature
alt<A, B, C>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>): AlternativesSchema_2<A | B | C>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
Returns
AlternativesSchema_2<A | B | C>
Call Signature
alt<A, B, C, D>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>,
d: SchemaLike_2<D>): AlternativesSchema_2<A | B | C | D>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
d | SchemaLike_2<D> |
Returns
AlternativesSchema_2<A | B | C | D>
Call Signature
alt<A, B, C, D, E>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>,
d: SchemaLike_2<D>,
e: SchemaLike_2<E>): AlternativesSchema_2<A | B | C | D | E>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
E |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
d | SchemaLike_2<D> |
e | SchemaLike_2<E> |
Returns
AlternativesSchema_2<A | B | C | D | E>
Call Signature
alt<TSchema>(types: SchemaLike_2<any>[]): AlternativesSchema_2<TSchema>;Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Parameters
| Parameter | Type |
|---|---|
types | SchemaLike_2<any>[] |
Returns
AlternativesSchema_2<TSchema>
Call Signature
alt<TSchema>(...types: SchemaLike_2<any>[]): AlternativesSchema_2<TSchema>;Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Parameters
| Parameter | Type |
|---|---|
...types | SchemaLike_2<any>[] |
Returns
AlternativesSchema_2<TSchema>
alternatives()
Call Signature
alternatives<A, B>(params: [SchemaLike_2<A>, SchemaLike_2<B>]): AlternativesSchema_2<A | B>;Generates a type that will match one of the provided alternative schemas
Type Parameters
| Type Parameter |
|---|
A |
B |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>] |
Returns
AlternativesSchema_2<A | B>
Call Signature
alternatives<A, B, C>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>]): AlternativesSchema_2<A | B | C>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>] |
Returns
AlternativesSchema_2<A | B | C>
Call Signature
alternatives<A, B, C, D>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>]): AlternativesSchema_2<A | B | C | D>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>] |
Returns
AlternativesSchema_2<A | B | C | D>
Call Signature
alternatives<A, B, C, D, E>(params: [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>, SchemaLike_2<E>]): AlternativesSchema_2<A | B | C | D | E>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
E |
Parameters
| Parameter | Type |
|---|---|
params | [SchemaLike_2<A>, SchemaLike_2<B>, SchemaLike_2<C>, SchemaLike_2<D>, SchemaLike_2<E>] |
Returns
AlternativesSchema_2<A | B | C | D | E>
Call Signature
alternatives<A, B>(a: SchemaLike_2<A>, b: SchemaLike_2<B>): AlternativesSchema_2<A | B>;Type Parameters
| Type Parameter |
|---|
A |
B |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
Returns
AlternativesSchema_2<A | B>
Call Signature
alternatives<A, B, C>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>): AlternativesSchema_2<A | B | C>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
Returns
AlternativesSchema_2<A | B | C>
Call Signature
alternatives<A, B, C, D>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>,
d: SchemaLike_2<D>): AlternativesSchema_2<A | B | C | D>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
d | SchemaLike_2<D> |
Returns
AlternativesSchema_2<A | B | C | D>
Call Signature
alternatives<A, B, C, D, E>(
a: SchemaLike_2<A>,
b: SchemaLike_2<B>,
c: SchemaLike_2<C>,
d: SchemaLike_2<D>,
e: SchemaLike_2<E>): AlternativesSchema_2<A | B | C | D | E>;Type Parameters
| Type Parameter |
|---|
A |
B |
C |
D |
E |
Parameters
| Parameter | Type |
|---|---|
a | SchemaLike_2<A> |
b | SchemaLike_2<B> |
c | SchemaLike_2<C> |
d | SchemaLike_2<D> |
e | SchemaLike_2<E> |
Returns
AlternativesSchema_2<A | B | C | D | E>
Call Signature
alternatives<TSchema>(types: SchemaLike_2<TSchema>[]): AlternativesSchema_2<TSchema>;Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Parameters
| Parameter | Type |
|---|---|
types | SchemaLike_2<TSchema>[] |
Returns
AlternativesSchema_2<TSchema>
Call Signature
alternatives<TSchema>(...types: SchemaLike_2<TSchema>[]): AlternativesSchema_2<TSchema>;Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Parameters
| Parameter | Type |
|---|---|
...types | SchemaLike_2<TSchema>[] |
Returns
AlternativesSchema_2<TSchema>
any()
any<TSchema>(): AnySchema_2<TSchema>;Generates a schema object that matches any data type.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Returns
AnySchema_2<TSchema>
array()
array<TSchema>(): ArraySchema_2<TSchema>;Generates a schema object that matches an array data type.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any[] |
Returns
ArraySchema_2<TSchema>
assert()
Call Signature
assert(
value: any,
schema: Schema_2,
options?: ValidationOptions): void;Validates a value against a schema and throws if validation fails.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | any | the value to validate. |
schema | Schema_2 | the schema object. |
options? | ValidationOptions | - |
Returns
void
Call Signature
assert(
value: any,
schema: Schema_2,
message: string | Error,
options?: ValidationOptions): void;Parameters
| Parameter | Type |
|---|---|
value | any |
schema | Schema_2 |
message | string | Error |
options? | ValidationOptions |
Returns
void
attempt()
Call Signature
attempt<TSchema>(
value: any,
schema: TSchema,
options?: ValidationOptions): TSchema extends Schema_2<Value> ? Value : never;Validates a value against a schema, returns valid object, and throws if validation fails.
Type Parameters
| Type Parameter |
|---|
TSchema extends Schema_2<any> |
Parameters
| Parameter | Type | Description |
|---|---|---|
value | any | the value to validate. |
schema | TSchema | the schema object. |
options? | ValidationOptions | - |
Returns
TSchema extends Schema_2<Value> ? Value : never
Call Signature
attempt<TSchema>(
value: any,
schema: TSchema,
message: string | Error,
options?: ValidationOptions): TSchema extends Schema_2<Value> ? Value : never;Type Parameters
| Type Parameter |
|---|
TSchema extends Schema_2<any> |
Parameters
| Parameter | Type |
|---|---|
value | any |
schema | TSchema |
message | string | Error |
options? | ValidationOptions |
Returns
TSchema extends Schema_2<Value> ? Value : never
binary()
binary<TSchema>(): BinarySchema_2<TSchema>;Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | Buffer<ArrayBufferLike> |
Returns
BinarySchema_2<TSchema>
bool()
bool<TSchema>(): BooleanSchema_2<TSchema>;Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via boolean().
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | boolean |
Returns
BooleanSchema_2<TSchema>
boolean()
boolean<TSchema>(): BooleanSchema_2<TSchema>;Generates a schema object that matches a boolean data type (as well as the strings 'true' and 'false'). Can also be called via bool().
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | boolean |
Returns
BooleanSchema_2<TSchema>
build()
build(...args: any[]): any;Unsure, maybe alias for compile?
Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
any
checkPreferences()
checkPreferences(prefs: ValidationOptions): void;Checks if the provided preferences are valid.
Throws an exception if the prefs object is invalid.
The method is provided to perform inputs validation for the any.validate() and any.validateAsync() methods. Validation is not performed automatically for performance reasons. Instead, manually validate the preferences passed once and reuse.
Parameters
| Parameter | Type |
|---|---|
prefs | ValidationOptions |
Returns
void
compile()
compile(schema: SchemaLike_2, options?: CompileOptions): Schema_2;Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
Parameters
| Parameter | Type |
|---|---|
schema | SchemaLike_2 |
options? | CompileOptions |
Returns
Schema_2
custom()
custom(fn: CustomValidator, description?: string): Schema_2;Creates a custom validation schema.
Parameters
| Parameter | Type |
|---|---|
fn | CustomValidator |
description? | string |
Returns
Schema_2
date()
date<TSchema>(): DateSchema_2<TSchema>;Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | Date |
Returns
DateSchema_2<TSchema>
defaults()
defaults(fn: SchemaFunction_2): Root;Creates a new Joi instance that will apply defaults onto newly created schemas through the use of the fn function that takes exactly one argument, the schema being created.
Parameters
| Parameter | Type | Description |
|---|---|---|
fn | SchemaFunction_2 | The function must always return a schema, even if untransformed. |
Returns
Root
disallow()
disallow(...values: any[]): Schema_2;Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
equal()
equal(...values: any[]): Schema_2;Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
exist()
exist(): Schema_2;Alias of required.
Returns
Schema_2
expression()
expression(template: string, options?: ReferenceOptions): any;Generates a dynamic expression using a template string.
Parameters
| Parameter | Type |
|---|---|
template | string |
options? | ReferenceOptions |
Returns
any
extend()
extend(...extensions: (
| Extension
| ExtensionFactory)[]): any;Creates a new Joi instance customized with the extension(s) you provide included.
Parameters
| Parameter | Type |
|---|---|
...extensions | ( | Extension | ExtensionFactory)[] |
Returns
any
forbidden()
forbidden(): Schema_2;Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
Returns
Schema_2
func()
func<TSchema>(): FunctionSchema_2<TSchema>;Generates a schema object that matches a function type.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | Function |
Returns
FunctionSchema_2<TSchema>
function()
function<TSchema>(): FunctionSchema_2<TSchema>;Generates a schema object that matches a function type.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | Function |
Returns
FunctionSchema_2<TSchema>
in()
in(ref: string, options?: ReferenceOptions): Reference;Creates a reference that when resolved, is used as an array of values to match against the rule.
Parameters
| Parameter | Type |
|---|---|
ref | string |
options? | ReferenceOptions |
Returns
invalid()
invalid(...values: any[]): Schema_2;Blacklists a value
Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
isError()
isError(error: any): error is ValidationError_2;Checks whether or not the provided argument is an instance of ValidationError
Parameters
| Parameter | Type |
|---|---|
error | any |
Returns
error is ValidationError_2
isExpression()
isExpression(expression: any): boolean;Checks whether or not the provided argument is an expression.
Parameters
| Parameter | Type |
|---|---|
expression | any |
Returns
boolean
isRef()
isRef(ref: any): ref is Reference;Checks whether or not the provided argument is a reference. It's especially useful if you want to post-process error messages.
Parameters
| Parameter | Type |
|---|---|
ref | any |
Returns
ref is Reference
isSchema()
isSchema(schema: any, options?: CompileOptions): schema is AnySchema_2<any>;Checks whether or not the provided argument is a joi schema.
Parameters
| Parameter | Type |
|---|---|
schema | any |
options? | CompileOptions |
Returns
schema is AnySchema_2<any>
link()
link<TSchema>(ref?: string): LinkSchema_2<TSchema>;Links to another schema node and reuses it for validation, typically for creative recursive schemas.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
Parameters
| Parameter | Type | Description |
|---|---|---|
ref? | string | the reference to the linked schema node. Cannot reference itself or its children as well as other links. Links can be expressed in relative terms like value references (Joi.link('...')), in absolute terms from the schema run-time root (Joi.link('/a')), or using schema ids implicitly using object keys or explicitly using any.id() (Joi.link('#a.b.c')). |
Returns
LinkSchema_2<TSchema>
not()
not(...values: any[]): Schema_2;Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
number()
number<TSchema>(): NumberSchema_2<TSchema>;Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | number |
Returns
NumberSchema_2<TSchema>
object()
object<TSchema, IsStrict, T>(schema?: SchemaMap_2<T, IsStrict>): ObjectSchema_2<TSchema>;Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | any |
IsStrict | false |
T | TSchema |
Parameters
| Parameter | Type |
|---|---|
schema? | SchemaMap_2<T, IsStrict> |
Returns
ObjectSchema_2<TSchema>
optional()
optional(): Schema_2;Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
Returns
Schema_2
options()
options(...args: any[]): any;Unsure, maybe alias for preferences?
Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
any
preferences()
preferences(options: ValidationOptions): Schema_2;Overrides the global validate() options for the current key and any sub-key.
Parameters
| Parameter | Type |
|---|---|
options | ValidationOptions |
Returns
Schema_2
prefs()
prefs(options: ValidationOptions): Schema_2;Overrides the global validate() options for the current key and any sub-key.
Parameters
| Parameter | Type |
|---|---|
options | ValidationOptions |
Returns
Schema_2
ref()
ref(key: string, options?: ReferenceOptions): Reference;Generates a reference to the value of the named key.
Parameters
| Parameter | Type |
|---|---|
key | string |
options? | ReferenceOptions |
Returns
required()
required(): Schema_2;Marks a key as required which will not allow undefined as value. All keys are optional by default.
Returns
Schema_2
string()
string<TSchema>(): StringSchema_2<TSchema>;Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | string |
Returns
StringSchema_2<TSchema>
symbol()
symbol<TSchema>(): SymbolSchema_2<TSchema>;Generates a schema object that matches any symbol.
Type Parameters
| Type Parameter | Default type |
|---|---|
TSchema | Symbol |
Returns
SymbolSchema_2<TSchema>
trace()
trace(...args: any[]): any;Unsure, maybe leaked from @hapi/lab/coverage/initialize
Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
any
types()
types(): {
alternatives: AlternativesSchema_2;
any: AnySchema_2;
array: ArraySchema_2;
binary: BinarySchema_2;
boolean: BooleanSchema_2;
date: DateSchema_2;
function: FunctionSchema_2;
link: LinkSchema_2;
number: NumberSchema_2;
object: ObjectSchema_2;
string: StringSchema_2;
symbol: SymbolSchema_2;
};Returns an object where each key is a plain joi schema type. Useful for creating type shortcuts using deconstruction. Note that the types are already formed and do not need to be called as functions (e.g. string, not string()).
Returns
{
alternatives: AlternativesSchema_2;
any: AnySchema_2;
array: ArraySchema_2;
binary: BinarySchema_2;
boolean: BooleanSchema_2;
date: DateSchema_2;
function: FunctionSchema_2;
link: LinkSchema_2;
number: NumberSchema_2;
object: ObjectSchema_2;
string: StringSchema_2;
symbol: SymbolSchema_2;
}| Name | Type |
|---|---|
alternatives | AlternativesSchema_2 |
any | AnySchema_2 |
array | ArraySchema_2 |
binary | BinarySchema_2 |
boolean | BooleanSchema_2 |
date | DateSchema_2 |
function | FunctionSchema_2 |
link | LinkSchema_2 |
number | NumberSchema_2 |
object | ObjectSchema_2 |
string | StringSchema_2 |
symbol | SymbolSchema_2 |
untrace()
untrace(...args: any[]): any;Parameters
| Parameter | Type |
|---|---|
...args | any[] |
Returns
any
valid()
valid(...values: any[]): Schema_2;Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
Parameters
| Parameter | Type |
|---|---|
...values | any[] |
Returns
Schema_2
when()
Call Signature
when(ref: string | Reference, options:
| WhenOptions<any, any>
| WhenOptions<any, any>[]): AlternativesSchema_2;Converts the type into an alternatives type where the conditions are merged into the type definition where:
Parameters
| Parameter | Type |
|---|---|
ref | string | Reference |
options | | WhenOptions<any, any> | WhenOptions<any, any>[] |
Returns
AlternativesSchema_2
Call Signature
when(ref: Schema_2, options: WhenSchemaOptions): AlternativesSchema_2;Parameters
| Parameter | Type |
|---|---|
ref | Schema_2 |
options | WhenSchemaOptions |
Returns
AlternativesSchema_2
x()
x(template: string, options?: ReferenceOptions): any;Generates a dynamic expression using a template string.
Parameters
| Parameter | Type |
|---|---|
template | string |
options? | ReferenceOptions |
Returns
any