Description
I am encountering an issue when binding date query parameters in a Gin-Gonic application. The problem arises when using oapi-codegen to generate models that include a date query parameter.
Steps to Reproduce
-
OpenAPI Specification: I defined a date query parameter in my OpenAPI specification as follows:
- name: date_from
in: query
schema:
type: string
format: date
-
Generated Go Model: Using oapi-codegen, the above specification generates a Go struct resembling:
type Params struct {
DateFrom *openapi_types.Date `form:"date_from,omitempty" json:"date_from,omitempty"`
}
-
Binding in Gin-Gonic: When I attempt to bind this query parameter using Gin's BindQuery method, I encounter an error.
var queryParams models.Params
if err := c.BindQuery(&queryParams); err != nil {
c.AbortWithStatusJSON(http.StatusBadRequest, api.NewError(err.Error()))
return
}
- Request URL:
/endpoint?date_from=2023-01-01
- Error Received:
invalid character '-' after top-level value
Expected Behavior
I expect the date_from query parameter to be bound successfully to the Params struct without errors, parsing the date string correctly.
Actual Behavior
The binding process fails with an error indicating an issue with the '-' character in the date string, which suggests a possible problem with how the date string is being parsed or handled during the binding process.
Additional Information
- Gin-Gonic Version: v1.9.1
- oapi-codegen Version: v2.0.0
- oapi-codegen/runtime Version: v1.1.0
- Go Version: go1.21.4
Description
I am encountering an issue when binding date query parameters in a Gin-Gonic application. The problem arises when using
oapi-codegento generate models that include a date query parameter.Steps to Reproduce
OpenAPI Specification: I defined a date query parameter in my OpenAPI specification as follows:
Generated Go Model: Using
oapi-codegen, the above specification generates a Go struct resembling:Binding in Gin-Gonic: When I attempt to bind this query parameter using Gin's
BindQuerymethod, I encounter an error./endpoint?date_from=2023-01-01invalid character '-' after top-level valueExpected Behavior
I expect the
date_fromquery parameter to be bound successfully to theParamsstruct without errors, parsing the date string correctly.Actual Behavior
The binding process fails with an error indicating an issue with the '-' character in the date string, which suggests a possible problem with how the date string is being parsed or handled during the binding process.
Additional Information