From e3975785ba21aa3e0129603e48d9ac10800d76ea Mon Sep 17 00:00:00 2001 From: Adam Stachowicz Date: Tue, 26 Nov 2024 18:58:15 +0100 Subject: [PATCH] DisplayName for ASP.NET --- .../WebApiOpenApiDocumentGenerator.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs index d74c5080d..99eacf606 100644 --- a/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs +++ b/src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs @@ -222,7 +222,12 @@ private bool AddOperationDescriptionsToDocument(OpenApiDocument document, Type c if (pathItem.ContainsKey(operation.Method)) { - throw new InvalidOperationException($"The method '{operation.Method}' on path '{path}' is registered multiple times " + + var conflictingOperationDisplayNames = operations + .Where(t => t.Item1.Path == operation.Path && t.Item1.Method == operation.Method) + .Select(t => GetDisplayName(controllerType, t.Item2)) + .ToList(); + + throw new InvalidOperationException($"The method '{operation.Method}' on path '{path}' is registered multiple times for action {string.Join(", ", conflictingOperationDisplayNames)} " + "(check the DefaultUrlTemplate setting [default for Web API: 'api/{controller}/{id}'; for MVC projects: '{controller}/{action}/{id?}'])."); } @@ -234,6 +239,11 @@ private bool AddOperationDescriptionsToDocument(OpenApiDocument document, Type c return addedOperations > 0; } + private static string GetDisplayName(Type controllerType, MethodInfo method) + { + return $"{controllerType.FullName}.{method.Name} ({controllerType.Assembly.GetName().Name})"; + } + private bool RunOperationProcessors(OpenApiDocument document, Type controllerType, MethodInfo methodInfo, OpenApiOperationDescription operationDescription, List allOperations, OpenApiDocumentGenerator generator, OpenApiSchemaResolver schemaResolver) {