mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-05-12 20:50:55 +00:00
[Go] minor improvements (#7134)
* fix boolean option, add eum prefix option * update code format * optimize code
This commit is contained in:
parent
be02a33c72
commit
201ac77d0c
@ -5,6 +5,7 @@ sidebar_label: go-server
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|enumClassPrefix|Prefix enum with class name| |false|
|
||||
|featureCORS|Enable Cross-Origin Resource Sharing middleware| |false|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||
|
@ -137,44 +137,32 @@ public class GoClientCodegen extends AbstractGoCodegen {
|
||||
|
||||
if (additionalProperties.containsKey(WITH_GO_CODEGEN_COMMENT)) {
|
||||
setWithGoCodegenComment(Boolean.parseBoolean(additionalProperties.get(WITH_GO_CODEGEN_COMMENT).toString()));
|
||||
if (withGoCodegenComment) {
|
||||
additionalProperties.put(WITH_GO_CODEGEN_COMMENT, "true");
|
||||
}
|
||||
additionalProperties.put(WITH_GO_CODEGEN_COMMENT, withGoCodegenComment);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(WITH_AWSV4_SIGNATURE)) {
|
||||
setWithAWSV4Signature(Boolean.parseBoolean(additionalProperties.get(WITH_AWSV4_SIGNATURE).toString()));
|
||||
if (withAWSV4Signature) {
|
||||
additionalProperties.put(WITH_AWSV4_SIGNATURE, "true");
|
||||
}
|
||||
additionalProperties.put(WITH_AWSV4_SIGNATURE, withAWSV4Signature);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(WITH_XML)) {
|
||||
setWithXml(Boolean.parseBoolean(additionalProperties.get(WITH_XML).toString()));
|
||||
if (withXml) {
|
||||
additionalProperties.put(WITH_XML, "true");
|
||||
}
|
||||
additionalProperties.put(WITH_XML, withXml);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ENUM_CLASS_PREFIX)) {
|
||||
setEnumClassPrefix(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.ENUM_CLASS_PREFIX).toString()));
|
||||
if (enumClassPrefix) {
|
||||
additionalProperties.put(CodegenConstants.ENUM_CLASS_PREFIX, "true");
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.ENUM_CLASS_PREFIX, enumClassPrefix);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.IS_GO_SUBMODULE)) {
|
||||
setIsGoSubmodule(Boolean.parseBoolean(additionalProperties.get(CodegenConstants.IS_GO_SUBMODULE).toString()));
|
||||
if (isGoSubmodule) {
|
||||
additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, "true");
|
||||
}
|
||||
additionalProperties.put(CodegenConstants.IS_GO_SUBMODULE, isGoSubmodule);
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(STRUCT_PREFIX)) {
|
||||
setStructPrefix(Boolean.parseBoolean(additionalProperties.get(STRUCT_PREFIX).toString()));
|
||||
if (structPrefix) {
|
||||
additionalProperties.put(STRUCT_PREFIX, "true");
|
||||
}
|
||||
additionalProperties.put(STRUCT_PREFIX, structPrefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,7 @@
|
||||
|
||||
package org.openapitools.codegen.languages;
|
||||
|
||||
import org.openapitools.codegen.CliOption;
|
||||
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.*;
|
||||
import org.openapitools.codegen.meta.features.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@ -83,6 +78,8 @@ public class GoServerCodegen extends AbstractGoCodegen {
|
||||
optFeatureCORS.defaultValue(corsFeatureEnabled.toString());
|
||||
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.
|
||||
* 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) {
|
||||
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 {
|
||||
this.setServerPort(Integer.parseInt(additionalProperties.get("serverPort").toString()));
|
||||
additionalProperties.put("serverPort", serverPort);
|
||||
}
|
||||
catch (NumberFormatException e)
|
||||
{
|
||||
} catch (NumberFormatException e) {
|
||||
LOGGER.warn("serverPort is not a valid integer... defaulting to {}", serverPort);
|
||||
additionalProperties.put("serverPort", serverPort);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user