Add SwaggerUI

This commit is contained in:
Claus Vium 2019-07-02 20:17:00 +02:00
parent c011fa2ea8
commit 05b7e22808
3 changed files with 32 additions and 4 deletions

View File

@ -113,7 +113,9 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Models;
using ServiceStack; using ServiceStack;
using Swashbuckle.AspNetCore.SwaggerGen;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem; using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations namespace Emby.Server.Implementations
@ -663,11 +665,36 @@ namespace Emby.Server.Implementations
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2) .SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddApplicationPart(Assembly.Load("Jellyfin.Api")); .AddApplicationPart(Assembly.Load("Jellyfin.Api"));
services.AddApiVersioning(opt => opt.ReportApiVersions = true); services.AddApiVersioning(opt => opt.ReportApiVersions = true);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Jellyfin API", Version = "v1" });
c.DocInclusionPredicate((docName, apiDesc) =>
{
if (!apiDesc.TryGetMethodInfo(out var methodInfo))
{
return false;
}
// A bit of a hack to make Swagger pick the versioned endpoints instead of the legacy emby endpoints
return methodInfo.DeclaringType?.BaseType == typeof(ControllerBase) &&
apiDesc.RelativePath.Contains("api/v");
});
});
// Merge the external ServiceCollection into ASP.NET DI // Merge the external ServiceCollection into ASP.NET DI
services.TryAdd(serviceCollection); services.TryAdd(serviceCollection);
}) })
.Configure(app => .Configure(app =>
{ {
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Jellyfin API V1");
});
app.UseWebSockets(); app.UseWebSockets();
app.UseResponseCompression(); app.UseResponseCompression();

View File

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" /> <ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
@ -21,6 +21,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="IPNetwork2" Version="2.4.0.126" /> <PackageReference Include="IPNetwork2" Version="2.4.0.126" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" /> <PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.2.7" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" /> <PackageReference Include="Microsoft.AspNetCore.Hosting.Server.Abstractions" Version="2.2.0" />
@ -37,6 +38,7 @@
<PackageReference Include="ServiceStack.Text.Core" Version="5.6.0" /> <PackageReference Include="ServiceStack.Text.Core" Version="5.6.0" />
<PackageReference Include="sharpcompress" Version="0.24.0" /> <PackageReference Include="sharpcompress" Version="0.24.0" />
<PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.0.1" /> <PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers namespace Jellyfin.Api.Controllers
{ {
[ApiVersion("1")] [ApiVersion("1")]
[Route("[controller]")]
public class StartupController : ControllerBase public class StartupController : ControllerBase
{ {
private readonly IServerConfigurationManager _config; private readonly IServerConfigurationManager _config;
@ -21,7 +20,7 @@ namespace Jellyfin.Api.Controllers
} }
[HttpPost("Complete")] [HttpPost("Complete")]
public void Post() public void CompleteWizard()
{ {
_config.Configuration.IsStartupWizardCompleted = true; _config.Configuration.IsStartupWizardCompleted = true;
_config.SetOptimalValues(); _config.SetOptimalValues();
@ -71,7 +70,7 @@ namespace Jellyfin.Api.Controllers
} }
[HttpPost("User")] [HttpPost("User")]
public async Task Post([FromForm] StartupUser startupUser) public async Task UpdateUser([FromForm] StartupUser startupUser)
{ {
var user = _userManager.Users.First(); var user = _userManager.Users.First();