Integrate ApiVersioning library for ASP.NET

This commit is contained in:
Ske 2020-05-07 04:39:49 +02:00
parent db1ebd0a1d
commit c4c3eaf954
6 changed files with 16 additions and 5 deletions

View File

@ -9,8 +9,9 @@ using PluralKit.Core;
namespace PluralKit.API namespace PluralKit.API
{ {
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("a")] [Route("a")]
[Route("v1/a")] [Route( "v{version:apiVersion}/a" )]
public class AccountController: ControllerBase public class AccountController: ControllerBase
{ {
private IDataStore _data; private IDataStore _data;

View File

@ -9,8 +9,9 @@ using PluralKit.Core;
namespace PluralKit.API namespace PluralKit.API
{ {
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("m")] [Route("m")]
[Route("v1/m")] [Route( "v{version:apiVersion}/m" )]
public class MemberController: ControllerBase public class MemberController: ControllerBase
{ {
private IDataStore _data; private IDataStore _data;

View File

@ -24,8 +24,9 @@ namespace PluralKit.API
} }
[ApiController] [ApiController]
[Route("v1/msg")] [ApiVersion("1.0")]
[Route("msg")] [Route("msg")]
[Route( "v{version:apiVersion}/msg" )]
public class MessageController: ControllerBase public class MessageController: ControllerBase
{ {
private IDataStore _data; private IDataStore _data;

View File

@ -34,8 +34,9 @@ namespace PluralKit.API
} }
[ApiController] [ApiController]
[ApiVersion("1.0")]
[Route("s")] [Route("s")]
[Route("v1/s")] [Route( "v{version:apiVersion}/s" )]
public class SystemController : ControllerBase public class SystemController : ControllerBase
{ {
private IDataStore _data; private IDataStore _data;

View File

@ -14,6 +14,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" /> <PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="4.1.1" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -1,4 +1,4 @@
using System; using System;
using Autofac; using Autofac;
@ -29,6 +29,12 @@ namespace PluralKit.API
services.AddControllers() services.AddControllers()
.SetCompatibilityVersion(CompatibilityVersion.Latest) .SetCompatibilityVersion(CompatibilityVersion.Latest)
.AddNewtonsoftJson(); // sorry MS, this just does *more* .AddNewtonsoftJson(); // sorry MS, this just does *more*
services.AddApiVersioning(c =>
{
c.AssumeDefaultVersionWhenUnspecified = true;
c.DefaultApiVersion = ApiVersion.Parse("1.0");
});
} }
public void ConfigureContainer(ContainerBuilder builder) public void ConfigureContainer(ContainerBuilder builder)