Combines Api Versioning with Api Versioning Discovery and Swagger Generation to provide a self-discovering api versioning configuration fronted with a Swashbuckle Swagger UI Frontend
AgileTea.AspNetCore.Swagger.ApiVersioning installs through NuGet and requires .NET Core 3.1
PS> Install-Package AgileTea.AspNetCore.Swagger.ApiVersioning
public void ConfigureServices(IServiceCollection services)
{
// service configuration etc.
// ...
services.AddSwaggerGenDiscovery(
options =>
{
options.ApplicationTitle = "Agile Tea Learning Web Api";
options.ApiVersionReaderType = ApiVersionReaderType.UrlSegment;
});
// ...
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider provider)
{
// other code removed from brevity
app.UseSwaggerWithSelfDiscovery(provider);
// ...
}
Decorate your controllers with your api version in whichever approach you prefer:
[ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")]
public class SomeClassController : ControllerBase
{
// etc
}
[ApiController]
[ApiVersion("1.0")]
[Route("api/v{version:apiVersion}/[controller]")]
public class SomeClassController : ControllerBase
{
// etc
}
Configuration will the pick up the versions and apply to middleware pipelines to enforce api version as well as allow automatic swagger document generations.
Browser to your local swagger end point to view results (i.e. https://localhost:5001/swagger)