Title: MergeSchemas silently drops a member's type when an earlier allOf member has none (order-dependent output) · Issue #2524 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: MergeSchemas silently drops a member's type when an earlier allOf member has none (order-dependent output) · Issue #2524 · oapi-codegen/oapi-codegen
X Title: MergeSchemas silently drops a member's type when an earlier allOf member has none (order-dependent output) · Issue #2524 · oapi-codegen/oapi-codegen
Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem MergeSchemas (pkg/codegen/merge_schemas.go) only errors on a type conflict when both members declare a type: if s1.Type.Slice() != nil && s2.Type....
Open Graph Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem MergeSchemas (pkg/codegen/merge_schemas.go) only errors on a type conflict when both members declare a typ...
X Description: Found during the review of #2522; pre-existing on main and independent of that PR. Problem MergeSchemas (pkg/codegen/merge_schemas.go) only errors on a type conflict when both members declare a typ...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/2524
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"MergeSchemas silently drops a member's type when an earlier allOf member has none (order-dependent output)","articleBody":"Found during the review of #2522; pre-existing on `main` and independent of that PR.\n\n## Problem\n\n`MergeSchemas` (pkg/codegen/merge_schemas.go) only errors on a type conflict when **both** members declare a type:\n\n```go\nif s1.Type.Slice() != nil && s2.Type.Slice() != nil && !equalTypes(s1.Type, s2.Type) {\n return openapi3.Schema{}, fmt.Errorf(\"can not merge incompatible types: ...\")\n}\nresult.Type = s1.Type\n```\n\nWhen `s1` has no type and `s2` does, `result.Type = s1.Type` silently discards `s2`'s type. Because allOf members are merged pairwise in order, the generated Go shape depends on member ordering.\n\n## Reproduction\n\n```yaml\nAllOfUnionMember:\n allOf:\n - properties:\n name:\n type: string\n - type: [string, number]\n```\n\ngenerates a plain struct — the second member's type constraint vanishes entirely:\n\n```go\ntype AllOfUnionMember struct {\n Name *string `json:\"name,omitempty\"`\n}\n```\n\nReversing the member order flips which constraint silently wins: `result.Type` then carries the union, the schema lowers to `any`, and the `properties` are dropped instead. The same mechanism applies to single types (`- type: string` as the second member is discarded the same way); the multi-type union case from #2521/#2522 just made it easier to notice, and converted some of these from hard generation errors into silent, order-dependent output.\n\n## Expected\n\nOrder should not change the result. Either:\n\n- propagate the type when exactly one member declares one (`result.Type = firstNonNil(s1.Type, s2.Type)`), keeping the existing incompatibility error when both declare different types, or\n- error loudly on the typeless+typed combination if propagation has unwanted interactions (e.g. a propagated primitive type alongside merged properties still silently drops the properties at the dispatch stage — propagation alone doesn't make that combination coherent).\n\nThe first option fixes the common case (a typeless member contributing only `properties`/`required` alongside a typed member); the second at least removes the silent order dependency. Behavior change to generated code either way, so this likely wants a look at what existing specs in the wild rely on before choosing.\n","author":{"url":"https://github.com/mromaszewicz","@type":"Person","name":"mromaszewicz"},"datePublished":"2026-08-16T14:27:28Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/2524"}
| 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:53a64046-ce19-0244-ddca-f5ad6b17857c |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C146:141D8D:44F3986:5A9291F:6AF9CCC7 |
| html-safe-nonce | 483e6d46fd57cebd8805608abf4b59b1d7e2472470aa1c5512269dacfccdcac5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMTQ2OjE0MUQ4RDo0NEYzOTg2OjVBOTI5MUY6NkFGOUNDQzciLCJ2aXNpdG9yX2lkIjoiNTE2Nzk4ODMzMDYzNjg4OTI4NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 19eee1bcfc0dcafba3b130128aeccc5062c11e2d540d4e93a90b39d151112e20 |
| hovercard-subject-tag | issue:5164704145 |
| 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/2524/issue_layout |
| twitter:image | https://opengraph.githubassets.com/8ebe0ff65d8601bcdc247bd81dd6324be5eef4dfc950336ac6ad8e44120d329c/oapi-codegen/oapi-codegen/issues/2524 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/8ebe0ff65d8601bcdc247bd81dd6324be5eef4dfc950336ac6ad8e44120d329c/oapi-codegen/oapi-codegen/issues/2524 |
| og:image:alt | Found during the review of #2522; pre-existing on main and independent of that PR. Problem MergeSchemas (pkg/codegen/merge_schemas.go) only errors on a type conflict when both members declare a typ... |
| 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