From 561425b338f03a41876bdb084534bb1135b34038 Mon Sep 17 00:00:00 2001 From: Andrew Omondi Date: Fri, 19 Apr 2024 15:06:14 +0300 Subject: [PATCH] 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('/');