[REQ] Added enumClassPrefix option to Go server generation (#7008)

* Added enumClassPrefix option to Go server generation

* Using literal 'true' instead of string
This commit is contained in:
Mike Raineri 2020-08-05 04:33:58 -04:00 committed by GitHub
parent c1b8c294aa
commit 51c45eb28b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 2 deletions

View File

@ -11,6 +11,7 @@ sidebar_label: go-server
|packageVersion|Go package version.| |1.0.0| |packageVersion|Go package version.| |1.0.0|
|serverPort|The network port the generated server binds to| |8080| |serverPort|The network port the generated server binds to| |8080|
|sourceFolder|source folder for generated code| |go| |sourceFolder|source folder for generated code| |go|
|enumClassPrefix|Prefix enum with class name| |false|
## IMPORT MAPPING ## IMPORT MAPPING

View File

@ -104,7 +104,7 @@ public class GoServerCodegen extends AbstractGoCodegen {
/* /*
* Service templates. You can write services for each Api file with the apiTemplateFiles map. * 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. expected parameters and response.
*/ */
apiTemplateFiles.put( apiTemplateFiles.put(
@ -185,6 +185,13 @@ public class GoServerCodegen extends AbstractGoCodegen {
additionalProperties.put("featureCORS", corsFeatureEnabled); 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; modelPackage = packageName;
apiPackage = packageName; apiPackage = packageName;

View File

@ -11,7 +11,7 @@ type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/form
const ( const (
{{#allowableValues}} {{#allowableValues}}
{{#enumVars}} {{#enumVars}}
{{name}} {{{classname}}} = {{{value}}} {{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
{{/enumVars}} {{/enumVars}}
{{/allowableValues}} {{/allowableValues}}
){{/isEnum}}{{^isEnum}}{{#description}} ){{/isEnum}}{{^isEnum}}{{#description}}