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:
Steven Crake
2025-06-29 08:52:55 +01:00
committed by GitHub
parent d11d008e71
commit 03effd7d05
6 changed files with 56 additions and 42 deletions

View File

@@ -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

View File

@@ -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");