diff options
| author | Claus Vium <clausvium@gmail.com> | 2019-07-02 20:17:00 +0200 |
|---|---|---|
| committer | Claus Vium <clausvium@gmail.com> | 2019-11-19 22:51:02 +0100 |
| commit | 05b7e2280843f25e48c2300b135f171aee0a54ea (patch) | |
| tree | cc1743b252b7728ee39dbd3a824bec6c43394a6a /Emby.Server.Implementations | |
| parent | c011fa2ea80a5f7f994649e6257bccf572f299e1 (diff) | |
Add SwaggerUI
Diffstat (limited to 'Emby.Server.Implementations')
| -rw-r--r-- | Emby.Server.Implementations/ApplicationHost.cs | 27 | ||||
| -rw-r--r-- | Emby.Server.Implementations/Emby.Server.Implementations.csproj | 4 |
2 files changed, 30 insertions, 1 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> |
