Skip to content

Commit 091742e

Browse files
mromaszewiczclaude
andauthored
fix(strict-server): generate correct type for $ref text responses (#2225)
* test: add regression test for issue #2190 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> * fix: generate correct type for $ref text responses in strict server (#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 #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 (#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 #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> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent b658fcf commit 091742e

File tree

6 files changed

+566
-1
lines changed

6 files changed

+566
-1
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package: issue2190
2+
output: issue2190.gen.go
3+
generate:
4+
std-http-server: true
5+
strict-server: true
6+
models: true
7+
client: true
8+
output-options:
9+
nullable-type: true
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package issue2190
2+
3+
//go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml spec.yaml

0 commit comments

Comments
 (0)