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

"headers" property for responses is not generated in swagger #170

Closed
ThomasKruegl opened this issue Oct 11, 2017 · 4 comments
Closed

"headers" property for responses is not generated in swagger #170

ThomasKruegl opened this issue Oct 11, 2017 · 4 comments
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted

Comments

@ThomasKruegl
Copy link

Hi,

we are trying to use tsoa to generate a swagger specification for our API. We are running into several issues, here is one of them.
There are other issues here on github regarding the use of custom headers in responses. From what i have understood it is now possible to set custom headers, and this works fine for the generated routes.
But for the generated swagger, there is simply no way of getting the headers property created for responses right?

kind regards,
Thomas

@dgreene1
Copy link
Collaborator

I believe the answer is to use the @Request parameter decorator. I’ve added more information to the readme on how to use it. Once you have that (and have set the type to be either Express.Request or Koa.Request), you have the full ability to set the header in the same that you would have with pure Express or Koa.

As for declaring it in Swagger... I actually don’t know (I just recently joined as a maintainer).

So I’ll mark this issue as [help wanted] so that maybe someone can either:

  • tell us if there is a way to do this in tsoa
  • or add that functionality

My apologies for the delay in answering. We have new, additional maintainers who will be adding more support in the future.

@dgreene1 dgreene1 added good first issue This issue could be an easy PR for those looking to help contribute help wanted labels Aug 17, 2019
@ThomasKruegl
Copy link
Author

Currently i am working in a completely different environment, and don't have time to follow up on this. Just saying so you know i won't be able to test or do anything here.
But thanks for picking this up anyway :)

@sundowndev
Copy link

sundowndev commented Sep 30, 2020

Up, this is still relevant today. this.setHeader works for generated routes but doesn't write in the specs. So, from what I understand, for now it's impossible to change application/json response content type in the docs.

const stat: fs.Stats = await fs.promises.stat(filePath);

this.setStatus(200);
this.setHeader('Content-Type', 'application/pdf');
this.setHeader('Content-Length', stat.size.toString());

image

@WoH
Copy link
Collaborator

WoH commented Oct 1, 2020

Up, this is still relevant today. this.setHeader works for generated routes but doesn't write in the specs. So, from what I understand, for now it's impossible to change application/json response content type in the docs.

const stat: fs.Stats = await fs.promises.stat(filePath);

this.setStatus(200);
this.setHeader('Content-Type', 'application/pdf');
this.setHeader('Content-Length', stat.size.toString());

image

We can't guess how you set the headers at runtime. Closing this in favor of #770

@WoH WoH closed this as completed Oct 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue This issue could be an easy PR for those looking to help contribute help wanted
Projects
None yet
Development

No branches or pull requests

4 participants