Skip to content

Commit

Permalink
Fix conflicting types
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Apr 19, 2024
1 parent e74b1d0 commit 561425b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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+)?=?'?\{(?<paramName>\w+)\}'?,?", RegexOptions.Singleline, 500)]
[GeneratedRegex(@"(?<prefix>\w+)?(?<equals>=?)'?\{(?<paramName>\w+)\}'?,?", RegexOptions.Singleline, 500)]
private static partial Regex PathParametersRegex();
// microsoft.graph.getRoleScopeTagsByIds(ids=@ids)
[GeneratedRegex(@"=@(\w+)", RegexOptions.Singleline, 500)]
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/KiotaBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('/');
Expand Down

0 comments on commit 561425b

Please sign in to comment.