/AgileTea.Swagger.ApiVersioning

Offers self discovery of api versions within an aspnet core 3.0+ project and automatic set up of Swagger UI Generation

Primary LanguageC#

drawing AgileTea.Swagger.ApiVersioning

Build Status NuGet Version NuGet Preview Version

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

Installation

AgileTea.AspNetCore.Swagger.ApiVersioning installs through NuGet and requires .NET Core 3.1

PS> Install-Package AgileTea.AspNetCore.Swagger.ApiVersioning

Configuration (in Startup.cs)

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);

    // ...
}

Self Discovery

Decorate your controllers with your api version in whichever approach you prefer:

Header/ Query Parameter versioning:

[ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")]
public class SomeClassController : ControllerBase
{
  // etc
}

Url Segment versioning:

[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.

Swagger UI

Browser to your local swagger end point to view results (i.e. https://localhost:5001/swagger)