Add option to use http.Header.Set when setting headers in Go client - #24791
Conversation
There was a problem hiding this comment.
2 issues found across 17 files
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/openapi3/client/petstore/go/go-petstore/client.go">
<violation number="1" location="samples/openapi3/client/petstore/go/go-petstore/client.go:426">
P2: When HTTP signature auth signs `x-api-key`, this assignment stores that casing, but `SignRequest` indexes `X-Api-Key` and returns an error. Use a case-insensitive lookup there or preserve a canonical key for signing.</violation>
</file>
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java:281">
P2: The new useHttpHeaderSet option has no test coverage. Every other Go generator option is exercised in GoClientOptionsTest via GoClientOptionsProvider, but this one is skipped, so a regression in wiring (e.g. the option not being parsed or written back) would pass the build silently. Add USE_HTTP_HEADER_SET to GoClientOptionsProvider, verify setUseHttpHeaderSet in GoClientOptionsTest, and add a test asserting the generated prepareRequest uses headers.Set when true and direct assignment when false.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| headers := http.Header{} | ||
| for h, v := range headerParams { | ||
| headers.Set(h, v) | ||
| headers[h] = []string{v} |
There was a problem hiding this comment.
P2: When HTTP signature auth signs x-api-key, this assignment stores that casing, but SignRequest indexes X-Api-Key and returns an error. Use a case-insensitive lookup there or preserve a canonical key for signing.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/openapi3/client/petstore/go/go-petstore/client.go, line 426:
<comment>When HTTP signature auth signs `x-api-key`, this assignment stores that casing, but `SignRequest` indexes `X-Api-Key` and returns an error. Use a case-insensitive lookup there or preserve a canonical key for signing.</comment>
<file context>
@@ -423,7 +423,7 @@ func (c *APIClient) prepareRequest(
headers := http.Header{}
for h, v := range headerParams {
- headers.Set(h, v)
+ headers[h] = []string{v}
}
localVarRequest.Header = headers
</file context>
| additionalProperties.put(USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, useDefaultValuesForRequiredVars); | ||
| } | ||
|
|
||
| if (additionalProperties.containsKey(USE_HTTP_HEADER_SET)) { |
There was a problem hiding this comment.
P2: The new useHttpHeaderSet option has no test coverage. Every other Go generator option is exercised in GoClientOptionsTest via GoClientOptionsProvider, but this one is skipped, so a regression in wiring (e.g. the option not being parsed or written back) would pass the build silently. Add USE_HTTP_HEADER_SET to GoClientOptionsProvider, verify setUseHttpHeaderSet in GoClientOptionsTest, and add a test asserting the generated prepareRequest uses headers.Set when true and direct assignment when false.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java, line 281:
<comment>The new useHttpHeaderSet option has no test coverage. Every other Go generator option is exercised in GoClientOptionsTest via GoClientOptionsProvider, but this one is skipped, so a regression in wiring (e.g. the option not being parsed or written back) would pass the build silently. Add USE_HTTP_HEADER_SET to GoClientOptionsProvider, verify setUseHttpHeaderSet in GoClientOptionsTest, and add a test asserting the generated prepareRequest uses headers.Set when true and direct assignment when false.</comment>
<file context>
@@ -276,6 +278,11 @@ public void processOpts() {
additionalProperties.put(USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, useDefaultValuesForRequiredVars);
}
+ if (additionalProperties.containsKey(USE_HTTP_HEADER_SET)) {
+ setUseHttpHeaderSet(Boolean.parseBoolean(additionalProperties.get(USE_HTTP_HEADER_SET).toString()));
+ additionalProperties.put(USE_HTTP_HEADER_SET, useHttpHeaderSet);
</file context>
There was a problem hiding this comment.
1 issue found across 2 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="modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GoClientOptionsProvider.java">
<violation number="1" location="modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GoClientOptionsProvider.java:73">
P3: The new `USE_HTTP_HEADER_SET` constant is never referenced in `createOptions()`, which hardcodes the literal "true" instead. The test asserts `setUseHttpHeaderSet(USE_HTTP_HEADER_SET)`, so if the constant value is ever changed the option map and the test silently diverge. Use `String.valueOf(USE_HTTP_HEADER_SET)` (or the key constant `GoClientCodegen.USE_HTTP_HEADER_SET`) to keep them in sync.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| .put("structPrefix", "true") | ||
| .put(CodegenConstants.USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, "true") | ||
| .put(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, ENUM_UNKNOWN_DEFAULT_CASE_VALUE) | ||
| .put("useHttpHeaderSet", "true") |
There was a problem hiding this comment.
P3: The new USE_HTTP_HEADER_SET constant is never referenced in createOptions(), which hardcodes the literal "true" instead. The test asserts setUseHttpHeaderSet(USE_HTTP_HEADER_SET), so if the constant value is ever changed the option map and the test silently diverge. Use String.valueOf(USE_HTTP_HEADER_SET) (or the key constant GoClientCodegen.USE_HTTP_HEADER_SET) to keep them in sync.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GoClientOptionsProvider.java, line 73:
<comment>The new `USE_HTTP_HEADER_SET` constant is never referenced in `createOptions()`, which hardcodes the literal "true" instead. The test asserts `setUseHttpHeaderSet(USE_HTTP_HEADER_SET)`, so if the constant value is ever changed the option map and the test silently diverge. Use `String.valueOf(USE_HTTP_HEADER_SET)` (or the key constant `GoClientCodegen.USE_HTTP_HEADER_SET`) to keep them in sync.</comment>
<file context>
@@ -68,6 +70,7 @@ public Map<String, String> createOptions() {
.put("structPrefix", "true")
.put(CodegenConstants.USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, "true")
.put(CodegenConstants.ENUM_UNKNOWN_DEFAULT_CASE, ENUM_UNKNOWN_DEFAULT_CASE_VALUE)
+ .put("useHttpHeaderSet", "true")
.build();
}
</file context>
| .put("useHttpHeaderSet", "true") | |
| .put("useHttpHeaderSet", String.valueOf(USE_HTTP_HEADER_SET)) |
a follow up pr to #24766
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
Adds a
useHttpHeaderSetoption to the Go client generator that changes howprepareRequestassigns headers. The new default preserves header-name casing from the API spec instead of canonicalizing; setuseHttpHeaderSet=trueto restore the previoushttp.Header.Setbehavior.Migration
useHttpHeaderSet=true.Written for commit c0146b6. Summary will update on new commits.