From 05b7e2280843f25e48c2300b135f171aee0a54ea Mon Sep 17 00:00:00 2001 From: Claus Vium Date: Tue, 2 Jul 2019 20:17:00 +0200 Subject: [PATCH] Add SwaggerUI --- .../ApplicationHost.cs | 27 +++++++++++++++++++ .../Emby.Server.Implementations.csproj | 4 ++- Jellyfin.Api/Controllers/StartupController.cs | 5 ++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Emby.Server.Implementations/ApplicationHost.cs b/Emby.Server.Implementations/ApplicationHost.cs index 11ee6d2d20..3d2d61225e 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 23e35f77e1..26301b379e 100644 --- a/Emby.Server.Implementations/Emby.Server.Implementations.csproj +++ b/Emby.Server.Implementations/Emby.Server.Implementations.csproj @@ -1,4 +1,4 @@ - + @@ -21,6 +21,7 @@ + @@ -37,6 +38,7 @@ + diff --git a/Jellyfin.Api/Controllers/StartupController.cs b/Jellyfin.Api/Controllers/StartupController.cs index c17b534ebf..45e4cd5ac8 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();