Skip to content

Compile error in generated code when there are multiple cookie parameters #924

Description

@shuz

The template generates multiple parameters. Example:

	var cookie *http.Cookie

	if cookie, err = r.Cookie("cookie1"); err == nil {
		var value string
		err = runtime.BindStyledParameter("simple", true, "oauth2_authentication_csrf", cookie.Value, &value)
		if err != nil {
			siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "oauth2_authentication_csrf", Err: err})
			return
		}
		params.Oauth2AuthenticationCsrf = &value

	}

	var cookie *http.Cookie

	if cookie, err = r.Cookie("cookie2"); err == nil {
		var value string
		err = runtime.BindStyledParameter("simple", true, "ulsid", cookie.Value, &value)
		if err != nil {
			siw.ErrorHandlerFunc(w, r, &InvalidParamFormatError{ParamName: "ulsid", Err: err})
			return
		}
		params.Ulsid = &value

	}

Note that var cookie *http.Cookie is duplicated and caused compile error.

I checked it's true for both chi and gorilla middleware.
Code reference for Chi: https://github.com/deepmap/oapi-codegen/blob/a444d309616eaac712c1b1a633c0818613918e11/pkg/codegen/templates/chi/chi-middleware.tmpl#L129

Code reference for Gorilla: https://github.com/deepmap/oapi-codegen/blob/ab90f1927bc5ec3e29af216d4298fbb4780ae36d/pkg/codegen/templates/gorilla/gorilla-middleware.tmpl#L129

Activity

  1. added 2 commits that reference this issue on Sep 20, 2024
    fdfdeca
    00a06d1
  2. jamietanna commented on Sep 20, 2024

    @jamietanna
    Member

    Accidentally detected Ahead of being able to fix #924, as me saying I wanted to close it 🫣

  3. added a commit that references this issue on Sep 20, 2024
    3d6764e
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