fix(strict-server): generate correct type for $ref text responses #2225
Merged
mromaszewicz merged 2 commits intooapi-codegen:mainfrom Feb 16, 2026
Merged
fix(strict-server): generate correct type for $ref text responses #2225mromaszewicz merged 2 commits intooapi-codegen:mainfrom
$ref text responses #2225mromaszewicz merged 2 commits intooapi-codegen:mainfrom
Conversation
Add a minimal reproduction for invalid generated code when reusing response components. The generated VisitGetTestResponse method attempts []byte(response) on a struct type, which does not compile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…api-codegen#2190) When a response is defined as a $ref to a component response with text/plain content type (and no headers), the strict-server template generated a struct-embedding type whose Visit method tried to call []byte(response) on a struct, which failed to compile. The root cause was the revert of PR oapi-codegen#1132 (commit 891a067), which had originally fixed this by making all text responses string types. That PR was reverted because it broke text responses with headers (oapi-codegen#1676), which require the struct form with a Body field. The fix extends the existing multipart special case in Branch 1A of the strict-interface template to also cover text responses without headers. This generates a named type alias (e.g. `type GetTest401TextResponse UnauthorizedTextResponse`) instead of a struct embedding, so []byte(response) compiles and works correctly. Text responses with headers continue to go through Branch 1C (struct with Body + Headers fields), so oapi-codegen#1676 is unaffected — confirmed by verifying no diff in internal/test/issues/issue-1676/ping.gen.go. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
$ref text responses
jamietanna
approved these changes
Feb 16, 2026
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.
No description provided.