-
-
Notifications
You must be signed in to change notification settings - Fork 44
Description
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
BindQuerymethod, 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
- Request URL:
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