Skip to content

ValidationPipe-specific options are included in validatorOptions and trigger classToPlain #17398

Description

@coxxny

Is there an existing issue for this?

  • I have searched the existing issues

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

  1. Clone the reproduction repository.
  2. Run npm install.
  3. Run npm test.
  4. Observe that the baseline subtest passes, while the subtests using only exceptionFactory, validatorPackage, or transformerPackage fail.
  5. 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?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs triageThis issue has not been looked into

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions