Title: Invalid typedefs when spec uses same ref name for request body and schema · Issue #407 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Invalid typedefs when spec uses same ref name for request body and schema · Issue #407 · oapi-codegen/oapi-codegen
X Title: Invalid typedefs when spec uses same ref name for request body and schema · Issue #407 · oapi-codegen/oapi-codegen
Description: When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the same identifier myThing for both the reques...
Open Graph Description: When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the sam...
X Description: When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the sam...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/407
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Invalid typedefs when spec uses same ref name for request body and schema","articleBody":"When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the same identifier `myThing` for both the request body and the schema):\r\n\r\n```\r\npaths:\r\n /my/end/point:\r\n put:\r\n requestBody:\r\n $ref: '#/components/requestBodies/myThing'\r\ncomponents:\r\n requestBodies:\r\n myThing:\r\n content:\r\n application/json:\r\n schema:\r\n $ref: '#/components/schemas/myThing'\r\n required: true\r\n schema:\r\n myThing:\r\n type: object\r\n properties:\r\n thing:\r\n type: string\r\n```\r\n\r\nThen I used up with a typedef in the generated code like: `type MyThing MyThing` which is invalid.\r\n\r\nI've currently worked around this by altering `typedef.tmpl` to do the following:\r\n\r\n```\r\n{{range .Types}}\r\n{{if ne .TypeName .Schema.TypeDecl }}\r\n{{ with .Schema.Description }}{{ . }}{{ else }}// {{.TypeName}} defines model for {{.JsonName}}.{{ end }}\r\ntype {{.TypeName}} {{if and (opts.AliasTypes) (.CanAlias)}}={{end}} {{.Schema.TypeDecl}}\r\n{{end}}\r\n{{end}}\r\n```\r\n\r\nWhich skips doing a typedef with a type name equal to it's schema declaration, but that is a bit of a hack and ideally the generator would create either unique names or be able to deduplicate identical types internally before iterating over them in the templates.","author":{"url":"https://github.com/darkliquid","@type":"Person","name":"darkliquid"},"datePublished":"2021-07-21T09:38:26Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/407"}
| 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:b9a1cf8f-66b5-1d4e-68d1-3fc891b410e7 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C934:341CBB:1149FF:1851E8:6AF9C212 |
| html-safe-nonce | 374f0962218d1d6fa0faac46dd1055d187de8cb8c895d93f97cd2ab861cf6fc1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOTM0OjM0MUNCQjoxMTQ5RkY6MTg1MUU4OjZBRjlDMjEyIiwidmlzaXRvcl9pZCI6Ijc3NzMwMTc3NTIzNzI2MjU5MzgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | faf560f3592bd6867d62d6cdde963cef860d321d857f0bc6728360bd68451b4c |
| hovercard-subject-tag | issue:949519821 |
| 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/407/issue_layout |
| twitter:image | https://opengraph.githubassets.com/82d17de9ac324e2ea242f9cb3b2adf14d0c3700dd6128be432d1fd49ca3c2c3f/oapi-codegen/oapi-codegen/issues/407 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/82d17de9ac324e2ea242f9cb3b2adf14d0c3700dd6128be432d1fd49ca3c2c3f/oapi-codegen/oapi-codegen/issues/407 |
| og:image:alt | When I have a spec that defines the same thing twice (but in different namespaces) I get invalid code generated. For example, with a spec containing something like this (notice the reuse of the sam... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | darkliquid |
| 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