Skip to content

Adding @ApiFoundResponse on a dynamic redirect method still renders a 200 response code in the OpenAPI contract #1639

@adworacz

Description

@adworacz

Is there an existing issue for this?

  • I have searched the existing issues

Current behavior

It appears that the Swagger CLI is adding an extra 200 response code to a method that will never return a 200 response. Specifically, for a method that always returns a dynamic redirect that's been labeled with @ApiFoundResponse

Example:

  interface RedirectResponse {
    url: string
    statusCode?: number
  }

  @Get()
  @ApiFoundResponse({ description: 'Redirects to a URL' })
  @Redirect()
  getRedirect(): RedirectResponse {
    return {
      url: `https://example.com`,
      statusCode: HttpStatus.FOUND,
    }
  }

Which produces:

  "/example": {
      "get": {
        ...
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "302": {
            "description": "Redirects to a URL"
          }
        }
      }

Minimum reproduction code

See above.

Steps to reproduce

See above.

Expected behavior

Only a single response is rendered - no 200 for a redirect.

Package version

5.1.3

NestJS version

8.0.11

Node.js version

14

In which operating systems have you tested?

  • macOS
  • Windows
  • Linux

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions