Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/generators/go.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
|structPrefix|whether to prefix struct with the class name. e.g. DeletePetOpts => PetApiDeletePetOpts| |false|
|useDefaultValuesForRequiredVars|Use default values for required variables when available| |false|
|useHttpHeaderSet|When setting HTTP request headers, use http.Header.Set with canonicalized header names| |false|
|useOneOfDiscriminatorLookup|Use the discriminator's mapping in oneOf to speed up the model lookup. IMPORTANT: Validation (e.g. one and only one match in oneOf's schemas) will be skipped.| |false|
|withAWSV4Signature|whether to include AWS v4 signature support| |false|
|withGoMod|Generate go.mod and go.sum| |true|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public abstract class AbstractGoCodegen extends DefaultCodegen implements Codege
protected boolean generateUnmarshalJSON = true;
@Setter
protected boolean useDefaultValuesForRequiredVars = false;
@Setter
protected boolean useHttpHeaderSet = false;

@Setter
protected String packageName = "openapi";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
public static final String MODEL_FILE_FOLDER = "modelFileFolder";
public static final String WITH_GO_MOD = "withGoMod";
public static final String USE_DEFAULT_VALUES_FOR_REQUIRED_VARS = "useDefaultValuesForRequiredVars";
public static final String USE_HTTP_HEADER_SET = "useHttpHeaderSet";
public static final String IMPORT_VALIDATOR = "importValidator";
@Setter protected String goImportAlias = "openapiclient";
protected boolean isGoSubmodule = false;
Expand Down Expand Up @@ -138,6 +139,7 @@ public GoClientCodegen() {
cliOptions.add(CliOption.newBoolean(WITH_AWSV4_SIGNATURE, "whether to include AWS v4 signature support"));
cliOptions.add(CliOption.newBoolean(GENERATE_INTERFACES, "Generate interfaces for api classes"));
cliOptions.add(CliOption.newBoolean(USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, "Use default values for required variables when available"));
cliOptions.add(CliOption.newBoolean(USE_HTTP_HEADER_SET, "When setting HTTP request headers, use http.Header.Set with canonicalized header names"));

// option to change the order of form/body parameter
cliOptions.add(CliOption.newBoolean(
Expand Down Expand Up @@ -276,6 +278,11 @@ public void processOpts() {
additionalProperties.put(USE_DEFAULT_VALUES_FOR_REQUIRED_VARS, useDefaultValuesForRequiredVars);
}

if (additionalProperties.containsKey(USE_HTTP_HEADER_SET)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

setUseHttpHeaderSet(Boolean.parseBoolean(additionalProperties.get(USE_HTTP_HEADER_SET).toString()));
additionalProperties.put(USE_HTTP_HEADER_SET, useHttpHeaderSet);
}

// Generate the 'signing.py' module, but only if the 'HTTP signature' security scheme is specified in the OAS.
Map<String, SecurityScheme> securitySchemeMap = openAPI != null ?
(openAPI.getComponents() != null ? openAPI.getComponents().getSecuritySchemes() : null) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,12 @@ func (c *APIClient) prepareRequest(
if len(headerParams) > 0 {
headers := http.Header{}
for h, v := range headerParams {
{{#useHttpHeaderSet}}
headers.Set(h, v)
{{/useHttpHeaderSet}}
{{^useHttpHeaderSet}}
headers[h] = []string{v}
{{/useHttpHeaderSet}}
}
localVarRequest.Header = headers
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ protected void verifyOptions() {
verify(clientCodegen).setGenerateUnmarshalJSON(GoClientOptionsProvider.GENERATE_UNMARSHAL_JSON_VALUE);
verify(clientCodegen).setUseDefaultValuesForRequiredVars(GoClientOptionsProvider.USE_DEFAULT_VALUES_FOR_REQUIRED_VARS_VALUE);
verify(clientCodegen).setEnumUnknownDefaultCase(Boolean.parseBoolean(GoClientOptionsProvider.ENUM_UNKNOWN_DEFAULT_CASE_VALUE));
verify(clientCodegen).setUseHttpHeaderSet(GoClientOptionsProvider.USE_HTTP_HEADER_SET);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public class GoClientOptionsProvider implements OptionsProvider {
public static final boolean GENERATE_UNMARSHAL_JSON_VALUE = true;
public static final boolean USE_DEFAULT_VALUES_FOR_REQUIRED_VARS_VALUE = true;
public static final String ENUM_UNKNOWN_DEFAULT_CASE_VALUE = "false";
public static final boolean USE_HTTP_HEADER_SET = true;


@Override
public String getLanguage() {
Expand Down Expand Up @@ -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")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Suggested change
.put("useHttpHeaderSet", "true")
.put("useHttpHeaderSet", String.valueOf(USE_HTTP_HEADER_SET))

.build();
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/echo_api/go-external-refs/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/client/echo_api/go/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/client/others/go/oneof-anyof-required/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions samples/client/petstore/go/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func TestAPIKeyNoPrefix(t *testing.T) {
}

reqb, _ := httputil.DumpRequest(r.Request, true)
if !strings.Contains((string)(reqb), "Api_key: TEST123") {
if !strings.Contains((string)(reqb), "api_key: TEST123") {
t.Errorf("APIKey Authentication is missing")
}

Expand Down Expand Up @@ -124,7 +124,7 @@ func TestAPIKeyWithPrefix(t *testing.T) {
}

reqb, _ := httputil.DumpRequest(r.Request, true)
if !strings.Contains((string)(reqb), "Api_key: Bearer TEST123") {
if !strings.Contains((string)(reqb), "api_key: Bearer TEST123") {
t.Errorf("APIKey Authentication is missing")
}

Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/go/go-petstore/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions samples/openapi3/client/petstore/go/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func TestAPIKeyNoPrefix(t *testing.T) {
}

reqb, _ := httputil.DumpRequest(r.Request, true)
if !strings.Contains((string)(reqb), "Api_key: TEST123") {
if !strings.Contains((string)(reqb), "api_key: TEST123") {
t.Errorf("APIKey Authentication is missing")
}

Expand Down Expand Up @@ -186,7 +186,7 @@ func TestAPIKeyWithPrefix(t *testing.T) {
}

reqb, _ := httputil.DumpRequest(r.Request, true)
if !strings.Contains((string)(reqb), "Api_key: Bearer TEST123") {
if !strings.Contains((string)(reqb), "api_key: Bearer TEST123") {
t.Errorf("APIKey Authentication is missing")
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/openapi3/client/petstore/go/go-petstore/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading