Title: strict-server: any-typed response bodies generate a method on an interface type, which does not compile · Issue #2525 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: strict-server: any-typed response bodies generate a method on an interface type, which does not compile · Issue #2525 · oapi-codegen/oapi-codegen
X Title: strict-server: any-typed response bodies generate a method on an interface type, which does not compile · Issue #2525 · oapi-codegen/oapi-codegen
Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem Under strict-server, a JSON response body whose schema lowers to any generates a defined type with an interface underlying type, plus a value-rece...
Open Graph Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem Under strict-server, a JSON response body whose schema lowers to any generates a defined type with an inte...
X Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem Under strict-server, a JSON response body whose schema lowers to any generates a defined type with an inte...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/2525
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"strict-server: any-typed response bodies generate a method on an interface type, which does not compile","articleBody":"Found during the review of #2522; pre-existing on `main` and independent of that PR.\n\n## Problem\n\nUnder `strict-server`, a JSON response body whose schema lowers to `any` generates a defined type with an interface underlying type, plus a value-receiver method on it:\n\n```go\ntype GetThing200JSONResponse any\n\nfunc (response GetThing200JSONResponse) VisitGetThingResponse(w http.ResponseWriter) error {\n```\n\nGo forbids methods on types whose underlying type is a pointer or interface, so the output does not compile:\n\n```\ninvalid receiver type GetThing200JSONResponse (pointer or interface type)\n```\n\n## Reproduction\n\nVerified on `main` with:\n\n```yaml\npaths:\n /things:\n get:\n operationId: getThing\n responses:\n \"200\":\n description: ok\n content:\n application/json:\n schema: {}\n```\n\nand config `generate: { models: true, std-http-server: true, strict-server: true }`. The same happens for `type: \"null\"` (#2430) and, once #2522 lands, for multi-type unions (`type: [string, number]`) — every schema shape that lowers to `any`.\n\n## Notes\n\n- Non-strict servers are unaffected; only the strict envelope needs a method on the response type.\n- Since this output has never compiled, there are no existing users of the current shape — the fix is free to choose the right one. The obvious candidate is wrapping the body in a struct for interface-underlying response types (e.g. `type GetThing200JSONResponse struct { Body any }`, with the visitor marshaling `response.Body`), mirroring how strict response envelopes with headers already wrap. Alternatively the generator could error on this combination with a pointer at the workaround (`x-go-type` to a concrete type), but generating something that works seems strictly better.\n","author":{"url":"https://github.com/mromaszewicz","@type":"Person","name":"mromaszewicz"},"datePublished":"2026-08-16T14:27:29Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/2525"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| 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:b3be600c-258a-072a-6293-484f9cd72589 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DD86:352312:20B04A:2E2CBD:6AF9C8F7 |
| html-safe-nonce | bcb8ab0e1a30aa536248986ac8b1a900ce9a4df191afa239eaeb9fdc97d7394c |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERDg2OjM1MjMxMjoyMEIwNEE6MkUyQ0JEOjZBRjlDOEY3IiwidmlzaXRvcl9pZCI6IjQzNjM4NjI3NTU0OTM2NjUxOSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1b0e3c27ed63fb98bc9939c26eec825fbb0607bbde4c7b78c4bf35fe16d0d4a1 |
| hovercard-subject-tag | issue:5164704227 |
| 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/2525/issue_layout |
| twitter:image | https://opengraph.githubassets.com/53ea4c7538723a905571b48dd730c920451dd5c19fe221cd4338a32a97af5045/oapi-codegen/oapi-codegen/issues/2525 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/53ea4c7538723a905571b48dd730c920451dd5c19fe221cd4338a32a97af5045/oapi-codegen/oapi-codegen/issues/2525 |
| og:image:alt | Found during the review of #2522; pre-existing on main and independent of that PR. Problem Under strict-server, a JSON response body whose schema lowers to any generates a defined type with an inte... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | mromaszewicz |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| 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 | 072e34035c13c31543fba9f025cbbbda4210dae4 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width