From 5d099ada5d9489b43731e7e60e3c29b601f4fef4 Mon Sep 17 00:00:00 2001 From: Yehoyada Date: Mon, 6 May 2024 18:36:55 +0300 Subject: [PATCH 1/4] Update toSnakeCase to convert this input "imageURL" into "image_url" and not "image_u_r_l" --- src/Kiota.Builder/Extensions/StringExtensions.cs | 7 +++++-- .../Extensions/StringExtensionsTests.cs | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Kiota.Builder/Extensions/StringExtensions.cs b/src/Kiota.Builder/Extensions/StringExtensions.cs index d220b073f1..ab6a8a247c 100644 --- a/src/Kiota.Builder/Extensions/StringExtensions.cs +++ b/src/Kiota.Builder/Extensions/StringExtensions.cs @@ -82,7 +82,7 @@ static int CountNecessaryNewSeparators(ReadOnlySpan 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++; } @@ -105,7 +105,10 @@ static int CountNecessaryNewSeparators(ReadOnlySpan 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 diff --git a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs index 6e9fce63a3..917e8db88e 100644 --- a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs @@ -75,6 +75,8 @@ public void ToSnakeCase() Assert.Equal("microsoft_graph_message_content", "microsoft_Graph_Message_Content".ToSnakeCase()); Assert.Equal("test_value", "testValue Date: Mon, 6 May 2024 18:43:53 +0300 Subject: [PATCH 2/4] try without new tests --- tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs index 917e8db88e..c35fe4ce5d 100644 --- a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs @@ -75,8 +75,8 @@ public void ToSnakeCase() Assert.Equal("microsoft_graph_message_content", "microsoft_Graph_Message_Content".ToSnakeCase()); Assert.Equal("test_value", "testValue Date: Mon, 6 May 2024 18:49:44 +0300 Subject: [PATCH 3/4] Add tests back --- tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs index c35fe4ce5d..917e8db88e 100644 --- a/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/StringExtensionsTests.cs @@ -75,8 +75,8 @@ public void ToSnakeCase() Assert.Equal("microsoft_graph_message_content", "microsoft_Graph_Message_Content".ToSnakeCase()); Assert.Equal("test_value", "testValue Date: Mon, 6 May 2024 21:18:57 +0300 Subject: [PATCH 4/4] update --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3386f8429c..dddc751e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed RPC server to respect the `KIOTA_CONFIG_PREVIEW` flag. - 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). +- 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" ## [1.14.0] - 2024-05-02