Skip to content

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

@shuz

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

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