From e784eb015d754e1d0aa74d8fc2b380cdc4907377 Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 26 Nov 2024 16:09:51 +0100 Subject: [PATCH] Display all conflicting actions --- .../AspNetCoreOpenApiDocumentGenerator.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs b/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs index ceb74a7f7..832480c15 100644 --- a/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs +++ b/src/NSwag.Generation.AspNetCore/AspNetCoreOpenApiDocumentGenerator.cs @@ -336,11 +336,12 @@ private List> Add if (pathItem.ContainsKey(operation.Method)) { - var conflictingApiDescription = addedOperations - .First(t => t.Item1.Path == operation.Path && t.Item1.Method == operation.Method) - .Item2; + var conflictingApiDescriptions = operations + .Where(t => t.Item1.Path == operation.Path && t.Item1.Method == operation.Method) + .Select(t => t.Item2) + .ToList(); - throw new InvalidOperationException($"The method '{operation.Method}' on path '{path}' is registered multiple times for actions {conflictingApiDescription.ActionDescriptor.DisplayName} and {apiDescription.ActionDescriptor.DisplayName}."); + throw new InvalidOperationException($"The method '{operation.Method}' on path '{path}' is registered multiple times for actions {string.Join(", ", conflictingApiDescriptions.Select(apiDesc => apiDesc.ActionDescriptor.DisplayName))}."); } pathItem[operation.Method] = operation.Operation;