Skip to content

Commit

Permalink
add opt-out word separation handling step to SanitizeName for use by …
Browse files Browse the repository at this point in the history
…the UnsanitaryName init helper
  • Loading branch information
Tyler-IN committed May 27, 2024
1 parent ab5f4d8 commit 2bd866b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/libs/OpenApiGenerator.Core/Models/PropertyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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');
Expand All @@ -95,6 +95,14 @@ static bool InvalidSubsequentChar(char ch)
return "";
}

if (!skipHandlingWordSeparators)
{
name = name
.ReplacePlusAndMinusOnStart()
.UseWordSeparator('_', '+', '-', '/')
.UseWordSeparator('(', '[', ']', ')');
}

if (InvalidFirstChar(name[0]))
{
name = $"_{name}";
Expand Down

0 comments on commit 2bd866b

Please sign in to comment.