Title: Generating Struct with Embedded Imported Type · Issue #1622 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Generating Struct with Embedded Imported Type · Issue #1622 · oapi-codegen/oapi-codegen
X Title: Generating Struct with Embedded Imported Type · Issue #1622 · oapi-codegen/oapi-codegen
Description: Hi all, I am attempting to generate a struct type that includes an embedded field from an imported type. However, I am not achieving the desired result. Here is the struct I aim to generate: import "github.com/golang-jwt/jwt" type MyClai...
Open Graph Description: Hi all, I am attempting to generate a struct type that includes an embedded field from an imported type. However, I am not achieving the desired result. Here is the struct I aim to generate: import...
X Description: Hi all, I am attempting to generate a struct type that includes an embedded field from an imported type. However, I am not achieving the desired result. Here is the struct I aim to generate: import...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/1622
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Generating Struct with Embedded Imported Type","articleBody":"Hi all, I am attempting to generate a struct type that includes an embedded field from an imported type. However, I am not achieving the desired result.\r\n\r\nHere is the struct I aim to generate:\r\n\r\n```go\r\nimport \"github.com/golang-jwt/jwt\"\r\n\r\ntype MyClaims struct {\r\n\tOrg string `json:\"org\"`\r\n\tUser string `json:\"user\"`\r\n\tjwt.StandardClaims\r\n}\r\n```\r\n\r\nThe spec I am using is as follows:\r\n\r\n```yaml\r\n MyClaims:\r\n allOf:\r\n - properties:\r\n user:\r\n type: string\r\n org:\r\n type: string\r\n required:\r\n - user\r\n - org\r\n - $ref: '#/components/schemas/JWTStandardClaims'\r\n \r\n JWTStandardClaims:\r\n type: object\r\n x-go-type: jwt.StandardClaims\r\n x-go-type-import:\r\n path: github.com/golang-jwt/jwt\r\n name: jwt\r\n```\r\n\r\n### `old-merge-schemas: false`\r\n\r\nWhen I use the default merge schemas configuration (`old-merge-schemas: false`), the generated `MyClaims` is merely a type definition on `jwt.StandardClaims`, and the additional fields are not included:\r\n\r\n```go\r\nimport jwt \"github.com/golang-jwt/jwt\"\r\n\r\n// MyClaims defines model for MyClaims.\r\ntype MyClaims jwt.StandardClaims\r\n\r\n// JWTStandardClaims defines model for JWTStandardClaims.\r\ntype JWTStandardClaims jwt.StandardClaims\r\n```\r\n\r\n\r\n### `old-merge-schemas: true`\r\n\r\nIf I switch to the old merge schemas configuration (`old-merge-schemas: true`), I get a struct with the `JWTStandardClaims` type embedded, rather than `jwt.StandardClaims`. The generated struct includes all the fields, but the embedded struct is not of the expected type:\r\n\r\n```go\r\nimport jwt \"github.com/golang-jwt/jwt\"\r\n\r\n// MyClaims defines model for MyClaims.\r\ntype MyClaims struct {\r\n\t// Embedded fields due to inline allOf schema\r\n\tOrg string `json:\"org\"`\r\n\tUser string `json:\"user\"`\r\n\t// Embedded struct due to allOf(#/components/schemas/JWTStandardClaims)\r\n\tJWTStandardClaims `yaml:\",inline\"`\r\n}\r\n\r\n// JWTStandardClaims defines model for JWTStandardClaims.\r\ntype JWTStandardClaims jwt.StandardClaims\r\n```\r\n\r\nIs there a configuration or method that would allow me to generate the desired struct? Any guidance would be greatly appreciated.","author":{"url":"https://github.com/user-llmm","@type":"Person","name":"user-llmm"},"datePublished":"2024-05-22T14:41:47Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/1622"}
| 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:28b5646e-cad1-55e9-13ee-70a72c2e7110 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9474:13D864:47494:5DE55:6AF9BE31 |
| html-safe-nonce | 6dbaef5556afc9ac2432ba19bd9c91c5d1f3aa5783e8fbc67d98ba2fbfb6d6b1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NDc0OjEzRDg2NDo0NzQ5NDo1REU1NTo2QUY5QkUzMSIsInZpc2l0b3JfaWQiOiI1NDI4MDY5MDIyOTc5MTc4MDMzIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a4e2c994d4f2ef54b241e2234ae7e4c1be8f3b6c8927813ce2b76067044e0ed1 |
| hovercard-subject-tag | issue:2310736019 |
| 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/1622/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3d29ba76cd1623d471c40cfc4b6aa28761fe3b053294c272a598be39378a6390/oapi-codegen/oapi-codegen/issues/1622 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3d29ba76cd1623d471c40cfc4b6aa28761fe3b053294c272a598be39378a6390/oapi-codegen/oapi-codegen/issues/1622 |
| og:image:alt | Hi all, I am attempting to generate a struct type that includes an embedded field from an imported type. However, I am not achieving the desired result. Here is the struct I aim to generate: import... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | user-llmm |
| 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