Skip to content

Commit 49042d1

Browse files
Set DisplayName on ActionDescriptor (#34063)
Copy the DisplayName from the route endpoint to the ActionDescriptor. Addresses #34062.
1 parent 932c553 commit 49042d1

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ private ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint, string
9191
RelativePath = routeEndpoint.RoutePattern.RawText?.TrimStart('/'),
9292
ActionDescriptor = new ActionDescriptor
9393
{
94+
DisplayName = routeEndpoint.DisplayName,
9495
RouteValues =
9596
{
9697
["controller"] = controllerName,

src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,19 @@ public void AddsMultipleParameters()
302302
Assert.Equal(BindingSource.Body, fromBodyParam.Source);
303303
}
304304

305+
[Fact]
306+
public void AddsDisplayNameFromRouteEndpoint()
307+
{
308+
var apiDescription = GetApiDescription(() => "foo", displayName: "FOO");
309+
310+
Assert.Equal("FOO", apiDescription.ActionDescriptor.DisplayName);
311+
}
312+
305313
private IList<ApiDescription> GetApiDescriptions(
306314
Delegate action,
307315
string pattern = null,
308-
IEnumerable<string> httpMethods = null)
316+
IEnumerable<string> httpMethods = null,
317+
string displayName = null)
309318
{
310319
var methodInfo = action.Method;
311320
var attributes = methodInfo.GetCustomAttributes();
@@ -316,7 +325,7 @@ private IList<ApiDescription> GetApiDescriptions(
316325
var endpointMetadata = new EndpointMetadataCollection(metadataItems.ToArray());
317326
var routePattern = RoutePatternFactory.Parse(pattern ?? "/");
318327

319-
var endpoint = new RouteEndpoint(httpContext => Task.CompletedTask, routePattern, 0, endpointMetadata, null);
328+
var endpoint = new RouteEndpoint(httpContext => Task.CompletedTask, routePattern, 0, endpointMetadata, displayName);
320329
var endpointDataSource = new DefaultEndpointDataSource(endpoint);
321330
var hostEnvironment = new HostEnvironment
322331
{
@@ -331,8 +340,8 @@ private IList<ApiDescription> GetApiDescriptions(
331340
return context.Results;
332341
}
333342

334-
private ApiDescription GetApiDescription(Delegate action, string pattern = null) =>
335-
Assert.Single(GetApiDescriptions(action, pattern));
343+
private ApiDescription GetApiDescription(Delegate action, string pattern = null, string displayName = null) =>
344+
Assert.Single(GetApiDescriptions(action, pattern, displayName: displayName));
336345

337346
private static void TestAction()
338347
{

0 commit comments

Comments
 (0)