Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Responses schema from @ApiOperation is not picked up #1420

Closed
tiholic opened this issue Jul 7, 2021 · 5 comments
Closed

Responses schema from @ApiOperation is not picked up #1420

tiholic opened this issue Jul 7, 2021 · 5 comments

Comments

@tiholic
Copy link
Contributor

tiholic commented Jul 7, 2021

I'm submitting a...


[ ] 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 want to create responses schema for returning file content.

The schema should be something as described here: https://swagger.io/docs/specification/describing-responses/#response-that-returns-a-file

Instead this gets returned from -json endpoint

{
  "/api/v2/download/": {
    "get": {
      "operationId": "HELO",
      "summary": "",
      "responses": {
        "200": {
          "description": ""
        }
      },
      "parameters": [],
      "tags": [
        "v2api"
      ],
      "security": [
        {
          "jwt": []
        }
      ]
    }
  }
}

Expected behavior

Expect responses to show schema as configured (see below snippet)

Minimal reproduction of the problem with instructions

Source code to replicate the issue:

@ApiBearerAuth('jwt')
@ApiTags('v2api')
@ApiExtraModels(
 Dto1, Dto2     // using for other purposes
)
export class APIController {

  // some other API controller methods

  @ApiOperation({
    operationId: 'HELO',
    responses: {
      '200': {
        description: 'download',
        content: {
          'application/pdf': {
            schema: {
              type: 'string',
              format: 'binary',
            },
          },
          'application/png': {
            schema: {
              type: 'string',
              format: 'binary',
            },
          },
        },
      },
    },
  })
  @Get('/download/')
  helo() {
    // TODO download
  }
}

Environment


Nest version: X.Y.Z
```
        "@nestjs/common": "7.4.2",
        "@nestjs/core": "7.4.2",
        "@nestjs/jwt": "7.1.0",
        "@nestjs/passport": "7.1.0",
        "@nestjs/platform-express": "7.4.2",
        "@nestjs/swagger": "4.8.1",
        "@nestjs/cli": "7.4.1"
```
 
For Tooling issues:
- Node version: v12.10.0
- Platform:  Mac

@kamilmysliwiec
Copy link
Member

Would you like to create a PR for this issue?

@tiholic
Copy link
Contributor Author

tiholic commented Jul 7, 2021

I haven't looked at the source yet!, But happy to contribute if you can point me where to look for the issue?

@kamilmysliwiec
Copy link
Member

Side question, any reason you don't want to use the @ApiResponse() decorator instead?

@tiholic
Copy link
Contributor Author

tiholic commented Jul 8, 2021

I want to configure multiple response content types. Download could be a PDF or Image or some other document type (document types are limited)

tiholic added a commit to tiholic/swagger that referenced this issue Jul 15, 2021
for example, prefer responses confgured in @ApiOperation instead of
what's detected from return type of the controller function

fixes: nestjs#1420
tiholic added a commit to tiholic/swagger that referenced this issue Jul 15, 2021
for example, responses confgured in @ApiOperation should be given
     preference over what's detected from return type of the controller function

fixes: nestjs#1420
@kamilmysliwiec
Copy link
Member

Let's track this here #1454

tiholic added a commit to tiholic/swagger that referenced this issue Oct 27, 2022
for example, responses confgured in @ApiOperation should be given
     preference over what's detected from return type of the controller function

fixes: nestjs#1420
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants