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

Support for response headers in generated OpenAPI spec #770

Closed
2 of 4 tasks
rhietala opened this issue Aug 4, 2020 · 1 comment · Fixed by #857
Closed
2 of 4 tasks

Support for response headers in generated OpenAPI spec #770

rhietala opened this issue Aug 4, 2020 · 1 comment · Fixed by #857

Comments

@rhietala
Copy link

rhietala commented Aug 4, 2020

Sorting

  • I'm submitting a ...

    • bug report
    • feature request
    • support request
  • I confirm that I

    • used the search to make sure that a similar issue hasn't already been submit

Expected Behavior

Using this kind of controller

interface ResponseHeaders {
  /**
   * Pagination uses Link header as defined in RFC5988
   */
  Link: string;
}

@Route("/")
export class FooController extends Controller {
  @Get()
  @SuccessHeaders<ResponseHeaders>()
  public async get(
    @Res() failed: TsoaResponse<400, string, ResponseHeaders>
  ): Promise<number> {
    if (false) {
      failed(400, "failure", { Link: "" });
    } else {
      this.setHeader("Link", '<https://localhost:3000/?page=2>; rel="next"');
      return 1;
    }
  }
}

It would be nice if the generated OpenAPI specification would have specifications for the response headers as well (as per https://swagger.io/specification/#response-object):

"paths": {
  "/": {
    "get": {
      "operationId": "Get",
      "responses": {
        "200": {
          "description": "Ok",
          "content": {
            "application/json": {
              "schema": {
                "type": "number",
                "format": "double"
              }
            }
          },
          "headers": {
            "Link": {
              "description": "Pagination uses Link header as defined in RFC5988",
              "schema": {
                "type": "string"
              }
            }
          }
        },
        "400": {
          "description": "",
          "content": {
            "application/json": {
              "schema": {
                "type": "string"
              }
            }
          },
          "headers": {
            "Link": {
              "description": "Pagination uses Link header as defined in RFC5988",
              "schema": {
                "type": "string"
              }
            }
          }
        }
      },
      "security": [],
      "parameters": []
    }
  }
},

I presumed @SuccessHeaders is an upcoming feature from #723.

Also, in real life it doesn't make sense to include the link header in error response, but I included it here just to illustrate that TsoaResponse should have the same functionality.

Current Behavior

Currently the generated specification has only the content schemas:

"paths": {
  "/": {
    "get": {
      "operationId": "Get",
      "responses": {
        "200": {
          "description": "Ok",
          "content": {
            "application/json": {
              "schema": {
                "type": "number",
                "format": "double"
              }
            }
          }
        },
        "400": {
          "description": "",
          "content": {
            "application/json": {
              "schema": {
                "type": "string"
              }
            }
          }
        }
      },
      "security": [],
      "parameters": []
    }
  }
},

Possible Solution

Steps to Reproduce

Working example repository https://github.com/rhietala/tsoa-response-header

Context (Environment)

Version of the library: 3.2.1
Version of NodeJS: 12.18.3

  • Confirm you were using yarn not npm: [x]

Detailed Description

Breaking change?

Probably not for @SuccessHeaders as is not in 3.x? For TsoaResponse probably not either, as this would only add the optional descriptions and spec generation as a new feature, but I don't know.

@WoH
Copy link
Collaborator

WoH commented Aug 6, 2020

I'd really like to have this in tsoa aswell. If you can open a PR I'd like to have a look.

@github-actions github-actions bot added the Stale label Sep 6, 2020
Repository owner deleted a comment from github-actions bot Sep 6, 2020
@WoH WoH added help wanted and removed Stale labels Sep 6, 2020
@github-actions github-actions bot added the Stale label Jan 8, 2021
@WoH WoH removed the Stale label Jan 8, 2021
Repository owner deleted a comment from github-actions bot Jan 8, 2021
@WoH WoH closed this as completed in #857 Jan 16, 2021
WoH added a commit that referenced this issue Jan 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants