@Body() decorator with param broke swagger, swagger plugin auto @ApiProperty() doesn't work
See original GitHub issueI’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
Issue Analytics
- State:
- Created 3 years ago
- Reactions:23
- Comments:19
Top Results From Across the Web
Nest + Swagger not recognizing endpoints or parameters
When I open my swagger docs I see all of the endpoints I expect but am having two issues: When I click on...
Read more >NestJS — The Hero We Didn't Know We Needed - SingleStone
We can fix this with Swagger decorators. Let's hop back into users.controllers.ts and add some in. import { Body, Controller, Get, ...
Read more >Operations - OpenAPI - A progressive Node.js framework
To define a custom HTTP response, use the @ApiResponse() decorator. ... If you run Swagger now, the generated swagger.json for this specific endpoint...
Read more >@darraghor/eslint-plugin-nestjs-typed - npm
Using Open Api / Swagger decorators and automatically generating a clients. When working with NestJS I generate my front end client and models ......
Read more >OpenAPI (Swagger) - 《Nest.js v7.0 Document》 - 书栈网
In addition, the @ApiProperty() decorator allows setting various Schema ... the Swagger plugin (see Plugin section) which will automatically ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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