Title: error merging schemas for AllOf: merging two schemas with different Nullable · Issue #1898 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: error merging schemas for AllOf: merging two schemas with different Nullable · Issue #1898 · oapi-codegen/oapi-codegen
X Title: error merging schemas for AllOf: merging two schemas with different Nullable · Issue #1898 · oapi-codegen/oapi-codegen
Description: oapi-codegen fails to properly merge allOf elements when one of them has the nullable property unset, and the other one has it set to true. oapi-codegen --version output: github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen v2.4.1 Op...
Open Graph Description: oapi-codegen fails to properly merge allOf elements when one of them has the nullable property unset, and the other one has it set to true. oapi-codegen --version output: github.com/oapi-codegen/oa...
X Description: oapi-codegen fails to properly merge allOf elements when one of them has the nullable property unset, and the other one has it set to true. oapi-codegen --version output: github.com/oapi-codegen/oa...
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen/issues/1898
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"error merging schemas for AllOf: merging two schemas with different Nullable","articleBody":"`oapi-codegen` fails to properly merge `allOf` elements when one of them has the `nullable` property unset, and the other one has it set to `true`.\n\n`oapi-codegen --version` output:\n```\ngithub.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen\nv2.4.1\n```\n\nOpenAPI spec I'm using:\n```yaml\nopenapi: \"3.0.0\"\npaths:\n /user:\n get:\n responses:\n 200:\n content:\n application/json:\n schema:\n properties:\n user:\n allOf:\n - $ref: \"#/components/schemas/user\"\n - nullable: true\ncomponents:\n schemas:\n user:\n required:\n - name\n - surname\n properties:\n name:\n type: string\n surname:\n type: string\n```\n\n`oapi-codegen` config:\n```yaml\n---\npackage: myapi\noutput: myapi.go\ngenerate:\n models: true\n client: true\noutput-options:\n nullable-type: true\n```\n\n`oapi-codegen` output I get:\n```\nerror generating code: error creating operation definitions: error generating response definitions: error generating request body definition: error generating Go schema for property 'user': error merging schemas: error merging schemas for AllOf: merging two schemas with different Nullable\n```\n\nI've scrolled through the code and it seems that the reason lies within the `github.com/getkin/kin-openapi/openapi3` package. The `Schema` type it provides has the `Nullable` field as a `bool`, which makes it impossible to differentiate between the default and unset values, which makes the schema merge code to misbehave.\n\nI'm not really sure what's the best way to address this issue. AFAIK, this OpenAPI idiom is quite popular to mix in some additional properties to shared schemas, and it doesn't really voilate the OpenAPI spec, so theoretically `oapi-codegen` should be able to deal with it.","author":{"url":"https://github.com/boogie-byte","@type":"Person","name":"boogie-byte"},"datePublished":"2025-02-10T13:53:37Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/1898"}
| 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:518f5fe6-3015-32fa-2034-84481874c90f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BF88:79AE7:154792B:1BEBCE0:6AF9CCA3 |
| html-safe-nonce | b990f3402423efd1208f3c3063e25e4c91d7d16fc5bf6331229b537ac3a9006d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRjg4Ojc5QUU3OjE1NDc5MkI6MUJFQkNFMDo2QUY5Q0NBMyIsInZpc2l0b3JfaWQiOiIxODg5NTk4OTkxNDEwNzc3MjUyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 062c5b73f2e5fea066b3956e33132793cbd5d835011737209d5ba168a4df53fd |
| hovercard-subject-tag | issue:2842484871 |
| 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/1898/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4704739982ff98946ad5afa395349bc82251104427a0302dc3e0ec7a611c15bd/oapi-codegen/oapi-codegen/issues/1898 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4704739982ff98946ad5afa395349bc82251104427a0302dc3e0ec7a611c15bd/oapi-codegen/oapi-codegen/issues/1898 |
| og:image:alt | oapi-codegen fails to properly merge allOf elements when one of them has the nullable property unset, and the other one has it set to true. oapi-codegen --version output: github.com/oapi-codegen/oa... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | boogie-byte |
| 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 | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width