Title: Invalid generated code on reusing responses · Issue #2190 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Invalid generated code on reusing responses · Issue #2190 · oapi-codegen/oapi-codegen
X Title: Invalid generated code on reusing responses · Issue #2190 · oapi-codegen/oapi-codegen
Description: Hi, we just upgraded from oapi-codegen 2.3.0 to 2.5.1 and our go code generated from OpenAPI isn't valid anymore. I pinned down the issue to response components being referenced in endpoints and came up with this minimal reproducible spe...
Open Graph Description: Hi, we just upgraded from oapi-codegen 2.3.0 to 2.5.1 and our go code generated from OpenAPI isn't valid anymore. I pinned down the issue to response components being referenced in endpoints and ca...
X Description: Hi, we just upgraded from oapi-codegen 2.3.0 to 2.5.1 and our go code generated from OpenAPI isn't valid anymore. I pinned down the issue to response components being referenced in endpoints an...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/2190
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid generated code on reusing responses","articleBody":"Hi,\n\nwe just upgraded from oapi-codegen 2.3.0 to 2.5.1 and our go code generated from OpenAPI isn't valid anymore. I pinned down the issue to response components being referenced in endpoints and came up with this minimal reproducible spec:\n\n```\nopenapi: 3.0.3\ninfo:\n title: test\n version: 1.0.0\nservers:\n - url: https://te.st\npaths:\n /v1/test:\n get:\n operationId: GetTest\n responses:\n \"200\":\n $ref: \"#/components/responses/Success\"\n \"401\":\n $ref: \"#/components/responses/Unauthorized\"\ncomponents:\n responses:\n Success:\n description: Success\n content:\n application/json:\n schema:\n type: string\n Unauthorized:\n description: Unauthorized\n content:\n text/plain:\n schema:\n type: string\n example: \"Unauthorized\"\n```\n\nWe execute oapi-codegen with this configuration:\n```\npackage: test\noutput: api.gen.go\ngenerate:\n std-http-server: true\n strict-server: true\n models: true\n client: true\noutput-options:\n nullable-type: true\n```\n\nThe generated go code contains this:\n```\ntype UnauthorizedTextResponse string\n\ntype GetTest401TextResponse struct{ UnauthorizedTextResponse }\n\nfunc (response GetTest401TextResponse) VisitGetTestResponse(w http.ResponseWriter) error {\n\tw.Header().Set(\"Content-Type\", \"text/plain\")\n\tw.WriteHeader(401)\n\n\t_, err := w.Write([]byte(response))\n\treturn err\n}\n```\n\nwhich is invalid as `response` is of type `GetTest401TextResponse` and cannot be converted to `[]byte`.\n\nWe are using Go version 1.25.7.\n\nI would appreciate if you could have a look, would also be happy to contribute.\nCheers ","author":{"url":"https://github.com/bravenut","@type":"Person","name":"bravenut"},"datePublished":"2026-01-28T11:48:58.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/2190/oapi-codegen/issues/2190"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:dd02ec1c-efc9-44d0-9ec3-30f66dc005d0 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CCCA:A8D95:BC821F:FBDEFC:6A51AA4E |
| html-safe-nonce | 65bba19dec3cbe2b500b6b7d04694394b933c40b8d713444df8d9dda6cf5ace4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDQ0NBOkE4RDk1OkJDODIxRjpGQkRFRkM6NkE1MUFBNEUiLCJ2aXNpdG9yX2lkIjoiOTA3MTk4MjA2MDcyNjQ5NTgyMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 5373b57ae4c11e4856e7a4943ae39b655d77e29868fe3f115e0549fd9fd35b23 |
| hovercard-subject-tag | issue:3865041868 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/oapi-codegen/oapi-codegen/2190/issue_layout |
| twitter:image | https://opengraph.githubassets.com/ad560a33b165a6e278cc8b1600d54f89cfc6f7e7e0497603c93e420419a29cad/oapi-codegen/oapi-codegen/issues/2190 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/ad560a33b165a6e278cc8b1600d54f89cfc6f7e7e0497603c93e420419a29cad/oapi-codegen/oapi-codegen/issues/2190 |
| og:image:alt | Hi, we just upgraded from oapi-codegen 2.3.0 to 2.5.1 and our go code generated from OpenAPI isn't valid anymore. I pinned down the issue to response components being referenced in endpoints and ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bravenut |
| hostname | github.com |
| expected-hostname | github.com |
| None | b9a586c06a05a7a86fc7e3f4dbd03e42f6869085879aa184aa6369456dbd50fb |
| turbo-cache-control | no-preview |
| go-import | github.com/oapi-codegen/oapi-codegen git https://github.com/oapi-codegen/oapi-codegen.git |
| octolytics-dimension-user_id | 142752710 |
| octolytics-dimension-user_login | oapi-codegen |
| octolytics-dimension-repository_id | 173009358 |
| octolytics-dimension-repository_nwo | oapi-codegen/oapi-codegen |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 173009358 |
| octolytics-dimension-repository_network_root_nwo | oapi-codegen/oapi-codegen |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7aed05249554b889eb33d002851a973eebcc7e91 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width