Skip to content
This repository was archived by the owner on Dec 25, 2024. It is now read-only.

Commit e6dd608

Browse files
authored
Rust: Issue #13453 - Empty enum variant names (#13454)
1 parent 4f732c5 commit e6dd608

File tree

16 files changed

+244
-99
lines changed

16 files changed

+244
-99
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ public String toModelDocFilename(String name) {
173173

174174
@Override
175175
public String toEnumVarName(String name, String datatype) {
176+
// Empty strings need to be mapped to "Empty"
177+
// https://github.com/OpenAPITools/openapi-generator/issues/13453
178+
if (Strings.isNullOrEmpty(name)) {
179+
return "Empty";
180+
}
176181
// Rust Enum variants should be camel cased
177182
return sanitizeIdentifier(name, CasingType.CAMEL_CASE, "variant", "enum variant", true);
178183
}

modules/openapi-generator/src/test/java/org/openapitools/codegen/rust/AbstractRustCodegenTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,9 @@ public void testToEnumVarName() {
117117
Assert.assertEquals(fakeRustCodegen.toEnumVarName("SCREAMING_SNAKE_CASE", null), "ScreamingSnakeCase");
118118
// Prefix is added when starting with a number
119119
Assert.assertEquals(fakeRustCodegen.toEnumVarName("1_pending", null), "Variant1Pending");
120+
// Empty strings need to be mapped to "Empty"
121+
// https://github.com/OpenAPITools/openapi-generator/issues/13453
122+
Assert.assertEquals(fakeRustCodegen.toEnumVarName("", null), "Empty");
120123
}
121124

122125
@Test

modules/openapi-generator/src/test/resources/3_0/rust/petstore.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,9 +812,11 @@ components:
812812
- $ref: '#/components/schemas/Baz'
813813
- nullable: false
814814
Baz:
815+
description: Test handling of empty variants
815816
enum:
816817
- A
817818
- B
819+
- ""
818820
type: string
819821
TypeTesting:
820822
description: Test handling of different field data types

samples/client/petstore/rust/.openapi-generator/VERSION

Lines changed: 0 additions & 1 deletion
This file was deleted.

samples/client/petstore/rust/docs/InlineObject.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

samples/client/petstore/rust/docs/InlineObject1.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

samples/client/petstore/rust/hyper/petstore/src/models/baz.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11+
/// Baz : Test handling of empty variants
1112
12-
///
13+
/// Test handling of empty variants
1314
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
1415
pub enum Baz {
1516
#[serde(rename = "A")]
1617
A,
1718
#[serde(rename = "B")]
1819
B,
20+
#[serde(rename = "")]
21+
Empty,
1922

2023
}
2124

@@ -24,6 +27,7 @@ impl ToString for Baz {
2427
match self {
2528
Self::A => String::from("A"),
2629
Self::B => String::from("B"),
30+
Self::Empty => String::from(""),
2731
}
2832
}
2933
}

samples/client/petstore/rust/reqwest/petstore-async/src/models/baz.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11+
/// Baz : Test handling of empty variants
1112
12-
///
13+
/// Test handling of empty variants
1314
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
1415
pub enum Baz {
1516
#[serde(rename = "A")]
1617
A,
1718
#[serde(rename = "B")]
1819
B,
20+
#[serde(rename = "")]
21+
Empty,
1922

2023
}
2124

@@ -24,6 +27,7 @@ impl ToString for Baz {
2427
match self {
2528
Self::A => String::from("A"),
2629
Self::B => String::from("B"),
30+
Self::Empty => String::from(""),
2731
}
2832
}
2933
}

samples/client/petstore/rust/reqwest/petstore-awsv4signature/src/models/baz.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11+
/// Baz : Test handling of empty variants
1112
12-
///
13+
/// Test handling of empty variants
1314
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
1415
pub enum Baz {
1516
#[serde(rename = "A")]
1617
A,
1718
#[serde(rename = "B")]
1819
B,
20+
#[serde(rename = "")]
21+
Empty,
1922

2023
}
2124

@@ -24,6 +27,7 @@ impl ToString for Baz {
2427
match self {
2528
Self::A => String::from("A"),
2629
Self::B => String::from("B"),
30+
Self::Empty => String::from(""),
2731
}
2832
}
2933
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@
88
* Generated by: https://openapi-generator.tech
99
*/
1010

11+
/// Baz : Test handling of empty variants
1112
12-
///
13+
/// Test handling of empty variants
1314
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
1415
pub enum Baz {
1516
#[serde(rename = "A")]
1617
A,
1718
#[serde(rename = "B")]
1819
B,
20+
#[serde(rename = "")]
21+
Empty,
1922

2023
}
2124

@@ -24,6 +27,7 @@ impl ToString for Baz {
2427
match self {
2528
Self::A => String::from("A"),
2629
Self::B => String::from("B"),
30+
Self::Empty => String::from(""),
2731
}
2832
}
2933
}

0 commit comments

Comments
 (0)