@@ -6,13 +6,15 @@ import {
66 ValidationError ,
77} from '../index' ;
88import { ValidatorOptions } from '../interfaces/external/validator-options.interface' ;
9+ import { ClassTransformOptions } from '../interfaces/external/class-transform-options.interface' ;
910import { PipeTransform } from '../interfaces/features/pipe-transform.interface' ;
1011import { loadPackage } from '../utils/load-package.util' ;
1112import { isNil } from '../utils/shared.utils' ;
1213
1314export interface ValidationPipeOptions extends ValidatorOptions {
1415 transform ?: boolean ;
1516 disableErrorMessages ?: boolean ;
17+ transformOptions ?: ClassTransformOptions ;
1618 exceptionFactory ?: ( errors : ValidationError [ ] ) => any ;
1719}
1820
@@ -24,13 +26,20 @@ export class ValidationPipe implements PipeTransform<any> {
2426 protected isTransformEnabled : boolean ;
2527 protected isDetailedOutputDisabled ?: boolean ;
2628 protected validatorOptions : ValidatorOptions ;
29+ protected transformOptions : ClassTransformOptions ;
2730 protected exceptionFactory : ( errors : ValidationError [ ] ) => any ;
2831
2932 constructor ( @Optional ( ) options ?: ValidationPipeOptions ) {
3033 options = options || { } ;
31- const { transform, disableErrorMessages, ...validatorOptions } = options ;
34+ const {
35+ transform,
36+ disableErrorMessages,
37+ transformOptions,
38+ ...validatorOptions
39+ } = options ;
3240 this . isTransformEnabled = ! ! transform ;
3341 this . validatorOptions = validatorOptions ;
42+ this . transformOptions = transformOptions ;
3443 this . isDetailedOutputDisabled = disableErrorMessages ;
3544 this . exceptionFactory =
3645 options . exceptionFactory ||
@@ -52,6 +61,7 @@ export class ValidationPipe implements PipeTransform<any> {
5261 const entity = classTransformer . plainToClass (
5362 metatype ,
5463 this . toEmptyIfNil ( value ) ,
64+ this . transformOptions ,
5565 ) ;
5666 const errors = await classValidator . validate ( entity , this . validatorOptions ) ;
5767 if ( errors . length > 0 ) {
@@ -60,8 +70,8 @@ export class ValidationPipe implements PipeTransform<any> {
6070 return this . isTransformEnabled
6171 ? entity
6272 : Object . keys ( this . validatorOptions ) . length > 0
63- ? classTransformer . classToPlain ( entity )
64- : value ;
73+ ? classTransformer . classToPlain ( entity , this . transformOptions )
74+ : value ;
6575 }
6676
6777 private toValidate ( metadata : ArgumentMetadata ) : boolean {
0 commit comments