1
0
mirror of https://github.com/ncblakely/GiantsTools synced 2024-11-24 15:15:37 +01:00

Add API versioning.

This commit is contained in:
Nick Blakely 2020-10-12 14:42:44 -07:00
parent 0a8271c7df
commit eb4f555606
6 changed files with 11 additions and 0 deletions

View File

@ -5,6 +5,7 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")] [Route("api/[controller]")]
public class CommunityController : ControllerBase public class CommunityController : ControllerBase
{ {

View File

@ -12,6 +12,7 @@
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")] [Route("api/[controller]")]
public class CrashReportsController : ControllerBase public class CrashReportsController : ControllerBase
{ {

View File

@ -13,6 +13,7 @@ using Microsoft.Extensions.Logging;
namespace Giants.Web.Controllers namespace Giants.Web.Controllers
{ {
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")] [Route("api/[controller]")]
public class ServersController : ControllerBase public class ServersController : ControllerBase
{ {

View File

@ -6,6 +6,7 @@ using Microsoft.AspNetCore.Mvc;
namespace Giants.WebApi.Controllers namespace Giants.WebApi.Controllers
{ {
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("api/[controller]")] [Route("api/[controller]")]
public class VersionController : ControllerBase public class VersionController : ControllerBase
{ {

View File

@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AutoMapper" Version="10.0.0" /> <PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" /> <PackageReference Include="Microsoft.ApplicationInsights" Version="2.14.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
<PackageReference Include="NSwag.AspNetCore" Version="13.7.0" /> <PackageReference Include="NSwag.AspNetCore" Version="13.7.0" />
</ItemGroup> </ItemGroup>

View File

@ -2,6 +2,7 @@ using AutoMapper;
using Giants.Services; using Giants.Services;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Infrastructure; using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
@ -23,6 +24,11 @@ namespace Giants.Web
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddControllers(); services.AddControllers();
services.AddApiVersioning(config =>
{
config.DefaultApiVersion = new ApiVersion(1, 0);
config.AssumeDefaultVersionWhenUnspecified = true;
});
services.AddOpenApiDocument(); services.AddOpenApiDocument();