Commit 1e31932
Qualify external header schema refs in generated response headers (oapi-codegen#2463)
Closes: oapi-codegen#2060
When a response header is an external `$ref` (it lives in another file
mapped via import-mapping) and that header's schema is itself a `$ref`
to a named type, the generated response-headers struct referenced the
type by a bare local name (e.g. `ETag ETagSchema`) instead of the
imported one (`ETag externalRef0.ETagSchema`). Because the named type is
only generated into the imported package, the referencing package failed
to compile with an undefined `ETagSchema`.
The header's schema `$ref` is written relative to the external file
(e.g. `#/components/schemas/ETagSchema`), so `GenerateGoSchema` resolves
it against the root spec as a bare local name. Since the header component
carries its own `$ref` telling us which file it came from, qualify the
schema with that external package via `ensureExternalRefsInSchema`,
mirroring how response content schemas are already handled. This is
guarded on the schema being a reference so an external header with an
inline primitive schema (e.g. `type: string`) is not mangled into
`externalRef0.string`.
The fix corrects both the strict-server `<Op><Status>ResponseHeaders`
struct and the client response wrapper's header fields introduced in
oapi-codegen#2462.
Adds internal/test/references/multipackage/header_ref exercising an
external header ref with a ref'd schema across strict-server and client
generation; the committed generated files must compile as part of the
test module, which guards against the undefined-symbol regression.
Co-authored-by: Claude Fable 5 <[email protected]>1 parent 9efd95a commit 1e31932
9 files changed
Lines changed: 690 additions & 0 deletions
File tree
- internal/test/references/multipackage/header_ref
- common
- gen
- api
- common
- pkg/codegen
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
Lines changed: 12 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
0 commit comments