question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

@Body() decorator with param broke swagger, swagger plugin auto @ApiProperty() doesn't work

See original GitHub issue

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:

  1. @Body('param') is not part of the request, I have to write wrapper DTO or use schema
  2. 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

  1. 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;
  }
  1. 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:open
  • Created 3 years ago
  • Reactions:23
  • Comments:19

github_iconTop GitHub Comments

5reactions
Akhouadcommented, May 26, 2022

@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:

const document = SwaggerModule.createDocument(app, config, {
  extraModels: [PaginatedDto]
});
4reactions
Akhouadcommented, May 26, 2022

I had the same issue and could resolve it by including ExtraModels to swagger main configuration: docs

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found