From 561425b338f03a41876bdb084534bb1135b34038 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Fri, 19 Apr 2024 15:06:14 +0300 Subject: [PATCH 1/5] Fix conflicting types --- .../Extensions/OpenApiUrlTreeNodeExtensions.cs | 8 +++++--- src/Kiota.Builder/KiotaBuilder.cs | 2 +- .../OpenApiUrlTreeNodeExtensionsTests.cs | 14 ++++++++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs index ba925d728b..c90136b87f 100644 --- a/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs @@ -40,7 +40,7 @@ public static string GetNodeNamespaceFromPath(this OpenApiUrlTreeNode currentNod return currentNode.Path.GetNamespaceFromPath(prefix); } //{id}, name(idParam={id}), name(idParam='{id}'), name(idParam='{id}',idParam2='{id2}') - [GeneratedRegex(@"(?:\w+)?=?'?\{(?\w+)\}'?,?", RegexOptions.Singleline, 500)] + [GeneratedRegex(@"(?\w+)?(?=?)'?\{(?\w+)\}'?,?", RegexOptions.Singleline, 500)] private static partial Regex PathParametersRegex(); // microsoft.graph.getRoleScopeTagsByIds(ids=@ids) [GeneratedRegex(@"=@(\w+)", RegexOptions.Singleline, 500)] @@ -51,8 +51,10 @@ public static string GetNodeNamespaceFromPath(this OpenApiUrlTreeNode currentNod private const string RequestParametersSectionEndChar = ")"; private const string WithKeyword = "With"; private static readonly MatchEvaluator requestParametersMatchEvaluator = match => - WithKeyword + match.Groups["paramName"].Value.ToFirstCharacterUpperCase(); - private static string CleanupParametersFromPath(string pathSegment) + string.IsNullOrEmpty(match.Groups["equals"].Value) ? + match.Groups["prefix"].Value + WithKeyword + match.Groups["paramName"].Value.ToFirstCharacterUpperCase() : + WithKeyword + match.Groups["paramName"].Value.ToFirstCharacterUpperCase(); + internal static string CleanupParametersFromPath(string pathSegment) { if (string.IsNullOrEmpty(pathSegment)) return pathSegment; diff --git a/src/Kiota.Builder/KiotaBuilder.cs b/src/Kiota.Builder/KiotaBuilder.cs index 1f8499d3d6..e272c5aa62 100644 --- a/src/Kiota.Builder/KiotaBuilder.cs +++ b/src/Kiota.Builder/KiotaBuilder.cs @@ -675,7 +675,7 @@ private static void AddPathParametersToMethod(OpenApiUrlTreeNode currentNode, Co Optional = asOptional, Documentation = new() { - DescriptionTemplate = parameter.Description.CleanupDescription(), + DescriptionTemplate = !string.IsNullOrEmpty(parameter.Description) ? parameter.Description.CleanupDescription() : $"The path parameter: {codeName}", }, Kind = CodeParameterKind.Path, SerializationName = parameter.Name.Equals(codeName, StringComparison.OrdinalIgnoreCase) ? string.Empty : parameter.Name.SanitizeParameterNameForUrlTemplate(), diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs index dba74a113f..c7929767cd 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs @@ -1072,6 +1072,20 @@ public void repro4085() Assert.Equal("\\path\\{differentThingId-id}", differentThingId.Path); Assert.Equal("{+baseurl}/path/{differentThingId%2Did}", differentThingId.GetUrlTemplate()); } + + [Theory] + [InlineData("{path}", "WithPath")] + [InlineData("archived{path}","archivedWithPath")] + [InlineData("files{path}","filesWithPath")] + [InlineData("name(idParam='{id}')","nameWithId")] + [InlineData("name(idParam={id})","nameWithId")] + [InlineData("name(idParam='{id}',idParam2='{id2}')","nameWithIdWithId2")] + public void CleanupParametersFromPathGeneratesDifferentResultsWithPrefixPresent(string segmentName, string expectedIdentifer) + { + var result = OpenApiUrlTreeNodeExtensions.CleanupParametersFromPath(segmentName); + Assert.Equal(expectedIdentifer, result ); + } + private static OpenApiUrlTreeNode GetChildNodeByPath(OpenApiUrlTreeNode node, string path) { var pathSegments = path.Split('/'); From 54208a1002760792325715db78b0db2ff70c796f Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Fri, 19 Apr 2024 15:09:54 +0300 Subject: [PATCH 2/5] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bbc3658e93..3c4e9cfa55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Changed URI template generation to reuse templates when required templates are absent across operations. - Updated reserved name providers for Java and Php so that "object" can be escaped. - Do not generate CS8603 warnings when enabling backing store in CSharp generation. +- Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448) ## [1.13.0] - 2024-04-04 From 9f95d287ea79dc608aedfca010b165c783ea050c Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Fri, 19 Apr 2024 15:11:11 +0300 Subject: [PATCH 3/5] format --- .../Extensions/OpenApiUrlTreeNodeExtensionsTests.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs index c7929767cd..6e36e0f2a3 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs @@ -1075,15 +1075,15 @@ public void repro4085() [Theory] [InlineData("{path}", "WithPath")] - [InlineData("archived{path}","archivedWithPath")] - [InlineData("files{path}","filesWithPath")] - [InlineData("name(idParam='{id}')","nameWithId")] - [InlineData("name(idParam={id})","nameWithId")] - [InlineData("name(idParam='{id}',idParam2='{id2}')","nameWithIdWithId2")] + [InlineData("archived{path}", "archivedWithPath")] + [InlineData("files{path}", "filesWithPath")] + [InlineData("name(idParam='{id}')", "nameWithId")] + [InlineData("name(idParam={id})", "nameWithId")] + [InlineData("name(idParam='{id}',idParam2='{id2}')", "nameWithIdWithId2")] public void CleanupParametersFromPathGeneratesDifferentResultsWithPrefixPresent(string segmentName, string expectedIdentifer) { var result = OpenApiUrlTreeNodeExtensions.CleanupParametersFromPath(segmentName); - Assert.Equal(expectedIdentifer, result ); + Assert.Equal(expectedIdentifer, result); } private static OpenApiUrlTreeNode GetChildNodeByPath(OpenApiUrlTreeNode node, string path) From a9a4c89a9ff109478d2f42b9ad552ca59f9cbd31 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Fri, 19 Apr 2024 13:02:05 -0400 Subject: [PATCH 4/5] - merge fix --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c61c5efaac..c717546586 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Fixed a bug where TypeScript deserialization would fail on Uppercase properties.[#4479](https://github.com/microsoft/kiota/issues/4479) - Changed URI template generation to reuse templates when required templates are absent across operations. -- Updated reserved name providers for Java and Php so that "object" can be escaped. -- Do not generate CS8603 warnings when enabling backing store in CSharp generation. +- Updated reserved name providers for Java and Php so that "object" can be escaped. - Fixes request builder disambiguation when child nodes had different prefixes for different paths with same parameters.[#4448](https://github.com/microsoft/kiota/issues/4448) - Do not generate CS8603 warnings when enabling backing store in CSharp generation. From 5bea316db47714ed54d52671f7ab0ed07daea7ac Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Mon, 22 Apr 2024 17:47:52 +0300 Subject: [PATCH 5/5] Adds comment --- .../Extensions/OpenApiUrlTreeNodeExtensionsTests.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs index 6e36e0f2a3..99fa6e6662 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs @@ -1079,6 +1079,9 @@ public void repro4085() [InlineData("files{path}", "filesWithPath")] [InlineData("name(idParam='{id}')", "nameWithId")] [InlineData("name(idParam={id})", "nameWithId")] + [InlineData("name(idParamFoo={id})", "nameWithId")] // The current implementation only uses the placeholder i.e {id} for the naming to ignore `idParamFoo` + // and thus generates the same identifier as the previous case. This collision risk is unlikely and constrained to an odata service scenario + // which would be invalid for functions scenario(overloads with the same parameters)) [InlineData("name(idParam='{id}',idParam2='{id2}')", "nameWithIdWithId2")] public void CleanupParametersFromPathGeneratesDifferentResultsWithPrefixPresent(string segmentName, string expectedIdentifer) {