0

I have a simple nest controller with validation pipe decorator


import {GetCatDto} from 'my-shared-lib'

@Controller('myController')
export class MyController {
  constructor(private readonly policyManagerService: PolicyManagerService) {}

  @Get()
  @UsePipes(new ValidationPipe({ transform: true }))
  getCat(@Query() getCatDto: GetCatDto) {
    return this.catService.getcates(getCatDto);
  }

in the shared lib (imported using npm link) :

export class getCatDto {
  @Expose({ name: 'cat_name' })
  catName: string;
}

if I send the following get request : GET localhost:3000/myController?Cat-Name=mycat I don't get validation error.

BUT.. If I copy/paste the dto into my project (i.e in the same file as the controller). the validation works as expected.

at first I thought it might be be related to this issue but my tsconfig.json includes the mentioned headers.

I'm using nest.js 8.0.0 and class-validator 0.13.2

Lior Baber
  • 852
  • 3
  • 11
  • 25
  • change `http://localhost:3000/myController?Cat-Name=mycat` --> to `http://localhost:3000/myController?cat_name=mycat` – Empty Brain Jan 18 '22 at 17:51
  • I wanted to give an example of something that violates the name as it is written in the "Expose" decorator – Lior Baber Jan 19 '22 at 18:26

1 Answers1

0

So it turns out the main issue was due to the fact that the class-transformer version in my shared lib was not exactly the same as it was in my service. once I straightened that up it worked as expected. This is mentioned in this Github Issue

Lior Baber
  • 852
  • 3
  • 11
  • 25