Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Apr 8, 2024
1 parent ba38af6 commit 3ce3813
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ public static bool IsComplexPathMultipleParameters(this OpenApiUrlTreeNode curre
public static bool HasRequiredQueryParametersAcrossOperations(this OpenApiUrlTreeNode currentNode)
{
ArgumentNullException.ThrowIfNull(currentNode);
var pathItem = currentNode.PathItems[Constants.DefaultOpenApiLabel];
if (!currentNode.PathItems.TryGetValue(Constants.DefaultOpenApiLabel, out var pathItem))
return false;

var operationQueryParameters = pathItem.Operations.SelectMany(static x => x.Value.Parameters);
return operationQueryParameters.Union(pathItem.Parameters).Where(static x => x.In == ParameterLocation.Query)
.Any(static x => x.Required);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ public void DifferentUrlTemplatesPerOperation()
});
var node = OpenApiUrlTreeNode.Create(doc, Label);
Assert.False(node.HasRequiredQueryParametersAcrossOperations());
Assert.False(node.Children.First().Value.HasRequiredQueryParametersAcrossOperations());
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment{?%24select}", node.Children.First().Value.GetUrlTemplate());
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment{?%24select}", node.Children.First().Value.GetUrlTemplate(OperationType.Get));
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment", node.Children.First().Value.GetUrlTemplate(OperationType.Put));
Expand Down Expand Up @@ -310,7 +311,8 @@ public void DifferentUrlTemplatesPerOperationWithRequiredParameter()
}
});
var node = OpenApiUrlTreeNode.Create(doc, Label);
Assert.True(node.HasRequiredQueryParametersAcrossOperations());
Assert.False(node.HasRequiredQueryParametersAcrossOperations());
Assert.True(node.Children.First().Value.HasRequiredQueryParametersAcrossOperations());
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment?id={id}{&%24expand,%24select}", node.Children.First().Value.GetUrlTemplate());//the default contains a combination of everything.
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment{?%24select}", node.Children.First().Value.GetUrlTemplate(OperationType.Get));
Assert.Equal("{+baseurl}/{param%2Dwith%2Ddashes}/existing-segment{?%24expand}", node.Children.First().Value.GetUrlTemplate(OperationType.Post));
Expand Down

0 comments on commit 3ce3813

Please sign in to comment.