diff --git a/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs b/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs index b646cdcca1b0..0ab8f7e113f6 100644 --- a/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs +++ b/src/Mvc/Mvc.ApiExplorer/src/EndpointMetadataApiDescriptionProvider.cs @@ -91,6 +91,7 @@ private ApiDescription CreateApiDescription(RouteEndpoint routeEndpoint, string RelativePath = routeEndpoint.RoutePattern.RawText?.TrimStart('/'), ActionDescriptor = new ActionDescriptor { + DisplayName = routeEndpoint.DisplayName, RouteValues = { ["controller"] = controllerName, diff --git a/src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs b/src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs index 093543d8b93f..231c2f3b20cd 100644 --- a/src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs +++ b/src/Mvc/Mvc.ApiExplorer/test/EndpointMetadataApiDescriptionProviderTest.cs @@ -302,10 +302,19 @@ public void AddsMultipleParameters() Assert.Equal(BindingSource.Body, fromBodyParam.Source); } + [Fact] + public void AddsDisplayNameFromRouteEndpoint() + { + var apiDescription = GetApiDescription(() => "foo", displayName: "FOO"); + + Assert.Equal("FOO", apiDescription.ActionDescriptor.DisplayName); + } + private IList GetApiDescriptions( Delegate action, string pattern = null, - IEnumerable httpMethods = null) + IEnumerable httpMethods = null, + string displayName = null) { var methodInfo = action.Method; var attributes = methodInfo.GetCustomAttributes(); @@ -316,7 +325,7 @@ private IList GetApiDescriptions( var endpointMetadata = new EndpointMetadataCollection(metadataItems.ToArray()); var routePattern = RoutePatternFactory.Parse(pattern ?? "/"); - var endpoint = new RouteEndpoint(httpContext => Task.CompletedTask, routePattern, 0, endpointMetadata, null); + var endpoint = new RouteEndpoint(httpContext => Task.CompletedTask, routePattern, 0, endpointMetadata, displayName); var endpointDataSource = new DefaultEndpointDataSource(endpoint); var hostEnvironment = new HostEnvironment { @@ -331,8 +340,8 @@ private IList GetApiDescriptions( return context.Results; } - private ApiDescription GetApiDescription(Delegate action, string pattern = null) => - Assert.Single(GetApiDescriptions(action, pattern)); + private ApiDescription GetApiDescription(Delegate action, string pattern = null, string displayName = null) => + Assert.Single(GetApiDescriptions(action, pattern, displayName: displayName)); private static void TestAction() {