From 49f1f14d9701914c3dd948d2162add1f3bc05235 Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Tue, 21 Jul 2020 19:58:04 -0400 Subject: [PATCH 1/2] Added enumClassPrefix option to Go server generation --- docs/generators/go-server.md | 1 + .../openapitools/codegen/languages/GoServerCodegen.java | 9 ++++++++- .../src/main/resources/go-server/model.mustache | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/generators/go-server.md b/docs/generators/go-server.md index 7eecfc75a0ba..15d771015238 100644 --- a/docs/generators/go-server.md +++ b/docs/generators/go-server.md @@ -11,6 +11,7 @@ sidebar_label: go-server |packageVersion|Go package version.| |1.0.0| |serverPort|The network port the generated server binds to| |8080| |sourceFolder|source folder for generated code| |go| +|enumClassPrefix|Prefix enum with class name| |false| ## IMPORT MAPPING diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java index e13042125492..7ae1632e5bba 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java @@ -104,7 +104,7 @@ public GoServerCodegen() { /* * Service templates. You can write services for each Api file with the apiTemplateFiles map. - These services are skeletons built to implement the logic of your api using the + These services are skeletons built to implement the logic of your api using the expected parameters and response. */ apiTemplateFiles.put( @@ -185,6 +185,13 @@ public void processOpts() { additionalProperties.put("featureCORS", corsFeatureEnabled); } + 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"); + } + } + modelPackage = packageName; apiPackage = packageName; diff --git a/modules/openapi-generator/src/main/resources/go-server/model.mustache b/modules/openapi-generator/src/main/resources/go-server/model.mustache index b6ae9ba9f349..3b5b5345a5a3 100644 --- a/modules/openapi-generator/src/main/resources/go-server/model.mustache +++ b/modules/openapi-generator/src/main/resources/go-server/model.mustache @@ -11,7 +11,7 @@ type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/form const ( {{#allowableValues}} {{#enumVars}} - {{name}} {{{classname}}} = {{{value}}} + {{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}} {{/enumVars}} {{/allowableValues}} ){{/isEnum}}{{^isEnum}}{{#description}} From 7025e76c972fb9a822a4d811256cb1a2cec5436e Mon Sep 17 00:00:00 2001 From: Mike Raineri Date: Thu, 30 Jul 2020 13:47:30 -0400 Subject: [PATCH 2/2] Using literal 'true' instead of string --- .../org/openapitools/codegen/languages/GoServerCodegen.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java index 7ae1632e5bba..62bb6a67e9b3 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoServerCodegen.java @@ -188,7 +188,7 @@ public void processOpts() { 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, true); } }