Skip to content

Commit ac45e3d

Browse files
authored
add enum name mapping feature to the rust generators (#17290)
1 parent b19bc59 commit ac45e3d

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

bin/configs/rust-reqwest-petstore.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ templateDir: modules/openapi-generator/src/main/resources/rust
66
additionalProperties:
77
supportAsync: false
88
packageName: petstore-reqwest
9+
enumNameMappings:
10+
delivered: shipped

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractRustCodegen.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,12 @@ public String toModelDocFilename(String name) {
285285
}
286286

287287
//// Enum naming ////
288-
289288
@Override
290289
public String toEnumVarName(String name, String datatype) {
290+
if (enumNameMapping.containsKey(name)) {
291+
return enumNameMapping.get(name);
292+
}
293+
291294
// Empty strings need to be mapped to "Empty"
292295
// https://github.com/OpenAPITools/openapi-generator/issues/13453
293296
if (Strings.isNullOrEmpty(name)) {

samples/client/petstore/rust/reqwest/petstore/src/models/order.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub enum Status {
5151
#[serde(rename = "approved")]
5252
Approved,
5353
#[serde(rename = "delivered")]
54-
Delivered,
54+
shipped,
5555
}
5656

5757
impl Default for Status {

0 commit comments

Comments
 (0)