FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: honour external package's Go name for direct response refs (#2423) · oapi-codegen/oapi-codegen@2ec2dc6 · GitHub

Commit 2ec2dc6

Browse files
andauthored
fix: honour external package's Go name for direct response refs (#2423)
Closes: #2422 When a base spec references a response defined in an external file directly (`$ref: 'spec-ext.yaml#/components/responses/Outcome'`, not via a path item) and that response is renamed in the external package via `x-go-name`, the generated `client-with-responses` wrapper pointed at the raw component name. The imported package declares the renamed model (e.g. `OutcomeResult`), so the base client referenced an undefined `externalRef0.Outcome` and failed to compile. GetResponseTypeDefinitions resolved external response names with RefPathToGoType / resolvedNameForRefPath, which key off the root spec and the raw component name; neither consults the external component's `x-go-name`. The #2308 fix already resolved this for externally-ref'd *path items* by reading the name from the resolved response value's context. This unifies that branch to also cover direct external refs: the imported package is detected via the path item's ref (relative response) or the response ref itself (direct), and the model name honours `x-go-name` the same way the external package generated it. Behaviour is unchanged for direct external refs without `x-go-name`: resolvedNameForRefPath already returns "" for non-`#/` refs, so the previous path also fell back to `<name> + mediaTypeSuffix`. The strict-server response envelope (`<name>JSONResponse`) ignores `x-go-name` on both sides and is unaffected. The cross-package collision-rename case noted in #2422 remains out of scope: it is unrecoverable without resolving the external document, and affects all external refs equally. A regression test is added under internal/test/issues/issue-2422. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 5b7f232 commit 2ec2dc6

11 files changed

Lines changed: 496 additions & 10 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
# yaml-language-server: $schema=../../../../configuration-schema.json
3+
package: spec_base
4+
generate:
5+
client: true
6+
models: true
7+
import-mapping:
8+
spec-ext.yaml: "github.com/oapi-codegen/oapi-codegen/v2/internal/test/issues/issue-2422/gen/spec_ext"
9+
output: gen/spec_base/issue.gen.go
10+
output-options:
11+
skip-prune: true
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
# yaml-language-server: $schema=../../../../configuration-schema.json
3+
package: spec_ext
4+
generate:
5+
client: true
6+
models: true
7+
output: gen/spec_ext/issue.gen.go
8+
output-options:
9+
skip-prune: true
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package issue2422
2+
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.ext.yaml spec-ext.yaml
4+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.base.yaml spec-base.yaml

‎internal/test/issues/issue-2422/gen/spec_base/.gitempty‎

Whitespace-only changes.

‎internal/test/issues/issue-2422/gen/spec_base/issue.gen.go‎

Lines changed: 262 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎internal/test/issues/issue-2422/gen/spec_ext/.gitempty‎

Whitespace-only changes.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL