diff --git a/src/libs/OpenApiGenerator.Core/Extensions/OpenApiExtensions.cs b/src/libs/OpenApiGenerator.Core/Extensions/OpenApiExtensions.cs index 7f227e155b..0e3c27c9f1 100644 --- a/src/libs/OpenApiGenerator.Core/Extensions/OpenApiExtensions.cs +++ b/src/libs/OpenApiGenerator.Core/Extensions/OpenApiExtensions.cs @@ -207,7 +207,7 @@ public static PropertyData ToEnumValue( return PropertyData.Default with { Id = id, - Name = name, + UnsanitaryName = name, }; } diff --git a/src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs b/src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs index 15bee559cb..5c9215d719 100644 --- a/src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs +++ b/src/libs/OpenApiGenerator.Core/Generation/Data.Methods.cs @@ -97,7 +97,7 @@ public static ImmutableArray PrepareData( ? [ .. includedTags.Select(x => PropertyData.Default with { - Name = x.Name.ToClassName(), + UnsanitaryName = x.Name.ToClassName(), Type = TypeData.Default with { CSharpType = $"{x.Name.ToClassName()}Client", diff --git a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs index dabc2c83db..082a672aab 100644 --- a/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs +++ b/src/libs/OpenApiGenerator.Core/Models/PropertyData.cs @@ -1,3 +1,4 @@ +using System.Diagnostics; using System.Text; using Microsoft.OpenApi.Models; using OpenApiGenerator.Core.Extensions; @@ -76,7 +77,7 @@ public static PropertyData FromSchema( Summary: schema.Value.GetSummary()); } - private static string SanitizeName(string name) + private static string SanitizeName(string? name) { static bool InvalidFirstChar(char ch) => ch is not ('_' or >= 'A' and <= 'Z' or >= 'a' and <= 'z'); @@ -88,6 +89,11 @@ static bool InvalidSubsequentChar(char ch) or >= 'a' and <= 'z' or >= '0' and <= '9' ); + + if (name is null || name.Length == 0) + { + return ""; + } if (InvalidFirstChar(name[0])) { @@ -121,6 +127,11 @@ static bool InvalidSubsequentChar(char ch) .ReplaceIfEquals("base", "@base") .ReplaceIfEquals("protected", "@protected"); + public string UnsanitaryName + { + init => Name = SanitizeName(value); + } + public string ArgumentName { get