oapi-codegen has an issue with parameters of type date-time which are declared as reusable: i.e., in components: parameters: in the OpenAPI specification:
components:
parameters:
minValidityEnd:
name: minValidityEndParam
in: query
required: false
schema:
type: string
format: date-time
...
# Then used as:
parameters:
- $ref: '#/components/parameters/minValidityEndParam'
Even if the parameter is passed in, it is ignored. However, the same parameter set directly in the parameters section of the API endpoint works fine.
For regular parameters, the code generation will produce:
MinValidityEnd *time.Time `json:"minValidityEnd,omitempty"`
bindParamsToExplodedObject in bindparam.go then checks:
switch dest.(type) {
case *time.Time:
return BindStringToObject(values.Get(paramName), dest)
...
}
and all is well, However, for reusable parameters, the code generation will produce
type MaxWindowEndParam = time.Time
...
MaxWindowEnd *MaxWindowEndParam `json:"maxWindowEnd,omitempty"`
which is now a new type. In particular, the type-switch above does not match any more. Instead, the code should probably be using if ok, v := *dest.(time.Time) { or something like that to try and convert to a time.Time.
Workaround: edit generated code to use a type alias instead of a type definition (i.e., type MaxWindowEndParam = time.Time with =).
oapi-codegenhas an issue with parameters of typedate-timewhich are declared as reusable: i.e., incomponents: parameters:in the OpenAPI specification:Even if the parameter is passed in, it is ignored. However, the same parameter set directly in the
parameterssection of the API endpoint works fine.For regular parameters, the code generation will produce:
bindParamsToExplodedObjectinbindparam.gothen checks:and all is well, However, for reusable parameters, the code generation will produce
which is now a new type. In particular, the type-switch above does not match any more. Instead, the code should probably be using
if ok, v := *dest.(time.Time) {or something like that to try and convert to atime.Time.Workaround: edit generated code to use a type alias instead of a type definition (i.e.,
type MaxWindowEndParam = time.Timewith=).