oapi-codegen icon indicating copy to clipboard operation
oapi-codegen copied to clipboard

fix: respect requestBody.required in strict server

Open dbarrosop opened this issue 11 months ago • 3 comments

I noticed that requestBody.required wasn't being respected and requests without a body were failing with an [EOF] error even though required was set to false.

This PR is a tentative fix to this issue. It certainly works as my API now behaves according to the spec and it fails without a body only if required: true

I was wondering if we should also do:

var body *{{$opid}}{{.NameTag}}RequestBody

That would mean that if the body isn't present we would correctly send a nil object down to the server implementation but I am concerned that would lead to lots of panics in existing services for users that hadn't been paying attention to the fact that required: false is the default behavior when not set.

Thoughts?

dbarrosop avatar Mar 23 '25 18:03 dbarrosop

any update on this PR? thanks!

dbarrosop avatar Aug 01 '25 08:08 dbarrosop

Kusari Analysis Results

Analysis for commit: 6225e75bb76ba1fa15113a7fc6aace55ad12862c, performed at: 2025-08-01T08:12:45Z

@kusari-inspector rerun - Trigger a re-analysis of this PR

@kusari-inspector feedback [your message] - Send feedback to our AI and team


Recommendation

✅ PROCEED with this Pull Request

Summary

No Flagged Issues Detected

All values appear to be within acceptable risk parameters.

No pinned version dependency changes, code issues or exposed secrets detected!

Found this helpful? Give it a 👍 or 👎 reaction!

kusari-inspector[bot] avatar Aug 01 '25 08:08 kusari-inspector[bot]

We also need this fix to support required: false request bodies being generated. Up

gologames avatar Oct 24 '25 14:10 gologames