diff --git a/packages/common/pipes/validation.pipe.ts b/packages/common/pipes/validation.pipe.ts index 3cd36769888..654e6c84791 100644 --- a/packages/common/pipes/validation.pipe.ts +++ b/packages/common/pipes/validation.pipe.ts @@ -68,6 +68,9 @@ export class ValidationPipe implements PipeTransform { errorHttpStatusCode, expectedType, transformOptions, + exceptionFactory, + validatorPackage, + transformerPackage, validateCustomDecorators, ...validatorOptions } = options; @@ -81,11 +84,10 @@ export class ValidationPipe implements PipeTransform { this.validateCustomDecorators = validateCustomDecorators || false; this.errorHttpStatusCode = errorHttpStatusCode || HttpStatus.BAD_REQUEST; this.expectedType = expectedType; - this.exceptionFactory = - options.exceptionFactory || this.createExceptionFactory(); + this.exceptionFactory = exceptionFactory || this.createExceptionFactory(); - classValidator = this.loadValidator(options.validatorPackage); - classTransformer = this.loadTransformer(options.transformerPackage); + classValidator = this.loadValidator(validatorPackage); + classTransformer = this.loadTransformer(transformerPackage); } protected loadValidator( diff --git a/packages/common/test/pipes/validation.pipe.spec.ts b/packages/common/test/pipes/validation.pipe.spec.ts index 3d54bf282dc..86de2593ea2 100644 --- a/packages/common/test/pipes/validation.pipe.spec.ts +++ b/packages/common/test/pipes/validation.pipe.spec.ts @@ -738,4 +738,32 @@ describe('ValidationPipe', () => { }); }); }); + describe('Issue #17398: when only ValidationPipe-specific options are provided', () => { + it('should return the original value when exceptionFactory is provided', async () => { + target = new ValidationPipe({ + exceptionFactory: () => new Error('custom'), + }); + const testObj = { prop1: 'value1', prop2: 'value2' }; + const result = await target.transform(testObj, metadata); + expect(result).to.equal(testObj); + }); + + it('should return the original value when validatorPackage is provided', async () => { + target = new ValidationPipe({ + validatorPackage: require('class-validator'), + }); + const testObj = { prop1: 'value1', prop2: 'value2' }; + const result = await target.transform(testObj, metadata); + expect(result).to.equal(testObj); + }); + + it('should return the original value when transformerPackage is provided', async () => { + target = new ValidationPipe({ + transformerPackage: require('class-transformer'), + }); + const testObj = { prop1: 'value1', prop2: 'value2' }; + const result = await target.transform(testObj, metadata); + expect(result).to.equal(testObj); + }); + }); });