Skip to content

Commit

Permalink
Added endpoint API explorer to default webhost (#33800)
Browse files Browse the repository at this point in the history
* Added endpoint API explorer to default webhost
- This will allow discovery of API explorer metadata without an explicit call.
- Added API explorer tests
  • Loading branch information
davidfowl authored Jun 25, 2021
1 parent e47ce67 commit 2af293d
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/DefaultBuilder/DefaultBuilder.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@
"src\\Http\\Http.Features\\src\\Microsoft.AspNetCore.Http.Features.csproj",
"src\\Http\\Http\\src\\Microsoft.AspNetCore.Http.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
"src\\Middleware\\ResponseCaching.Abstractions\\src\\Microsoft.AspNetCore.ResponseCaching.Abstractions.csproj",
"src\\Middleware\\StaticFiles\\src\\Microsoft.AspNetCore.StaticFiles.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj"
"src\\Mvc\\Mvc.Abstractions\\src\\Microsoft.AspNetCore.Mvc.Abstractions.csproj",
"src\\Mvc\\Mvc.ApiExplorer\\src\\Microsoft.AspNetCore.Mvc.ApiExplorer.csproj",
"src\\Mvc\\Mvc.Core\\src\\Microsoft.AspNetCore.Mvc.Core.csproj",
"src\\ObjectPool\\src\\Microsoft.Extensions.ObjectPool.csproj",
"src\\Security\\Authentication\\Core\\src\\Microsoft.AspNetCore.Authentication.csproj",
"src\\Security\\Authorization\\Policy\\src\\Microsoft.AspNetCore.Authorization.Policy.csproj"
]
}
}
1 change: 1 addition & 0 deletions src/DefaultBuilder/src/Microsoft.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Reference Include="Microsoft.AspNetCore.Server.IIS" />
<Reference Include="Microsoft.AspNetCore.Server.IISIntegration" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
<Reference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" />
<Reference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" />
<Reference Include="Microsoft.Extensions.Configuration.FileExtensions" />
<Reference Include="Microsoft.Extensions.Configuration.Json" />
Expand Down
1 change: 1 addition & 0 deletions src/DefaultBuilder/src/WebHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ internal static void ConfigureWebDefaults(IWebHostBuilder builder)
}
services.AddRouting();
services.AddEndpointsApiExplorer();
})
.UseIIS()
.UseIISIntegration();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.AspNetCore.Hosting.Server;
using Microsoft.AspNetCore.Hosting.Server.Features;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Testing;
Expand Down Expand Up @@ -269,6 +270,14 @@ public void WebApplicationCreate_RegistersRouting()
Assert.NotNull(linkGenerator);
}

[Fact]
public void WebApplicationCreate_RegistersApiExplorerForEndpoints()
{
var app = WebApplication.Create();
var apiDescriptionProvider = app.Services.GetService(typeof(IApiDescriptionProvider));
Assert.NotNull(apiDescriptionProvider);
}

[Fact]
public void WebApplicationCreate_RegistersEventSourceLogger()
{
Expand Down
12 changes: 12 additions & 0 deletions src/DefaultBuilder/test/Microsoft.AspNetCore.Tests/WebHostTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.HostFiltering;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.TestHost;
using Microsoft.AspNetCore.Testing;
Expand Down Expand Up @@ -99,6 +100,17 @@ public void CreateDefaultBuilder_RegistersRouting()
Assert.NotNull(linkGenerator);
}

[Fact]
public void CreateDefaultBuilder_RegistersApiExplorer()
{
var host = WebHost.CreateDefaultBuilder()
.Configure(_ => { })
.Build();

var apiDescriptionProvider = host.Services.GetService(typeof(IApiDescriptionProvider));
Assert.NotNull(apiDescriptionProvider);
}

[Fact]
public void CreateDefaultBuilder_RegistersEventSourceLogger()
{
Expand Down

0 comments on commit 2af293d

Please sign in to comment.