Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when unmarshaling types.Date query param #21

Open
0gener opened this issue Nov 23, 2023 · 0 comments
Open

Error when unmarshaling types.Date query param #21

0gener opened this issue Nov 23, 2023 · 0 comments

Comments

@0gener
Copy link

0gener commented Nov 23, 2023

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

  1. OpenAPI Specification: I defined a date query parameter in my OpenAPI specification as follows:

    - name: date_from
      in: query
      schema:
        type: string
        format: date
  2. 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"`
    }
  3. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant