fix(go): fix Go client to normalize request header keys using Header.Set - #24766
fix(go): fix Go client to normalize request header keys using Header.Set#24766Wuchieh wants to merge 5 commits into
Conversation
- Use Set when writing headerParams to http.Header to automatically apply canonical key formatting. - Avoid inconsistent casing or duplicate header issues caused by direct map assignment.
|
@lwj5 Please review it. |
|
please review the build failures when you've time, e.g. https://github.com/OpenAPITools/openapi-generator/actions/runs/32814668511/job/97700780542?pr=24766 |
Okay, I'll take a look later to see what the issue is. |
…templates - Update the go.mod Go version format for multiple Go client/server templates (e.g., 1.23 → 1.23.0, 1.25 → 1.25.0). - Add missing terraform-plugin-testing checksums to the Terraform templates' go.sum. - Sync checksums for indirect dependencies such as testify, x/sys, and x/text. - Add go.sum files for templates including echo-server, chi-server, and gin-api-server-interface-only.
There was a problem hiding this comment.
1 issue found across 24 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/echo_api/go/client.go">
<violation number="1">
P2: This PR changes properly gofmt-formatted Go code into gofmt-invalid code: spaces inside call/signature parens, `var param,ok`, `dataMap,err :=`, `for i:=0;i<len;...`, and an over-indented `case`. The same non-gofmt text is now in the `client.mustache` template, so every generated Go client ships this. Keep generated Go output gofmt-clean (run `gofmt -w` on the template and regenerate, or write the template in gofmt style) or CI/`go vet`/gofmt checks and downstream users on the Go codebase will hit formatting failures.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| @@ -420,7 +420,7 @@ func (c *APIClient) prepareRequest( | |||
| if len(headerParams) > 0 { | |||
There was a problem hiding this comment.
P2: This PR changes properly gofmt-formatted Go code into gofmt-invalid code: spaces inside call/signature parens, var param,ok, dataMap,err :=, for i:=0;i<len;..., and an over-indented case. The same non-gofmt text is now in the client.mustache template, so every generated Go client ships this. Keep generated Go output gofmt-clean (run gofmt -w on the template and regenerate, or write the template in gofmt style) or CI/go vet/gofmt checks and downstream users on the Go codebase will hit formatting failures.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/go/client.go, line 144:
<comment>This PR changes properly gofmt-formatted Go code into gofmt-invalid code: spaces inside call/signature parens, `var param,ok`, `dataMap,err :=`, `for i:=0;i<len;...`, and an over-indented `case`. The same non-gofmt text is now in the `client.mustache` template, so every generated Go client ships this. Keep generated Go output gofmt-clean (run `gofmt -w` on the template and regenerate, or write the template in gofmt style) or CI/`go vet`/gofmt checks and downstream users on the Go codebase will hit formatting failures.</comment>
<file context>
@@ -140,19 +141,19 @@ func typeCheckParameter(obj interface{}, expected string, name string) error {
}
-func parameterValueToString(obj interface{}, key string) string {
+func parameterValueToString( obj interface{}, key string ) string {
if reflect.TypeOf(obj).Kind() != reflect.Ptr {
if actualObj, ok := obj.(interface{ GetActualInstanceValue() interface{} }); ok {
</file context>
| if len(headerParams) > 0 { | |
| func parameterValueToString(obj interface{}, key string) string { |
Use
http.Header.Setwhen writingheaderParamstohttp.Headerin the generated Go client.Previously, generated code directly assigned values to the underlying
http.Headermap:This bypasses the header name canonicalization provided by
http.Header.Setand may result in inconsistent header casing or duplicate logical headers.This change replaces direct map assignment with:
Changes
http.Header.Setwhen writingheaderParamstohttp.Header.Related Issue
Fixes #24765
PR checklist
Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
Run the following to [build the project](https://github.com/openapitools/openapi-generator#14---build-projects) and update samples:
If your PR is targeting a particular programming language, @mention the relevant [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) members.
Summary by cubic
Normalizes request header keys in generated Go clients by using
http.Header.Setinstead of direct map assignment. This canonicalizes names and prevents duplicate logical headers.headerParamscontains case-variant duplicates, only one canonical header is sent; which value is kept depends on map iteration order.go.modGo versions to X.Y.0 and add missinggo.sumentries liketerraform-plugin-testing).Written for commit 8e27634. Summary will update on new commits.