[Go] minor improvements (#7134)

* fix boolean option, add eum prefix option

* update code format

* optimize code
This commit is contained in:
William Cheng 2020-08-06 15:11:20 +08:00 committed by GitHub
parent be02a33c72
commit 201ac77d0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 28 deletions

View File

@ -5,6 +5,7 @@ sidebar_label: go-server
| Option | Description | Values | Default | | Option | Description | Values | Default |
| ------ | ----------- | ------ | ------- | | ------ | ----------- | ------ | ------- |
|enumClassPrefix|Prefix enum with class name| |false|
|featureCORS|Enable Cross-Origin Resource Sharing middleware| |false| |featureCORS|Enable Cross-Origin Resource Sharing middleware| |false|
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true| |hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|packageName|Go package name (convention: lowercase).| |openapi| |packageName|Go package name (convention: lowercase).| |openapi|

View File

@ -137,44 +137,32 @@ public class GoClientCodegen extends AbstractGoCodegen {
if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) { if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) {
setWithGoCodegenComment(Boolean.parseBoolean(additionalProperties.get(WITH_GO_CODEGEN_COMMENT).toString())); setWithGoCodegenComment(Boolean.parseBoolean(additionalProperties.get(WITH_GO_CODEGEN_COMMENT).toString()));
if (withGoCodegenComment) { additionalProperties.put(WITH_GO_CODEGEN_COMMENT, withGoCodegenComment);
additionalProperties.put(WITH_GO_CODEGEN_COMMENT, "true");
}
} }
if (additionalProperties.containsKey(WITH_AWSV4_SIGNATURE)) { if (additionalProperties.containsKey(WITH_AWSV4_SIGNATURE)) {
setWithAWSV4Signature(Boolean.parseBoolean(additionalProperties.get(WITH_AWSV4_SIGNATURE).toString())); setWithAWSV4Signature(Boolean.parseBoolean(additionalProperties.get(WITH_AWSV4_SIGNATURE).toString()));
if (withAWSV4Signature) { additionalProperties.put(WITH_AWSV4_SIGNATURE, withAWSV4Signature);
additionalProperties.put(WITH_AWSV4_SIGNATURE, "true");
}
} }
if (additionalProperties.containsKey(WITH_XML)) { if (additionalProperties.containsKey(WITH_XML)) {
setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString())); setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString()));
if (withXml) { additionalProperties.put(WITH_XML, withXml);
additionalProperties.put(WITH_XML, "true");
}
} }
if (additionalProperties.containsKey(CodegenConstants.ENUM_CLASS_PREFIX)) { if (additionalProperties.containsKey(CodegenConstants.ENUM_CLASS_PREFIX)) {
setEnumClassPrefix(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.ENUM_CLASS_PREFIX).toString())); setEnumClassPrefix(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.ENUM_CLASS_PREFIX).toString()));
if (enumClassPrefix) { additionalProperties.put(CodegenConstants.ENUM_CLASS_PREFIX, enumClassPrefix);
additionalProperties.put(CodegenConstants.ENUM_CLASS_PREFIX, "true");
}
} }
if (additionalProperties.containsKey(CodegenConstants.IS_GO_SUBMODULE)) { if (additionalProperties.containsKey(CodegenConstants.IS_GO_SUBMODULE)) {
setIsGoSubmodule(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.IS_GO_SUBMODULE).toString())); setIsGoSubmodule(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.IS_GO_SUBMODULE).toString()));
if (isGoSubmodule) { additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, isGoSubmodule);
additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, "true");
}
} }
if (additionalProperties.containsKey(STRUCT_PREFIX)) { if (additionalProperties.containsKey(STRUCT_PREFIX)) {
setStructPrefix(Boolean.parseBoolean(additionalProperties.get(STRUCT_PREFIX).toString())); setStructPrefix(Boolean.parseBoolean(additionalProperties.get(STRUCT_PREFIX).toString()));
if (structPrefix) { additionalProperties.put(STRUCT_PREFIX, structPrefix);
additionalProperties.put(STRUCT_PREFIX, "true");
}
} }
} }

View File

@ -17,12 +17,7 @@
package org.openapitools.codegen.languages; package org.openapitools.codegen.languages;
import org.openapitools.codegen.CliOption; import org.openapitools.codegen.*;
import org.openapitools.codegen.CodegenConstants;
import org.openapitools.codegen.CodegenOperation;
import org.openapitools.codegen.CodegenParameter;
import org.openapitools.codegen.CodegenType;
import org.openapitools.codegen.SupportingFile;
import org.openapitools.codegen.meta.features.*; import org.openapitools.codegen.meta.features.*;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -83,6 +78,8 @@ public class GoServerCodegen extends AbstractGoCodegen {
optFeatureCORS.defaultValue(corsFeatureEnabled.toString()); optFeatureCORS.defaultValue(corsFeatureEnabled.toString());
cliOptions.add(optFeatureCORS); cliOptions.add(optFeatureCORS);
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENUM_CLASS_PREFIX, CodegenConstants.ENUM_CLASS_PREFIX_DESC));
/* /*
* Models. You can write model files using the modelTemplateFiles map. * Models. You can write model files using the modelTemplateFiles map.
* if you want to create one template for file, you can do so here. * if you want to create one template for file, you can do so here.
@ -166,13 +163,11 @@ public class GoServerCodegen extends AbstractGoCodegen {
if (additionalProperties.containsKey("serverPort") && additionalProperties.get("serverPort") instanceof Integer) { if (additionalProperties.containsKey("serverPort") && additionalProperties.get("serverPort") instanceof Integer) {
this.setServerPort((int) additionalProperties.get("serverPort")); this.setServerPort((int) additionalProperties.get("serverPort"));
} else if (additionalProperties.containsKey("serverPort") && additionalProperties.get("serverPort") instanceof String){ } else if (additionalProperties.containsKey("serverPort") && additionalProperties.get("serverPort") instanceof String) {
try { try {
this.setServerPort(Integer.parseInt(additionalProperties.get("serverPort").toString())); this.setServerPort(Integer.parseInt(additionalProperties.get("serverPort").toString()));
additionalProperties.put("serverPort", serverPort); additionalProperties.put("serverPort", serverPort);
} } catch (NumberFormatException e) {
catch (NumberFormatException e)
{
LOGGER.warn("serverPort is not a valid integer... defaulting to {}", serverPort); LOGGER.warn("serverPort is not a valid integer... defaulting to {}", serverPort);
additionalProperties.put("serverPort", serverPort); additionalProperties.put("serverPort", serverPort);
} }