Skip to content

Commit 2af293d

Browse files
authored
Added endpoint API explorer to default webhost (#33800)
* Added endpoint API explorer to default webhost - This will allow discovery of API explorer metadata without an explicit call. - Added API explorer tests
1 parent e47ce67 commit 2af293d

File tree

5 files changed

+30
-1
lines changed

5 files changed

+30
-1
lines changed

src/DefaultBuilder/DefaultBuilder.slnf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,14 @@
1717
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
1818
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj",
1919
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
20+
"src\\Middleware\\ResponseCaching.Abstractions\\src\\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj",
2021
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
21-
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj"
22+
"src\\Mvc\\Mvc.Abstractions\\src\\Microsoft.AspNetCore.Mvc.Abstractions.csproj",
23+
"src\\Mvc\\Mvc.ApiExplorer\\src\\Microsoft.AspNetCore.Mvc.ApiExplorer.csproj",
24+
"src\\Mvc\\Mvc.Core\\src\\Microsoft.AspNetCore.Mvc.Core.csproj",
25+
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
26+
"src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj",
27+
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj"
2228
]
2329
}
2430
}

src/DefaultBuilder/src/Microsoft.AspNetCore.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
1919
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
2020
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
21+
<Reference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" />
2122
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
2223
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions" />
2324
<Reference Include="Microsoft.Extensions.Configuration.Json" />

src/DefaultBuilder/src/WebHost.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
259259
}
260260

261261
services.AddRouting();
262+
services.AddEndpointsApiExplorer();
262263
})
263264
.UseIIS()
264265
.UseIISIntegration();

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebApplicationTests.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using Microsoft.AspNetCore.Hosting.Server;
1616
using Microsoft.AspNetCore.Hosting.Server.Features;
1717
using Microsoft.AspNetCore.Http.Features;
18+
using Microsoft.AspNetCore.Mvc.ApiExplorer;
1819
using Microsoft.AspNetCore.Routing;
1920
using Microsoft.AspNetCore.TestHost;
2021
using Microsoft.AspNetCore.Testing;
@@ -269,6 +270,14 @@ public void WebApplicationCreate_RegistersRouting()
269270
Assert.NotNull(linkGenerator);
270271
}
271272

273+
[Fact]
274+
public void WebApplicationCreate_RegistersApiExplorerForEndpoints()
275+
{
276+
var app = WebApplication.Create();
277+
var apiDescriptionProvider = app.Services.GetService(typeof(IApiDescriptionProvider));
278+
Assert.NotNull(apiDescriptionProvider);
279+
}
280+
272281
[Fact]
273282
public void WebApplicationCreate_RegistersEventSourceLogger()
274283
{

src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
using Microsoft.AspNetCore.Builder;
1212
using Microsoft.AspNetCore.HostFiltering;
1313
using Microsoft.AspNetCore.Hosting;
14+
using Microsoft.AspNetCore.Mvc.ApiExplorer;
1415
using Microsoft.AspNetCore.Routing;
1516
using Microsoft.AspNetCore.TestHost;
1617
using Microsoft.AspNetCore.Testing;
@@ -99,6 +100,17 @@ public void CreateDefaultBuilder_RegistersRouting()
99100
Assert.NotNull(linkGenerator);
100101
}
101102

103+
[Fact]
104+
public void CreateDefaultBuilder_RegistersApiExplorer()
105+
{
106+
var host = WebHost.CreateDefaultBuilder()
107+
.Configure(_ => { })
108+
.Build();
109+
110+
var apiDescriptionProvider = host.Services.GetService(typeof(IApiDescriptionProvider));
111+
Assert.NotNull(apiDescriptionProvider);
112+
}
113+
102114
[Fact]
103115
public void CreateDefaultBuilder_RegistersEventSourceLogger()
104116
{

0 commit comments

Comments
 (0)