You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"required" of date query parameters is ignored #369
If a query parameter of date format is required in the API definition but not passed in a request, runtime does not return an error.
I have created a minimal example of this bug: https://github.com/Makinami/oapi-codegen-bug together with my analysis of the problem, which I'm copy/pasting below for convenience:
Analysis
The problem is with how date and time are internally handled.
If a query parameter is required, it's generated as a non-pointer member. When passed to BindQueryParameter it goes to the switch statement on line 326 in bindparam.go where it's type is checked:
// abbreviatedswitchk {
casereflect.Slice:
// contains checks if param is required and foundcasereflect.Struct:
// no additional checkserr=bindParamsToExplodedObject(paramName, queryParams, output)
default:
// contains checks if param is required and found
}
Since oapi-codegen's Date type and time.Time are both structs they fall into second case where information about whether the parameter is required or not is completely lost.
I think that the problem can be solved by adding checks to the above switch, passing required flag down to bindParamsToExplodedObject and/or better handling of time.Time like struct. This, I think, can be done without braking public API, although it would change the behaviour (return an error rather than set to zero value).
I'd be happy to work on this as we have recently started using this package extensively in my company, but I'd just like to hear a comment or even a simply yes/no on whether my analysis and proposed "solution" is correct.
This is fixed in github.com/oapi-codegen/runtime by oapi-codegen/runtime#135, released in runtime v1.4.2.
The cause was in BindQueryParameterWithOptions: for an exploded form parameter whose Go type is a struct, including types.Date and time.Time, a missing parameter returned nil without checking the required flag. The struct branch now returns a RequiredParameterError, the same as the primitive and slice cases.
I re-checked against current runtime main. A required format: date query parameter that is left out of the request now fails binding with query parameter 'date' is required. Upgrading to runtime v1.4.2 or later picks this up; the generated code doesn't need to change.
Closing as fixed. Please reopen if you still see this on a current runtime.
Activity
mromaszewicz commentedon Nov 7, 2026
This is fixed in
github.com/oapi-codegen/runtimeby oapi-codegen/runtime#135, released in runtime v1.4.2.The cause was in
BindQueryParameterWithOptions: for an exploded form parameter whose Go type is a struct, includingtypes.Dateandtime.Time, a missing parameter returnednilwithout checking therequiredflag. The struct branch now returns aRequiredParameterError, the same as the primitive and slice cases.I re-checked against current runtime main. A required
format: datequery parameter that is left out of the request now fails binding withquery parameter 'date' is required. Upgrading to runtime v1.4.2 or later picks this up; the generated code doesn't need to change.Closing as fixed. Please reopen if you still see this on a current runtime.
This message was drafted with the help of Claude.