Skip to content

Commit

Permalink
[Golang][client] Allow generating go client code as a submodule. (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkabrda authored and wing328 committed Jun 5, 2019
1 parent 9f1b938 commit 66bf0dc
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/generators/go.md
Expand Up @@ -10,6 +10,7 @@ sidebar_label: go
|packageName|Go package name (convention: lowercase).| |openapi| |packageName|Go package name (convention: lowercase).| |openapi|
|packageVersion|Go package version.| |1.0.0| |packageVersion|Go package version.| |1.0.0|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|isGoSubmodule|whether the generated Go module is a submodule| |false|
|withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false| |withGoCodegenComment|whether to include Go codegen comment to disable Go Lint and collapse by default GitHub in PRs and diffs| |false|
|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| |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|
|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| |prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false|
Expand Up @@ -69,6 +69,9 @@ public class CodegenConstants {
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment"; public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
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"; 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";


public static final String IS_GO_SUBMODULE = "isGoSubmodule";
public static final String IS_GO_SUBMODULE_DESC = "whether the generated Go module is a submodule";

public static final String GROUP_ID = "groupId"; public static final String GROUP_ID = "groupId";
public static final String GROUP_ID_DESC = "groupId in generated pom.xml"; public static final String GROUP_ID_DESC = "groupId in generated pom.xml";


Expand Down
Expand Up @@ -33,6 +33,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
protected String packageVersion = "1.0.0"; protected String packageVersion = "1.0.0";
protected String apiDocPath = "docs/"; protected String apiDocPath = "docs/";
protected String modelDocPath = "docs/"; protected String modelDocPath = "docs/";
protected boolean isGoSubmodule = false;
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment"; public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
public static final String WITH_XML = "withXml"; public static final String WITH_XML = "withXml";


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


cliOptions.add(CliOption.newBoolean(CodegenConstants.IS_GO_SUBMODULE, CodegenConstants.IS_GO_SUBMODULE_DESC));
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")); 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"));
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)")); 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)"));


Expand Down Expand Up @@ -111,6 +113,13 @@ public void processOpts() {
additionalProperties.put(WITH_XML, "true"); additionalProperties.put(WITH_XML, "true");
} }
} }

if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) {
setIsGoSubmodule(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.IS_GO_SUBMODULE).toString()));
if (isGoSubmodule) {
additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, "true");
}
}
} }


/** /**
Expand Down Expand Up @@ -184,4 +193,8 @@ public void setPackageVersion(String packageVersion) {
this.packageVersion = packageVersion; this.packageVersion = packageVersion;
} }


public void setIsGoSubmodule(boolean isGoSubmodule) {
this.isGoSubmodule = isGoSubmodule;
}

} }
@@ -1,4 +1,4 @@
module github.com/{{gitUserId}}/{{gitRepoId}} module github.com/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}


require ( require (
github.com/antihax/optional v0.0.0-20180406194304-ca021399b1a6 github.com/antihax/optional v0.0.0-20180406194304-ca021399b1a6
Expand Down
Expand Up @@ -52,6 +52,8 @@ protected void setExpectations() {
times = 1; times = 1;
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(GoClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE)); clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(GoClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
times = 1; times = 1;
clientCodegen.setIsGoSubmodule(Boolean.valueOf(GoClientOptionsProvider.IS_GO_SUBMODULE_VALUE));
times = 1;
}}; }};
} }
} }
Expand Up @@ -29,6 +29,7 @@ public class GoClientOptionsProvider implements OptionsProvider {
public static final boolean WITH_GO_CODEGEN_COMMENT_VALUE = true; public static final boolean WITH_GO_CODEGEN_COMMENT_VALUE = true;
public static final boolean WITH_XML_VALUE = true; public static final boolean WITH_XML_VALUE = true;
public static final Boolean PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = true; public static final Boolean PREPEND_FORM_OR_BODY_PARAMETERS_VALUE = true;
public static final boolean IS_GO_SUBMODULE_VALUE = true;


@Override @Override
public String getLanguage() { public String getLanguage() {
Expand All @@ -45,6 +46,7 @@ public Map<String, String> createOptions() {
.put(CodegenConstants.WITH_GO_CODEGEN_COMMENT, "true") .put(CodegenConstants.WITH_GO_CODEGEN_COMMENT, "true")
.put(CodegenConstants.WITH_XML, "true") .put(CodegenConstants.WITH_XML, "true")
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, "true") .put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, "true")
.put(CodegenConstants.IS_GO_SUBMODULE, "true")
.build(); .build();
} }


Expand Down

0 comments on commit 66bf0dc

Please sign in to comment.