| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Closes: oapi-codegen#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 oapi-codegen#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 oapi-codegen#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>
Greptile SummaryThis PR fixes response-wrapper type resolution for direct external response references. The main changes are:
Confidence Score: 5/5This looks safe to merge.
Important Files Changed
Reviews (1): Last reviewed commit: "fix: honour external package's Go name f..." | Re-trigger Greptile |
Sorry, something went wrong.
…-codegen#2423) Closes: oapi-codegen#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 oapi-codegen#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 oapi-codegen#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>
| Back | FazBrowse Home | New Git URL |
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.