Title: Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen · GitHub
Open Graph Title: Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen
X Title: Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen
Description: Generate Go client and server boilerplate from OpenAPI 3 specifications - Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen
Open Graph Description: Generate Go client and server boilerplate from OpenAPI 3 specifications - Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen
X Description: Generate Go client and server boilerplate from OpenAPI 3 specifications - Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen
Opengraph URL: https://github.com/oapi-codegen/oapi-codegen
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Request bodies with `required: false` should have an optional argument for body","articleBody":"For instance, given:\n\n```yaml\nopenapi: \"3.0.0\"\ninfo:\n version: 1.0.0\n title: Generate models\npaths:\n /client:\n put:\n operationId: updateClient\n requestBody:\n required: false\n content:\n application/json:\n schema:\n type: object\n properties:\n foo:\n type: string\n\n```\n`oapi-codegen` v2.5.0 will generate:\n\n```go\npackage client\n\n// ...\n\ntype UpdateClientJSONBody struct {\n\tFoo *string `json:\"foo,omitempty\"`\n}\n\n// NOTE that this is not optional\ntype UpdateClientJSONRequestBody UpdateClientJSONBody\n\ntype ClientInterface interface {\n // NOTE that this is not an optional body\n\tUpdateClientWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n\n // NOTE that this is not an optional body\n\tUpdateClient(ctx context.Context, body UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n}\n```\n\nIt would be better if we detected `required: false` and instead i.e.\n\n```go\ntype UpdateClientJSONRequestBody *UpdateClientJSONBody\n\ntype ClientInterface interface {\n // A body can be set from raw data\n\tUpdateClientWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)\n\n // A body can be set as its struct\n\tUpdateClient(ctx context.Context, body *UpdateClientJSONRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)\n}\n```\n\nAs a breaking change to currently generated code, this would be via an `output-options`.\n","author":{"url":"https://github.com/jamietanna","@type":"Person","name":"jamietanna"},"datePublished":"2026-02-02T10:33:30Z","url":"https://github.com/oapi-codegen/oapi-codegen/issues/2194"}
| 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 | /:user_id/:repository/issues/:id(.:format) |
| route-controller | issues |
| route-action | show |
| fetch-nonce | v2:ee1fef5a-4490-e3ba-b5f9-a8878103cefe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A7C4:8513F:2BBD1B3:394B751:6AF9BAAC |
| html-safe-nonce | 0e89617def8260b378de93cfefac9825cea965682ef84ce6dadc8aa59dd92d3f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBN0M0Ojg1MTNGOjJCQkQxQjM6Mzk0Qjc1MTo2QUY5QkFBQyIsInZpc2l0b3JfaWQiOiIyMDU1NDA5NDY4MDQ3OTk3NjEyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 6bbf63a509bc9b2f1858354952d939069ece41beed81eb0ae6c9a57df60a4af2 |
| hovercard-subject-tag | repository:173009358 |
| 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/oapi-codegen/oapi-codegen/issues/2194 |
| twitter:image | https://opengraph.githubassets.com/795d53ee6dad6051e74f3580af19614fbae92dac0dc480c0eae39b8a4166213a/oapi-codegen/oapi-codegen |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/795d53ee6dad6051e74f3580af19614fbae92dac0dc480c0eae39b8a4166213a/oapi-codegen/oapi-codegen |
| og:image:alt | Generate Go client and server boilerplate from OpenAPI 3 specifications - Request bodies with `required: false` should have an optional argument for body · Issue #2194 · oapi-codegen/oapi-codegen |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 612d3e6ffd693e7ea8d9fcf452370995872baef31d825b1fedef704cd3d24ac7 |
| turbo-cache-control | no-cache |
| 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