Skip to content

Support for response header documentation #181

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

Open
Kek5chen opened this issue Jun 11, 2025 · 4 comments
Open

Support for response header documentation #181

Kek5chen opened this issue Jun 11, 2025 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@Kek5chen
Copy link
Contributor

The OpenAPI Spec includes the possibility to provide information about (custom) headers passed through the responder of a handler, in actix_web usually that resolved to a HttpResponse(Builder) object. This is probably analogous to a feature on the #[api_operation] macro.

Currently there's the use case where you would like to document information about custom headers passed in the response, and I don't see the possibility to do this in any way.

@Kek5chen
Copy link
Contributor Author

I suppose one way would be to wrap the response in a wrapper type and manually implement Responder and ApiComponent, without using the derive macro as well.

That doesn't seem like a good intended way though for just supporting more options in the response documentation.

@rlebran
Copy link
Contributor

rlebran commented Jun 11, 2025

Hey, thanks for the report.

There is currently no acceptable way to document a response header, I will have a look at it.
Keeping you updated.

@rlebran
Copy link
Contributor

rlebran commented Jun 11, 2025

I see two possibilities here:

  • Have another parameter like response_header = ... on the #[api_operation] macro which allow to document response header
  • Have another parameter like response = ... on the #[api_operation] macro which allow to override the documentation for the response

The second one would allow to document response when the handler return an HttpResponse but might be a bit too verbose when all we want is to add a header to an already documented response.
We can possibly have both mutually exclusive.

WDYT ?

@Kek5chen
Copy link
Contributor Author

My thoughts on the syntax went into a similar direction. Though I see a pattern here.

The produces and error_code attributes are both also part of a broader response pattern.

I think introducing all of these fields under a response field would make the api cleaner and would allow for even more future expansion in case people would like to document other response related things. For example cookies? (which also aligns pretty tight with this issue, just to keep it close mentally).

Maybe there's even more things that a response would turn opaque, and there's no proper way to make these all known since an HttpResponse object is extremely flexible and we can't inspect it later on runtime.

One extremely cursed thing that'd also be possible is to introspection the full path of any function ident in the proc macro, and extract the arguments, including any header names. But I can see how that doesn't hold stably in any way and completely disregards non-static variables passed into header insertion functions.

TLDR; I'd go with a response attribute and move response related things in there, as well as expand it in the future.

@rlebran rlebran self-assigned this Jun 12, 2025
@rlebran rlebran added the enhancement New feature or request label Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants