Skip to content

Generated code silently ignores date-time reusable parameters #247

Description

@peay

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 =).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions