Skip to content

Commit

Permalink
Update toSnakeCase to convert this input "imageURL" into "image_url" …
Browse files Browse the repository at this point in the history
…and not "image_u_r_l"
  • Loading branch information
hvuhsg committed May 6, 2024
1 parent ff05cc6 commit 5d099ad
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Kiota.Builder/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int CountNecessaryNewSeparators(ReadOnlySpan<char> span)
int count = 0;
for (var i = 1; i < span.Length; i++)
{
if (char.IsUpper(span[i]) && span[i - 1] is not '_' and not '-')
if (char.IsUpper(span[i]) && span[i - 1] is not '_' and not '-' && !char.IsUpper(span[i - 1]))
{
count++;
}
Expand All @@ -105,7 +105,10 @@ static int CountNecessaryNewSeparators(ReadOnlySpan<char> span)
}
else if (char.IsUpper(current))
{
if (nameSpan[i - 1] != '_') span[counter++] = separator;
if (nameSpan[i - 1] is not '_' && !char.IsUpper(nameSpan[i - 1]))
{
span[counter++] = separator;
}
span[counter++] = char.ToLowerInvariant(current);
}
else
Expand Down
2 changes: 2 additions & 0 deletions tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ public void ToSnakeCase()
Assert.Equal("microsoft_graph_message_content", "microsoft_Graph_Message_Content".ToSnakeCase());
Assert.Equal("test_value", "testValue<WithStrippedContent".ToSnakeCase());
Assert.Equal("test", "test<Value".ToSnakeCase());
Assert.Equal("microsoft_website_url", "microsoftWebsiteURL".ToSnakeCase());
Assert.Equal("microsoft_website_url", "MICROSOFT_WEBSITE_URL".ToSnakeCase());
}
[Fact]
public void NormalizeNameSpaceName()
Expand Down

0 comments on commit 5d099ad

Please sign in to comment.