ValidationPipe

  
class ValidationPipe implements PipeTransform {
  protected isTransformEnabled: boolean
  protected isDetailedOutputDisabled?: boolean
  protected validatorOptions: ValidatorOptions
  protected transformOptions: ClassTransformOptions | undefined
  protected errorHttpStatusCode: ErrorHttpStatusCode
  protected expectedType: Type<any> | undefined
  protected exceptionFactory: (errors: ValidationError[]) => any
  protected validateCustomDecorators: boolean
  protected loadValidator(validatorPackage?: ValidatorPackage): ValidatorPackage
  protected loadTransformer(transformerPackage?: TransformerPackage): TransformerPackage
  transform(value: any, metadata: ArgumentMetadata)
  createExceptionFactory()
  protected toValidate(metadata: ArgumentMetadata): boolean
  protected transformPrimitive(value: any, metadata: ArgumentMetadata)
  protected toEmptyIfNil<T = any, R = T>(value: T, metatype: object | Type<unknown>): R | object | string
  protected stripProtoKeys(value: any)
  protected isPrimitive(value: unknown): boolean
  protected validate(object: object, validatorOptions?: ValidatorOptions): Promise<ValidationError[]> | ValidationError[]
  protected flattenValidationErrors(validationErrors: ValidationError[]): string[]
  protected mapChildrenToValidationErrors(error: ValidationError, parentPath?: string): ValidationError[]
  protected prependConstraintsWithParentProp(parentPath: string, error: ValidationError): ValidationError
}

See also

Properties

Property Description
protected isTransformEnabled: boolean
protected isDetailedOutputDisabled?: boolean
protected validatorOptions: ValidatorOptions
protected transformOptions: ClassTransformOptions | undefined
protected errorHttpStatusCode: ErrorHttpStatusCode
protected expectedType: Type<any> | undefined
protected exceptionFactory: (errors: ValidationError[]) => any
protected validateCustomDecorators: boolean

Methods

loadValidator()


protected loadValidator(validatorPackage?: ValidatorPackage): ValidatorPackage

Parameters

Option Type Description
validatorPackage ValidatorPackage

Optional. Default is undefined.

Returns

ValidatorPackage

loadTransformer()


protected loadTransformer(transformerPackage?: TransformerPackage): TransformerPackage

Parameters

Option Type Description
transformerPackage TransformerPackage

Optional. Default is undefined.

Returns

TransformerPackage

transform()


transform(value: any, metadata: ArgumentMetadata)

Parameters

Option Type Description
value any
metadata ArgumentMetadata

createExceptionFactory()


createExceptionFactory()

Parameters

There are no parameters.

toValidate()


protected toValidate(metadata: ArgumentMetadata): boolean

Parameters

Option Type Description
metadata ArgumentMetadata

Returns

boolean

transformPrimitive()


protected transformPrimitive(value: any, metadata: ArgumentMetadata)

Parameters

Option Type Description
value any
metadata ArgumentMetadata

toEmptyIfNil()


protected toEmptyIfNil<T = any, R = T>(value: T, metatype: object | Type<unknown>): R | object | string

Parameters

Option Type Description
value T
metatype object | Type

Returns

R | object | string

stripProtoKeys()


protected stripProtoKeys(value: any)

Parameters

Option Type Description
value any

isPrimitive()


protected isPrimitive(value: unknown): boolean

Parameters

Option Type Description
value unknown

Returns

boolean

validate()


protected validate(object: object, validatorOptions?: ValidatorOptions): Promise<ValidationError[]> | ValidationError[]

Parameters

Option Type Description
object object
validatorOptions ValidatorOptions

Optional. Default is undefined.

Returns

Promise<ValidationError[]> | ValidationError[]

flattenValidationErrors()


protected flattenValidationErrors(validationErrors: ValidationError[]): string[]

Parameters

Option Type Description
validationErrors ValidationError[]

Returns

string[]

mapChildrenToValidationErrors()


protected mapChildrenToValidationErrors(error: ValidationError, parentPath?: string): ValidationError[]

Parameters

Option Type Description
error ValidationError
parentPath string

Optional. Default is undefined.

Returns

ValidationError[]

prependConstraintsWithParentProp()


protected prependConstraintsWithParentProp(parentPath: string, error: ValidationError): ValidationError

Parameters

Option Type Description
parentPath string
error ValidationError

Returns

ValidationError