Skip to content

Commit

Permalink
DisplayName for ASP.NET
Browse files Browse the repository at this point in the history
  • Loading branch information
Saibamen committed Nov 26, 2024
1 parent 40c96f8 commit e397578
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/NSwag.Generation.WebApi/WebApiOpenApiDocumentGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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?}']).");
}

Expand All @@ -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<OpenApiOperationDescription> allOperations, OpenApiDocumentGenerator generator, OpenApiSchemaResolver schemaResolver)
{
Expand Down

0 comments on commit e397578

Please sign in to comment.