Commit 99615d0
fix: handle optional request bodies in strict server mode (#2222)
Fixes #2116
Strict server handlers unconditionally decoded the request body,
causing an EOF error when no body was sent for operations with
optional request bodies (requestBody.required defaults to false in
OpenAPI 3.0).
For optional JSON bodies, the generated handlers now treat io.EOF
from the decoder as "no body provided" and leave request.Body as nil
rather than returning an error. For optional text bodies, an empty
read is similarly treated as absent. Required bodies retain the
original unconditional error handling.
All five strict server templates are updated: stdhttp (used by chi
and gorilla), echo, gin, fiber, and iris.
Two new test operations (RequiredJSONBody, RequiredTextBody) with
required: true are added to the strict server test schema to verify
both code paths are generated correctly.
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>1 parent 091742e commit 99615d0
File tree
29 files changed
+2098
-263
lines changed- internal/test
- issues/issue-1298
- strict-server
- chi
- client
- echo
- fiber
- gin
- gorilla
- iris
- stdhttp
- pkg/codegen/templates/strict
29 files changed
+2098
-263
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
0 commit comments