Skip to content

Missing headers in responses when generating clients #2011

Closed

Description

@MrwanBaghdad

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.

Example yaml

openapi: 3.0.2
info:
  version: "0.0.1"
paths:
  /foo:
    get:
      responses:
        200:
          description: "endpoint"
          headers:
            "bar":
              schema:
                type: string
          content:
            application/json:
              schema: 
                $ref: "#/components/schemas/data"
components:
  schemas:
    data:
      type: object
      properties:
        foo:
          type: string

Activity

  1. MrwanBaghdad commented on Jun 27, 2025

    @MrwanBaghdad
    Author
  2. mromaszewicz commented on Jul 9, 2026

    @mromaszewicz
    Member

    This is a bug. This functionality is simply unimplemented.

  3. added
    bug
    on Jul 9, 2026
  4. mromaszewicz commented on Jul 9, 2026

    @mromaszewicz
    Member

    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.

  5. mromaszewicz commented on Jul 13, 2026

    @mromaszewicz
    Member

    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.

  6. added 2 commits that reference this issue on Jul 13, 2026
    5a67112
    9efd95a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions