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
{
[ApiController]
[ApiVersion("1.0")]
[Route("a")]
[Route("v1/a")]
[Route( "v{version:apiVersion}/a" )]
public class AccountController: ControllerBase
{
private IDataStore _data;

View File

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

View File

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

View File

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

View File

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

View File

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