Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions packages/common/pipes/validation.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ export class ValidationPipe implements PipeTransform<any> {
errorHttpStatusCode,
expectedType,
transformOptions,
exceptionFactory,
validatorPackage,
transformerPackage,
validateCustomDecorators,
...validatorOptions
} = options;
Expand All @@ -81,11 +84,10 @@ export class ValidationPipe implements PipeTransform<any> {
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(
Expand Down
28 changes: 28 additions & 0 deletions packages/common/test/pipes/validation.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});