Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ToSnakeCase so it wouldn't return "image_u_r_l" for "imageURL" #4608

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed handling of nested arrays to be handled as `UntypedNode` instances [#4549](https://github.com/microsoft/kiota/issues/4549)
- Fixed `InvalidOperationException` thrown when serializing IBacked models with no changes present in the additional data in dotnet [microsoftgraph/msgraph-sdk-dotnet#2471](https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/2471).
- Fixed `RequestConfiguration` Classes dropped in RequestBuilder methods in python [#4535](https://github.com/microsoft/kiota/issues/4535)
- Updated conversion to snake case to deal with strigns with multiple uppercase letters in a row for example "imageURL" will be converted to "image_url" and not "image_u_r_l"
- Fixed incorrect optional types in method parameters in Python [#4507](https://github.com/microsoft/kiota/issues/4507)

## [1.14.0] - 2024-05-02
Expand Down
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
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
Loading