You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing headers in responses when generating clients #2011
Hey team! I have been trying out oapi-codegen, and it's a fantastic tool. Thanks a lot for putting this effort in.
While trying it out, I have discovered an interesting behaviour that I would like to determine if it's a bug or a design decision.
When generating a client from a spec that define headers as part of it's response, the generated client response skips the aforementioned headers in the generated response struct.
This is actually a pretty significant change to fix, as we don't automatically marshal required headers or cookies, just bodies and params.
To date, when returning response headers, I've always just put them into the response builder in the HTTP router that I was using, without relying on oapi-codegen to do so. It's hard to do automatically, because we'd need to provide you with a callback to provide header values or something. I'm not entirely sure on how to do it cleanly.
I'm working on an experimental PR which moves the response definitions in to the models component of the generator (they're currently bundled with the strict-server), and seeing what the fallout looks like. It does appear that it might be possible to reorganize this code without breaking existing consumers. It'll be additive for people not using the strict-server, but it does change where type definitions end up if you split your spec output across multiple directories.
Edit: That was the wrong approach, it was too complex. The change can be contained just to the client code.
Activity
MrwanBaghdad commentedon Jun 27, 2025
MrwanBaghdad@1be7f75
mromaszewicz commentedon Jul 9, 2026
This is a bug. This functionality is simply unimplemented.
mromaszewicz commentedon Jul 9, 2026
This is actually a pretty significant change to fix, as we don't automatically marshal required headers or cookies, just bodies and params.
To date, when returning response headers, I've always just put them into the response builder in the HTTP router that I was using, without relying on
oapi-codegento do so. It's hard to do automatically, because we'd need to provide you with a callback to provide header values or something. I'm not entirely sure on how to do it cleanly.mromaszewicz commentedon Jul 13, 2026
I'm working on an experimental PR which moves the response definitions in to the
modelscomponent of the generator (they're currently bundled with the strict-server), and seeing what the fallout looks like. It does appear that it might be possible to reorganize this code without breaking existing consumers. It'll be additive for people not using the strict-server, but it does change where type definitions end up if you split your spec output across multiple directories.Edit: That was the wrong approach, it was too complex. The change can be contained just to the client code.
Parse declared response headers into typed fields on client response …
Parse declared response headers into typed fields on client response …