Skip to content

Commit 66bf0dc

Browse files
Slavek Kabrdawing328
Slavek Kabrda
authored andcommitted
[Golang][client] Allow generating go client code as a submodule. (#3012)
1 parent 9f1b938 commit 66bf0dc

File tree

6 files changed

+22
-1
lines changed

6 files changed

+22
-1
lines changed

docs/generators/go.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ sidebar_label: go
1010
|packageName|Go package name (convention: lowercase).| |openapi|
1111
|packageVersion|Go package version.| |1.0.0|
1212
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
13+
|isGoSubmodule|whether the generated Go module is a submodule| |false|
1314
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false|
1415
|withXml|whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)| |false|
1516
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenConstants.java

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ public class CodegenConstants {
6969
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
7070
public static final String WITH_GO_CODEGEN_COMMENT_DESC = "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs";
7171

72+
public static final String IS_GO_SUBMODULE = "isGoSubmodule";
73+
public static final String IS_GO_SUBMODULE_DESC = "whether the generated Go module is a submodule";
74+
7275
public static final String GROUP_ID = "groupId";
7376
public static final String GROUP_ID_DESC = "groupId in generated pom.xml";
7477

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoClientCodegen.java

+13
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
3333
protected String packageVersion = "1.0.0";
3434
protected String apiDocPath = "docs/";
3535
protected String modelDocPath = "docs/";
36+
protected boolean isGoSubmodule = false;
3637
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
3738
public static final String WITH_XML = "withXml";
3839

@@ -51,6 +52,7 @@ public GoClientCodegen() {
5152
// default HIDE_GENERATION_TIMESTAMP to true
5253
hideGenerationTimestamp = Boolean.TRUE;
5354

55+
cliOptions.add(CliOption.newBoolean(CodegenConstants.IS_GO_SUBMODULE, CodegenConstants.IS_GO_SUBMODULE_DESC));
5456
cliOptions.add(CliOption.newBoolean(WITH_GO_CODEGEN_COMMENT, "whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs"));
5557
cliOptions.add(CliOption.newBoolean(WITH_XML, "whether to include support for application/xml content type and include XML annotations in the model (works with libraries that provide support for JSON and XML)"));
5658

@@ -111,6 +113,13 @@ public void processOpts() {
111113
additionalProperties.put(WITH_XML, "true");
112114
}
113115
}
116+
117+
if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) {
118+
setIsGoSubmodule(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.IS_GO_SUBMODULE).toString()));
119+
if (isGoSubmodule) {
120+
additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, "true");
121+
}
122+
}
114123
}
115124

116125
/**
@@ -184,4 +193,8 @@ public void setPackageVersion(String packageVersion) {
184193
this.packageVersion = packageVersion;
185194
}
186195

196+
public void setIsGoSubmodule(boolean isGoSubmodule) {
197+
this.isGoSubmodule = isGoSubmodule;
198+
}
199+
187200
}

modules/openapi-generator/src/main/resources/go/go.mod.mustache

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/{{gitUserId}}/{{gitRepoId}}
1+
module github.com/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}
22

33
require (
44
github.com/antihax/optional v0.0.0-20180406194304-ca021399b1a6

modules/openapi-generator/src/test/java/org/openapitools/codegen/go/GoClientOptionsTest.java

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ protected void setExpectations() {
5252
times = 1;
5353
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(GoClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
5454
times = 1;
55+
clientCodegen.setIsGoSubmodule(Boolean.valueOf(GoClientOptionsProvider.IS_GO_SUBMODULE_VALUE));
56+
times = 1;
5557
}};
5658
}
5759
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/options/GoClientOptionsProvider.java

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ public class GoClientOptionsProvider implements OptionsProvider {
2929
public static final boolean WITH_GO_CODEGEN_COMMENT_VALUE = true;
3030
public static final boolean WITH_XML_VALUE = true;
3131
public static final Boolean PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = true;
32+
public static final boolean IS_GO_SUBMODULE_VALUE = true;
3233

3334
@Override
3435
public String getLanguage() {
@@ -45,6 +46,7 @@ public Map<String, String> createOptions() {
4546
.put(CodegenConstants.WITH_GO_CODEGEN_COMMENT, "true")
4647
.put(CodegenConstants.WITH_XML, "true")
4748
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, "true")
49+
.put(CodegenConstants.IS_GO_SUBMODULE, "true")
4850
.build();
4951
}
5052

0 commit comments

Comments
 (0)