Skip to content

Commit 96cad35

Browse files
committed
refactor(document): replace Concat with dedicated GetAllOperations iterator
1 parent 3d009ae commit 96cad35

1 file changed

Lines changed: 22 additions & 13 deletions

File tree

src/Microsoft.OpenApi/Models/OpenApiDocument.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -867,23 +867,32 @@ static bool AddToDictionary<TValue>(IDictionary<string, TValue> dict, string key
867867
{
868868
Utils.CheckArgumentNullOrEmpty(operationId);
869869

870-
var allPathItems = Webhooks is not null
871-
? Paths.Values.Concat(Webhooks.Values)
872-
: Paths.Values;
873-
874-
foreach (var pathItem in allPathItems)
870+
foreach (var operation in GetAllOperations())
875871
{
876-
if (pathItem.Operations is not null)
877-
{
878-
foreach (var operation in pathItem.Operations.Values)
879-
{
880-
if (string.Equals(operation.OperationId, operationId, StringComparison.Ordinal))
881-
return operation;
882-
}
883-
}
872+
if (string.Equals(operation.OperationId, operationId, StringComparison.Ordinal))
873+
return operation;
884874
}
885875
return null;
886876
}
877+
878+
private IEnumerable<OpenApiOperation> GetAllOperations()
879+
{
880+
foreach (var pathItem in Paths.Values)
881+
{
882+
if (pathItem.Operations is null) continue;
883+
foreach (var operation in pathItem.Operations.Values)
884+
yield return operation;
885+
}
886+
887+
if (Webhooks is null) yield break;
888+
889+
foreach (var pathItem in Webhooks.Values)
890+
{
891+
if (pathItem.Operations is null) continue;
892+
foreach (var operation in pathItem.Operations.Values)
893+
yield return operation;
894+
}
895+
}
887896
}
888897

889898
internal class FindSchemaReferences : OpenApiVisitorBase

0 commit comments

Comments
 (0)