Is there an existing issue for this?
Current behavior
When exceptionFactory, validatorPackage, or transformerPackage is passed to ValidationPipe, the option is included in the remaining validatorOptions.
As a result, specifying any one of them adds a second key alongside the default forbidUnknownValues value. This makes the following condition unexpectedly evaluate to true.
const shouldTransformToPlain =
Object.keys(this.validatorOptions).length > 1;
classToPlain is therefore executed even when no actual ValidatorOptions were specified.
Minimum reproduction code
https://github.com/coxxny/nest-validation-pipe-class-to-plain-repro/tree/import-fixed-package
Steps to reproduce
- Clone the reproduction repository.
- Run
npm install.
- Run
npm test.
- Observe that the baseline subtest passes, while the subtests using only
exceptionFactory, validatorPackage, or transformerPackage fail.
- In each failing subtest, the
secret property is removed because classToPlain was executed.
Expected behavior
exceptionFactory, validatorPackage, and transformerPackage should not be included in this.validatorOptions.
When one of these options is specified without any actual ValidatorOptions, classToPlain should not be executed and the pipe should return the original plain value.
NestJS version
11.1.28
Packages versions
"@nestjs/common": "11.1.28",
Node.js version
24.17.0
In which operating systems have you tested?
Other
No response
Is there an existing issue for this?
Current behavior
When
exceptionFactory,validatorPackage, ortransformerPackageis passed toValidationPipe, the option is included in the remainingvalidatorOptions.As a result, specifying any one of them adds a second key alongside the default
forbidUnknownValuesvalue. This makes the following condition unexpectedly evaluate totrue.classToPlainis therefore executed even when no actualValidatorOptionswere specified.Minimum reproduction code
https://github.com/coxxny/nest-validation-pipe-class-to-plain-repro/tree/import-fixed-package
Steps to reproduce
npm install.npm test.exceptionFactory,validatorPackage, ortransformerPackagefail.secretproperty is removed becauseclassToPlainwas executed.Expected behavior
exceptionFactory,validatorPackage, andtransformerPackageshould not be included inthis.validatorOptions.When one of these options is specified without any actual
ValidatorOptions,classToPlainshould not be executed and the pipe should return the original plain value.NestJS version
11.1.28
Packages versions
Node.js version
24.17.0
In which operating systems have you tested?
Other
No response