fix: qualify response refs from externally-ref'd path items#2421
Merged
Conversation
Contributor
Greptile SummaryThis PR fixes response type qualification for externally referenced OpenAPI path items. The main changes are:
Confidence Score: 5/5This looks safe to merge.
|
| Filename | Overview |
|---|---|
| pkg/codegen/operations.go | Updates response type generation so relative response refs from external path items resolve through the imported package. |
| internal/test/issues/issue-2308/issue_test.go | Adds compile-time coverage for the external path-item response wrapper type. |
Reviews (4): Last reviewed commit: "fix: qualify response refs from external..." | Re-trigger Greptile
mromaszewicz
force-pushed
the
fix/issue-2308
branch
2 times, most recently
from
June 21, 2026 04:07
3258696 to
b200a65
Compare
Closes: oapi-codegen#2308 When a path item is referenced from an external file (an OpenAPI 3.1 `components.pathItems` entry referenced from `paths`), and its operation's response is in turn a `$ref` relative to that same external file (`#/components/responses/...`), the generated strict-server response struct embedded an unqualified type name. That type only exists in the imported package, so the generated code referenced an undefined symbol and failed to compile: type GetV1Version200JSONResponse struct{ VersionGetResponseJSONResponse } GenerateResponseDefinitions already tracks the external package of the path item (externalPkg) and applies that prefix to inline response content, but not to the response-is-a-`$ref` branch. There, RefPathToGoType returns a bare name for a `#/`-relative ref -- it cannot know the ref originated in an external file once the path item has been merged into the root document. Qualify the ref with externalPkg when the operation came from an external path item and the response ref is relative (`#`-prefixed). Refs that already target another file are qualified by RefPathToGoType, so those are left untouched to avoid double-prefixing. A regression test is added under internal/test/issues/issue-2308. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mromaszewicz
force-pushed
the
fix/issue-2308
branch
from
June 21, 2026 04:19
b200a65 to
4693b81
Compare
lwc
pushed a commit
to lwc/oapi-codegen
that referenced
this pull request
Jun 23, 2026
…egen#2421) Closes: oapi-codegen#2308 When a path item is referenced from an external file (an OpenAPI 3.1 `components.pathItems` entry referenced from `paths`), and its operation's response is in turn a `$ref` relative to that same external file (`#/components/responses/...`), the generated strict-server response struct embedded an unqualified type name. That type only exists in the imported package, so the generated code referenced an undefined symbol and failed to compile: type GetV1Version200JSONResponse struct{ VersionGetResponseJSONResponse } GenerateResponseDefinitions already tracks the external package of the path item (externalPkg) and applies that prefix to inline response content, but not to the response-is-a-`$ref` branch. There, RefPathToGoType returns a bare name for a `#/`-relative ref -- it cannot know the ref originated in an external file once the path item has been merged into the root document. Qualify the ref with externalPkg when the operation came from an external path item and the response ref is relative (`#`-prefixed). Refs that already target another file are qualified by RefPathToGoType, so those are left untouched to avoid double-prefixing. A regression test is added under internal/test/issues/issue-2308. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes: #2308
When a path item is referenced from an external file (an OpenAPI 3.1
components.pathItemsentry referenced frompaths), and its operation's response is in turn a$refrelative to that same external file (#/components/responses/...), the generated strict-server response struct embedded an unqualified type name. That type only exists in the imported package, so the generated code referenced an undefined symbol and failed to compile:GenerateResponseDefinitions already tracks the external package of the path item (externalPkg) and applies that prefix to inline response content, but not to the response-is-a-
$refbranch. There, RefPathToGoType returns a bare name for a#/-relative ref -- it cannot know the ref originated in an external file once the path item has been merged into the root document.Qualify the ref with externalPkg when the operation came from an external path item and the response ref is relative (
#-prefixed). Refs that already target another file are qualified by RefPathToGoType, so those are left untouched to avoid double-prefixing.A regression test is added under internal/test/issues/issue-2308.