mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-12-09 12:06:10 +00:00
Replace periods with underscores in Rust model names (#21480)
Fix issue where period-delimited model names (e.g. microsoft.graph.fido2AuthenticationMethod) were being converted to unwieldy names with "Period" substitutions. Now periods are replaced with underscores like hyphens, resulting in cleaner and more idiomatic Rust identifiers. Fixes #15254
This commit is contained in:
@@ -183,8 +183,8 @@ public abstract class AbstractRustCodegen extends DefaultCodegen implements Code
|
||||
throw new IllegalArgumentException("Unknown CasingType");
|
||||
}
|
||||
|
||||
// Replace hyphens with underscores
|
||||
name = name.replaceAll("-", "_");
|
||||
// Replace hyphens and periods with underscores
|
||||
name = name.replaceAll("[\\.\\-]", "_");
|
||||
|
||||
// Apply special character escapes, e.g. "@type" => "At_type"
|
||||
// Remove the trailing underscore if necessary
|
||||
|
||||
@@ -36,6 +36,10 @@ public class AbstractRustCodegenTest {
|
||||
// Hyphens should be replaced (https://github.com/OpenAPITools/openapi-generator/commit/4cb7f1d6135aa3a42ff38cf89771105c40e7e5a9)
|
||||
Assert.assertEquals(sanitizeSnakeCase.apply("pet-name"), "pet_name");
|
||||
|
||||
// Periods should be replaced with underscores (https://github.com/OpenAPITools/openapi-generator/issues/15254)
|
||||
Assert.assertEquals(sanitizeSnakeCase.apply("microsoft.graph.fido2AuthenticationMethod"), "microsoft_graph_fido2_authentication_method");
|
||||
Assert.assertEquals(sanitizeCamelCase.apply("microsoft.graph.user"), "MicrosoftGraphUser");
|
||||
|
||||
// Special character mappings are applied
|
||||
Assert.assertEquals(sanitizeSnakeCase.apply("@type"), "at_type");
|
||||
Assert.assertEquals(sanitizeCamelCase.apply("@type"), "AtType");
|
||||
|
||||
Reference in New Issue
Block a user