Closed YakovL closed 1 year ago
1) swagger doesn't validate the DTO. That comes from the user of the ValidationPipe
and the class-validator
decorators
2) you should use PickType
from @nestjs/swagger
instead of @nestjs/mapped-types
to ensure the swagger metadata is propagated as expected
@jmcdo29 thanks, switching to PickType
from @nestjs/swagger
helped (I've pushed the fix ae8d224 to the same repo).
In the MCVE repo, there was also no global validation enabled, I've added it in a separate commit (2956d1b).
Is there an existing issue for this?
Current behavior
I've implemented a "rename project" endpoint which looks like this:
and
UpdateProjectNameParamsDto
looks like this:This worked fine (the endpoint works, swagger shows what's expected ..well, except for swagger doesn't validate
IsUUID
and if I send a string that's not UUID, I'm getting a 500 error instead of.. 400? and a helpful error message; but this is not the main issue).I've noticed that we already have
So, I decided to reuse those and tried instead (looking at the docs):
and
The result is.. unexptected: while the same request still works as previously, Swagger now shows that the endpoint has no params!
Minimum reproduction code
https://github.com/YakovL/nest-typescript-starter/tree/swagger-dto-mcve
Steps to reproduce
Note: in the mcve, I've used Get instead of Patch, just for simplicity; the bug affects Get, too.
git clone https://github.com/YakovL/nest-typescript-starter.git
,cd nest-typescript-starter
git checkout swagger-dto-mcve
npm i
,npm run start:dev
git checkout a09d1c3
Expected behavior
Both for
HEAD
and fora09d1c3
, the endpoint responds with a line that tellssomeId
andsomeName
were passed, and swagger shows that the endpoint has 2 params.Package
Other package
May be @nestjs/swagger, @nestjs/mapped-types; less likely class-validator
NestJS version
10.2.6
Packages versions
Node.js version
18.16.0
In which operating systems have you tested?
Other
No response