Nest: ValidationPipe is no longer allowing Transformer Pipes to work with classes

Created on 3 Oct 2019  路  4Comments  路  Source: nestjs/nest

Regression

The validation pipe is doing extra check since 6.6.7 that breaks the ability to use Transformer pipes in @Param decorator, as suggested in the official documentation here.

@Get(':id')
findOne(@Param('id', UserByIdPipe) userEntity: UserEntity) {
  return userEntity;
}

When UserEntity is a class, this code above works in 6.6.6 but triggers Bad Request in 6.6.7

Potential Commit/PR that introduced the regression**

https://github.com/nestjs/nest/commit/d4bb43009b0d34480fe414baff2940bc11f913a8

Describe the regression

Transformer pipes allow to transform the input value (here a string) to an output value (here a UserEntity so the controller will always receive an entity. This is a very powerful approach to keep controllers simple.

With the addition of the extra check, the ValidationPipe is triggering a Bad Request exception when the output type is a class and the input type does not match its type.

Input Code

yarn test:e2e is all green on master but fails on branch v6.6.7_ko
https://github.com/nlenepveu/nest-validation-pipe-regression/
https://github.com/nlenepveu/nest-validation-pipe-regression/compare/v6.6.7_ko

Expected behavior/code

Remove the extra check, or add a config option to the ValidationPipe to not validate the meta-type. I will be happy to help here.

Environment


Nest version: 6.6.6 -> 6.6.7

For Tooling issues:

  • Node version: 12.9
  • Platform: Linux
needs triage type

All 4 comments

Fixed in 6.8.1. Please, let me know if you face any issue

@kamilmysliwiec working perfectly, thank you.

Thanks @kamilmysliwiec !

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

j picture j  路  32Comments

BrunnerLivio picture BrunnerLivio  路  40Comments

xmlking picture xmlking  路  28Comments

weeco picture weeco  路  28Comments

chaostheory picture chaostheory  路  34Comments