mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
add enum suffic support to rust client (#9107)
This commit is contained in:
@@ -7,6 +7,7 @@ These options may be applied as additional-properties (cli) or configOptions (pl
|
||||
|
||||
| Option | Description | Values | Default |
|
||||
| ------ | ----------- | ------ | ------- |
|
||||
|enumNameSuffix|Suffix that will be appended to all enum names.| ||
|
||||
|hideGenerationTimestamp|Hides the generation timestamp when files are generated.| |true|
|
||||
|library|library template (sub-template) to use.|<dl><dt>**hyper**</dt><dd>HTTP client: Hyper.</dd><dt>**reqwest**</dt><dd>HTTP client: Reqwest.</dd></dl>|reqwest|
|
||||
|packageName|Rust package name (convention: lowercase).| |openapi|
|
||||
|
||||
@@ -54,6 +54,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
protected String modelDocPath = "docs/";
|
||||
protected String apiFolder = "src/apis";
|
||||
protected String modelFolder = "src/models";
|
||||
protected String enumSuffix = ""; // default to empty string for backward compatibility
|
||||
|
||||
public CodegenType getTag() {
|
||||
return CodegenType.CLIENT;
|
||||
@@ -179,6 +180,7 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
.defaultValue(Boolean.TRUE.toString()));
|
||||
cliOptions.add(new CliOption(SUPPORT_MULTIPLE_RESPONSES, "If set, return type wraps an enum of all possible 2xx schemas. This option is for 'reqwest' library only", SchemaTypeUtil.BOOLEAN_TYPE)
|
||||
.defaultValue(Boolean.FALSE.toString()));
|
||||
cliOptions.add(new CliOption(CodegenConstants.ENUM_NAME_SUFFIX, CodegenConstants.ENUM_NAME_SUFFIX_DESC).defaultValue(this.enumSuffix));
|
||||
|
||||
supportedLibraries.put(HYPER_LIBRARY, "HTTP client: Hyper.");
|
||||
supportedLibraries.put(REQWEST_LIBRARY, "HTTP client: Reqwest.");
|
||||
@@ -247,6 +249,10 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
public void processOpts() {
|
||||
super.processOpts();
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.ENUM_NAME_SUFFIX)) {
|
||||
enumSuffix = additionalProperties.get(CodegenConstants.ENUM_NAME_SUFFIX).toString();
|
||||
}
|
||||
|
||||
if (additionalProperties.containsKey(CodegenConstants.PACKAGE_NAME)) {
|
||||
setPackageName((String) additionalProperties.get(CodegenConstants.PACKAGE_NAME));
|
||||
} else {
|
||||
@@ -650,9 +656,13 @@ public class RustClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||
|
||||
@Override
|
||||
public String toEnumName(CodegenProperty property) {
|
||||
String name = property.name;
|
||||
if (!org.apache.commons.lang3.StringUtils.isEmpty(enumSuffix)) {
|
||||
name = name + "_" + enumSuffix;
|
||||
}
|
||||
// camelize the enum name
|
||||
// phone_number => PhoneNumber
|
||||
String enumName = camelize(toModelName(property.name));
|
||||
String enumName = camelize(toModelName(name));
|
||||
|
||||
// remove [] for array or map of enum
|
||||
enumName = enumName.replace("[]", "");
|
||||
|
||||
Reference in New Issue
Block a user