Title: allOf with cross-file does not qualify nested type references from source schema · Issue #2288 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: allOf with cross-file does not qualify nested type references from source schema · Issue #2288 · oapi-codegen/oapi-codegen
X Title: allOf with cross-file does not qualify nested type references from source schema · Issue #2288 · oapi-codegen/oapi-codegen
Description: Description When using allOf to extend a schema from another file, oapi-codegen flattens the fields correctly but does not qualify nested type references that originate from the source schema's file. This produces uncompilable Go code. R...
Open Graph Description: Description When using allOf to extend a schema from another file, oapi-codegen flattens the fields correctly but does not qualify nested type references that originate from the source schema's fil...
X Description: Description When using allOf to extend a schema from another file, oapi-codegen flattens the fields correctly but does not qualify nested type references that originate from the source schema's...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/2288
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"allOf with cross-file does not qualify nested type references from source schema","articleBody":"### Description\n\nWhen using `allOf` to extend a schema from another file, oapi-codegen flattens the fields correctly but does not qualify nested type references that originate from the source schema's file. This produces uncompilable Go code.\n\n### Reproduction\n\nGiven two OpenAPI spec files with an `import-mapping` configured:\n\n**`api/common/openapi.yaml`**\n```yaml\nopenapi: 3.0.0\ninfo:\n title: Common\n version: 0.1.0\npaths: {}\ncomponents:\n schemas:\n Role:\n type: string\n enum: [admin, user]\n User:\n type: object\n required: [id, username]\n properties:\n id:\n type: string\n username:\n type: string\n roles:\n type: array\n items:\n $ref: '#/components/schemas/Role'\n```\n\n**`api/service/openapi.yaml`**\n```yaml\nopenapi: 3.0.0\ninfo:\n title: Service\n version: 0.1.0\npaths: {}\ncomponents:\n schemas:\n EnrichedUser:\n allOf:\n - $ref: '../common/openapi.yaml#/components/schemas/User'\n - type: object\n properties:\n extra_field:\n type: string\n```\n\n**`api/service/types.yaml`** (codegen config)\n```yaml\npackage: service\ngenerate:\n models: true\noutput: types.gen.go\nimport-mapping:\n '../common/openapi.yaml': common github.com/example/api/common\n```\n\n### Expected behavior\n\nGenerated `EnrichedUser` should qualify the `Role` reference via the import mapping:\n\n```go\ntype EnrichedUser struct {\n ExtraField *string `json:\"extra_field,omitempty\"`\n ID string `json:\"id\"`\n Roles *[]common.Role `json:\"roles,omitempty\"`\n Username string `json:\"username\"`\n}\n```\n\n### Actual behavior\n\nGenerated code uses an unqualified `Role` reference:\n\n```go\ntype EnrichedUser struct {\n ExtraField *string `json:\"extra_field,omitempty\"`\n ID string `json:\"id\"`\n Roles *[]Role `json:\"roles,omitempty\"` // \u003c-- unqualified\n Username string `json:\"username\"`\n}\n```\n\nThis fails to compile: `undefined: Role`\n\n### Workaround\n\nOverride the field in the `allOf` extension with a direct cross-file `$ref`:\n\n```yaml\n EnrichedUser:\n allOf:\n - $ref: '../common/openapi.yaml#/components/schemas/User'\n - type: object\n properties:\n roles:\n type: array\n items:\n $ref: '../common/openapi.yaml#/components/schemas/Role'\n extra_field:\n type: string\n```\n\nThis correctly generates `Roles *[]common.Role`.\n\n### Version\n\noapi-codegen v2.6.0","author":{"url":"https://github.com/xiongzubiao","@type":"Person","name":"xiongzubiao"},"datePublished":"2026-03-10T18:04:58Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/2288"}
| 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:4ebed680-960c-82df-a735-cfee38ca5da2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9B92:3166AC:2CF7FA6:3B3E835:6AF9CBCE |
| html-safe-nonce | e7951a7a46f786f889345543b203741ca394d479eb9c1da95cb58243381c02a4 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5QjkyOjMxNjZBQzoyQ0Y3RkE2OjNCM0U4MzU6NkFGOUNCQ0UiLCJ2aXNpdG9yX2lkIjoiNTEyODEwNTY2MTA1MDM2MzAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2604d8a557580b8e9bdf6e4307f7e5ee0173548aa3d2ddbce86868f08f65dcde |
| hovercard-subject-tag | issue:4053373424 |
| 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/2288/issue_layout |
| twitter:image | https://opengraph.githubassets.com/541aba57a4229bbf6ae9be3d28f8cd0c8409b366c30f7e79b586e7c893930817/oapi-codegen/oapi-codegen/issues/2288 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/541aba57a4229bbf6ae9be3d28f8cd0c8409b366c30f7e79b586e7c893930817/oapi-codegen/oapi-codegen/issues/2288 |
| og:image:alt | Description When using allOf to extend a schema from another file, oapi-codegen flattens the fields correctly but does not qualify nested type references that originate from the source schema's fil... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | xiongzubiao |
| 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