forked from loafle/openapi-generator-original
[Golang][client] Allow generating go client code as a submodule. (#3012)
This commit is contained in:
committed by
William Cheng
parent
9f1b9386f1
commit
66bf0dce9e
@@ -10,6 +10,7 @@ sidebar_label: go
|
||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|Go package version.| |1.0.0|
|
||||
|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|
|
||||
|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|
|
||||
|
||||
@@ -69,6 +69,9 @@ public class CodegenConstants {
|
||||
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 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_DESC = "groupId in generated pom.xml";
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
protected String packageVersion = "1.0.0";
|
||||
protected String apiDocPath = "docs/";
|
||||
protected String modelDocPath = "docs/";
|
||||
protected boolean isGoSubmodule = false;
|
||||
public static final String WITH_GO_CODEGEN_COMMENT = "withGoCodegenComment";
|
||||
public static final String WITH_XML = "withXml";
|
||||
|
||||
@@ -51,6 +52,7 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
// default HIDE_GENERATION_TIMESTAMP to 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_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)"));
|
||||
|
||||
@@ -111,6 +113,13 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -184,4 +193,8 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
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 (
|
||||
github.com/antihax/optional v0.0.0-20180406194304-ca021399b1a6
|
||||
|
||||
@@ -52,6 +52,8 @@ public class GoClientOptionsTest extends AbstractOptionsTest {
|
||||
times = 1;
|
||||
clientCodegen.setPrependFormOrBodyParameters(Boolean.valueOf(GoClientOptionsProvider.PREPEND_FORM_OR_BODY_PARAMETERS_VALUE));
|
||||
times = 1;
|
||||
clientCodegen.setIsGoSubmodule(Boolean.valueOf(GoClientOptionsProvider.IS_GO_SUBMODULE_VALUE));
|
||||
times = 1;
|
||||
}};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public class GoClientOptionsProvider implements OptionsProvider {
|
||||
public static final boolean WITH_GO_CODEGEN_COMMENT_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 IS_GO_SUBMODULE_VALUE = true;
|
||||
|
||||
@Override
|
||||
public String getLanguage() {
|
||||
@@ -45,6 +46,7 @@ public class GoClientOptionsProvider implements OptionsProvider {
|
||||
.put(CodegenConstants.WITH_GO_CODEGEN_COMMENT, "true")
|
||||
.put(CodegenConstants.WITH_XML, "true")
|
||||
.put(CodegenConstants.PREPEND_FORM_OR_BODY_PARAMETERS, "true")
|
||||
.put(CodegenConstants.IS_GO_SUBMODULE, "true")
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user