diff --git a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs index 9f4ccb8be..a5fb0e836 100644 --- a/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs +++ b/src/Microsoft.OpenApi/Services/OpenApiUrlTreeNode.cs @@ -59,12 +59,7 @@ public bool HasOperations(string label) { Utils.CheckArgumentNullOrEmpty(label, nameof(label)); - if (!(PathItems?.ContainsKey(label) ?? false)) - { - return false; - } - - return PathItems[label].Operations?.Any() ?? false; + return PathItems is not null && PathItems.TryGetValue(label, out var item) && item.Operations is not null && item.Operations.Any(); } /// @@ -190,14 +185,15 @@ private OpenApiUrlTreeNode Attach(IEnumerable segments, } // If the child segment has already been defined, then insert into it - if (Children.ContainsKey(segment)) + if (Children.TryGetValue(segment, out var child)) { var newPath = currentPath + PathSeparator + segment; - return Children[segment].Attach(segments: segments.Skip(1), - pathItem: pathItem, - label: label, - currentPath: newPath); + return child.Attach( + segments: segments.Skip(1), + pathItem: pathItem, + label: label, + currentPath: newPath); } else { @@ -227,14 +223,7 @@ public void AddAdditionalData(Dictionary> additionalData) foreach (var item in additionalData) { - if (AdditionalData.ContainsKey(item.Key)) - { - AdditionalData[item.Key] = item.Value; - } - else - { - AdditionalData.Add(item.Key, item.Value); - } + AdditionalData[item.Key] = item.Value; } }