aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaus Vium <clausvium@gmail.com>2019-07-02 20:17:00 +0200
committerClaus Vium <clausvium@gmail.com>2019-11-19 22:51:02 +0100
commit05b7e2280843f25e48c2300b135f171aee0a54ea (patch)
treecc1743b252b7728ee39dbd3a824bec6c43394a6a
parentc011fa2ea80a5f7f994649e6257bccf572f299e1 (diff)
Add SwaggerUI
-rw-r--r--Emby.Server.Implementations/ApplicationHost.cs27
-rw-r--r--Emby.Server.Implementations/Emby.Server.Implementations.csproj4
-rw-r--r--Jellyfin.Api/Controllers/StartupController.cs5
3 files changed, 32 insertions, 4 deletions
diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs
index 11ee6d2d2..3d2d61225 100644
--- a/Emby.Server.Implementations/ApplicationHost.cs
+++ b/Emby.Server.Implementations/ApplicationHost.cs
@@ -113,7 +113,9 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Logging;
+using Microsoft.OpenApi.Models;
using ServiceStack;
+using Swashbuckle.AspNetCore.SwaggerGen;
using OperatingSystem = MediaBrowser.Common.System.OperatingSystem;
namespace Emby.Server.Implementations
@@ -663,11 +665,36 @@ namespace Emby.Server.Implementations
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddApplicationPart(Assembly.Load("Jellyfin.Api"));
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
services.TryAdd(serviceCollection);
})
.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.UseResponseCompression();
diff --git a/Emby.Server.Implementations/Emby.Server.Implementations.csproj b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
index 23e35f77e..26301b379 100644
--- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj
+++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj
@@ -1,4 +1,4 @@
-<Project Sdk="Microsoft.NET.Sdk">
+<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\Emby.Naming\Emby.Naming.csproj" />
@@ -21,6 +21,7 @@
<ItemGroup>
<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.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="sharpcompress" Version="0.24.0" />
<PackageReference Include="SQLitePCL.pretty.netstandard" Version="2.0.1" />
+ <PackageReference Include="Swashbuckle.AspNetCore" Version="5.0.0-rc2" />
</ItemGroup>
<ItemGroup>
diff --git a/Jellyfin.Api/Controllers/StartupController.cs b/Jellyfin.Api/Controllers/StartupController.cs
index c17b534eb..45e4cd5ac 100644
--- a/Jellyfin.Api/Controllers/StartupController.cs
+++ b/Jellyfin.Api/Controllers/StartupController.cs
@@ -8,7 +8,6 @@ using Microsoft.AspNetCore.Mvc;
namespace Jellyfin.Api.Controllers
{
[ApiVersion("1")]
- [Route("[controller]")]
public class StartupController : ControllerBase
{
private readonly IServerConfigurationManager _config;
@@ -21,7 +20,7 @@ namespace Jellyfin.Api.Controllers
}
[HttpPost("Complete")]
- public void Post()
+ public void CompleteWizard()
{
_config.Configuration.IsStartupWizardCompleted = true;
_config.SetOptimalValues();
@@ -71,7 +70,7 @@ namespace Jellyfin.Api.Controllers
}
[HttpPost("User")]
- public async Task Post([FromForm] StartupUser startupUser)
+ public async Task UpdateUser([FromForm] StartupUser startupUser)
{
var user = _userManager.Users.First();