Commit 9efd95a
Parse declared response headers into typed fields on client response wrappers (oapi-codegen#2462)
Closes: oapi-codegen#2011
Response headers declared in the spec were dropped by the generated
client: the response wrapper exposed only the body fields, leaving
declared headers reachable solely through the raw http.Response. The
strict server already generates typed header structs and writes them in
its Visit* methods; the client had no equivalent on the read side.
Each response that declares headers now generates a client-local struct
named after the response wrapper (e.g. GetFooResponse200Headers), and
the wrapper gains a matching Headers<StatusCode> pointer field
(Headers200, HeadersDefault, ...) populated by Parse<Op>Response using
runtime.BindStyledParameterWithOptions with ParamLocationHeader
("simple" style, per the OpenAPI spec for response headers). Deriving
the type name from the wrapper (via genResponseTypeName) keeps it
collision-resolver-aware, and the types are emitted and consumed
entirely within the client output, independent of the strict server's
<Op><Status>ResponseHeaders types.
Binding is lenient: an absent header - even a required one - leaves the
field at its zero value rather than failing the parse, mirroring the
body unmarshal's tolerance of spec-violating servers; a present header
that fails to bind to its declared type is an error. Case clauses are
ordered most-specific-first (exact codes, then range wildcards, then
default) by the same lexicographic scheme the body unmarshal uses.
The change is purely additive: specs without response headers generate
byte-identical output, and no strict-server or model output changes.
Co-authored-by: Claude Fable 5 <[email protected]>1 parent 28e0964 commit 9efd95a
12 files changed
Lines changed: 840 additions & 0 deletions
File tree
- internal/test
- clients/responseheaders
- naming/conflicts
- references/multipackage/pruned_deps
- schemas/deprecated
- servers/strict/client
- pkg/codegen
- templates
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments