swagger: @Body() decorator with param broke swagger, swagger plugin auto @ApiProperty() doesn't work
I’m submitting a…
[ x ] Regression
[ x ] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Current behavior
I faced 2 issues when I use NestCLI to start my application with swagger plugin in nest-cli.json:
@Body('param')is not part of the request, I have to write wrapper DTO or use schema- The auto
@ApiProperty()doesn’t work. I have to use @ApiProperty in all of my DTO files.
I tried to reproduce nest-example-cats-swagger in my own repository, but it doesn’t work like the Docs mentions here
Expected behavior
- When I use
@Body('param'), swagger maybe could wrap the type inside that parameter name.
@Post('noDoc/param/scheme')
@ApiBody({
schema: {
type: 'object',
properties: {
user: { // the `user` word comes from @Body('user')
properties: { // these properties are coming from `UserDto`
id: { type: 'number' },
username: { type: 'string' },
email: { type: 'string' },
},
},
},
},
})
async noDocParamScheme(@Body('user') user: UserDto) {
return user;
}
- Swagger plugin should properly create
@ApiProperty
Minimal reproduction of the problem with instructions
You can check it in my test-repository: https://github.com/PoOwAa/nestjs-swagger-body-param-bug
What is the motivation / use case for changing the behavior?
At least @Body() without params should work like in the documentation.
Environment
[System Information]
OS Version : Linux 5.3
NodeJS Version : v12.16.1
NPM Version : 6.14.4
[Nest CLI]
Nest CLI Version : 7.1.2
[Nest Platform Information]
platform-express version : 7.0.0
swagger version : 4.5.1
common version : 7.0.0
core version : 7.0.0
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 26
- Comments: 21
@PoOwAa , i basically had this issue after trying to create a new decorator for a paginated response, following the steps in this docs page and the error I had was complaining about PaginatedDto schema which couldn’t be resolved, so I added the extraModels in swagger main configuration with PaginatedDto, it looked like this:
I had the same issue and could resolve it by including ExtraModels to swagger main configuration: docs
I was following along with the docs on using a Generic schema + using the CLI Plugin. This was giving me the circular dep error that @ankibalyan mentioned above. I was able to fix this by manually setting an
@ApiPropertyfor the generic property, soPaginatedDtowould look like this:It’s works for me!
I also have same issue
Exact same problem here, need to use @ApiProperty() directly for it to work.
having the same issue, swagger-cli does not work as expected.
I also have same issue
I also have same issue
I also have this issue.
I’m encountering the same behavior as well.
I also have same issue