From 2bd866b6c6eadaa76cb207c7d71aa90422b40c68 Mon Sep 17 00:00:00 2001 From: Tyler Young Date: Mon, 27 May 2024 02:48:14 -0400 Subject: [PATCH] add opt-out word separation handling step to SanitizeName for use by the UnsanitaryName init helper --- .../OpenApiGenerator.Core/Models/PropertyData.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs index 082a672aab..d14048d2d9 100644 --- a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs +++ b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs @@ -56,7 +56,7 @@ public static PropertyData FromSchema( name = name.FixPropertyName(parents.Last().ClassName); } - name = SanitizeName(name); + name = SanitizeName(name, true); return new PropertyData( Id: schema.Key, @@ -77,7 +77,7 @@ public static PropertyData FromSchema( Summary: schema.Value.GetSummary()); } - private static string SanitizeName(string? name) + private static string SanitizeName(string? name, bool skipHandlingWordSeparators = false) { static bool InvalidFirstChar(char ch) => ch is not ('_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z'); @@ -95,6 +95,14 @@ static bool InvalidSubsequentChar(char ch) return ""; } + if (!skipHandlingWordSeparators) + { + name = name + .ReplacePlusAndMinusOnStart() + .UseWordSeparator('_', '+', '-', '/') + .UseWordSeparator('(', '[', ']', ')'); + } + if (InvalidFirstChar(name[0])) { name = $"_{name}";