forked from loafle/openapi-generator-original
[REQ] [GO] Added enumClassPrefix option to go-gin-server. Used same appro… (#8681)
* [REQ] Added enumClassPrefix option to go-gin-server. Used same approach as #7008 (go-server) modified: docs/generators/go-gin-server.md modified: modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/GoGinServerCodegen.java modified: modules/openapi-generator/src/main/resources/go-gin-server/model.mustache * Fixed CI error in docs
This commit is contained in:
committed by
GitHub
parent
cd0ca65732
commit
3c4015b897
@@ -8,6 +8,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|apiPath|Name of the folder that contains the Go source code| |go|
|
||||
|enumClassPrefix|Prefix enum with class name| |false|
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|packageName|Go package name (convention: lowercase).| |openapi|
|
||||
|packageVersion|Go package version.| |1.0.0|
|
||||
|
||||
@@ -116,6 +116,8 @@ public class GoGinServerCodegen extends AbstractGoCodegen {
|
||||
optServerPort.setType("int");
|
||||
optServerPort.defaultValue(Integer.toString(serverPort));
|
||||
cliOptions.add(optServerPort);
|
||||
|
||||
cliOptions.add(CliOption.newBoolean(CodegenConstants.ENUM_CLASS_PREFIX, CodegenConstants.ENUM_CLASS_PREFIX_DESC));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -165,6 +167,13 @@ public class GoGinServerCodegen extends AbstractGoCodegen {
|
||||
additionalProperties.put("apiPath", apiPath);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ package {{packageName}}
|
||||
{{/-first}} "{{import}}"{{#-last}}
|
||||
)
|
||||
{{/-last}}{{/imports}}{{#model}}{{#isEnum}}{{#description}}// {{{classname}}} : {{{description}}}{{/description}}
|
||||
type {{{name}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
|
||||
type {{{classname}}} {{^format}}{{dataType}}{{/format}}{{#format}}{{{format}}}{{/format}}
|
||||
|
||||
// List of {{{name}}}
|
||||
// List of {{{classname}}}
|
||||
const (
|
||||
{{#allowableValues}}
|
||||
{{#enumVars}}
|
||||
{{name}} {{{classname}}} = {{{value}}}
|
||||
{{#enumClassPrefix}}{{{classname.toUpperCase}}}_{{/enumClassPrefix}}{{name}} {{{classname}}} = {{{value}}}
|
||||
{{/enumVars}}
|
||||
{{/allowableValues}}
|
||||
){{/isEnum}}{{^isEnum}}{{#description}}
|
||||
|
||||
Reference in New Issue
Block a user