diff --git a/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs index 046dd3dfc4..ba925d728b 100644 --- a/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs +++ b/src/Kiota.Builder/Extensions/OpenApiUrlTreeNodeExtensions.cs @@ -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); diff --git a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs index 7a0c41f151..dba74a113f 100644 --- a/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs +++ b/tests/Kiota.Builder.Tests/Extensions/OpenApiUrlTreeNodeExtensionsTests.cs @@ -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)); @@ -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));