nestjs / nest

A progressive Node.js framework for building efficient, scalable, and enterprise-grade server-side applications with TypeScript/JavaScript 🚀
https://nestjs.com
MIT License
66.91k stars 7.55k forks source link

ValidationPipe: an unknown value was passed to the validate function #9132

Closed rudemex closed 2 years ago

rudemex commented 2 years ago

Is there an existing issue for this?

Current behavior

Sending the correct parameters through the body in a PUT or PATCH returns a 400 Bad Request status with the message "an unknown value was passed to the validate function". Captura de Pantalla 2022-02-10 a la(s) 12 12 04 a  m

Minimum reproduction code

https://github.com/rudemex/nestjs-starter

Steps to reproduce

  1. git clone https://github.com/rudemex/nestjs-starter
  2. git checkout feat/docker
  3. npm install
  4. rename .env.example to .env
  5. npm run start:dev
  6. go to http://localhost:8080/docs/#/Users/UsersController_update
  7. Try PUT method with ID = 1 and change any value of schema
  8. see the response

Expected behavior

It is expected to validate the body data against the DTO and make the change with an ok status.

Package

Other package

@nestjs/class-transformer, @nestjs/class-validator, class-transformer

NestJS version

8.2.6

Packages versions

"@nestjs/class-transformer": "^0.4.0",
"@nestjs/class-validator": "^0.13.3",
"class-transformer": "^0.5.1",

Node.js version

14.15.4

In which operating systems have you tested?

Other

Global Pipe validation config

// ./src/main.ts

app.useGlobalPipes(
    new ValidationPipe({
      validatorPackage: require('@nestjs/class-validator'),
      transformerPackage: require('class-transformer'),
      //whitelist: true,
      forbidUnknownValues: true,
      forbidNonWhitelisted: true,
      transformOptions: {
        enableImplicitConversion: true,
      },
    }),
  );
kamilmysliwiec commented 2 years ago

Please, use our Discord channel (support) for such questions. We are using GitHub to track bugs, feature requests, and potential improvements.