2020-04-21 22:15:31 +00:00
|
|
|
using MediaBrowser.Controller.Configuration;
|
2019-11-23 18:43:30 +00:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
|
2019-11-24 14:27:58 +00:00
|
|
|
namespace Jellyfin.Server.Extensions
|
2019-11-23 18:43:30 +00:00
|
|
|
{
|
2019-11-23 19:31:17 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Extensions for adding API specific functionality to the application pipeline.
|
|
|
|
/// </summary>
|
2019-11-23 18:43:30 +00:00
|
|
|
public static class ApiApplicationBuilderExtensions
|
|
|
|
{
|
2019-11-23 19:31:17 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Adds swagger and swagger UI to the application pipeline.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="applicationBuilder">The application builder.</param>
|
2020-04-21 22:15:31 +00:00
|
|
|
/// <param name="serverConfigurationManager">The server configuration.</param>
|
2019-11-23 19:31:17 +00:00
|
|
|
/// <returns>The updated application builder.</returns>
|
2020-04-21 22:15:31 +00:00
|
|
|
public static IApplicationBuilder UseJellyfinApiSwagger(
|
|
|
|
this IApplicationBuilder applicationBuilder,
|
|
|
|
IServerConfigurationManager serverConfigurationManager)
|
2019-11-23 18:43:30 +00:00
|
|
|
{
|
|
|
|
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
|
|
|
|
// specifying the Swagger JSON endpoint.
|
2020-04-21 22:15:31 +00:00
|
|
|
|
|
|
|
var baseUrl = serverConfigurationManager.Configuration.BaseUrl.Trim('/');
|
|
|
|
if (!string.IsNullOrEmpty(baseUrl))
|
|
|
|
{
|
|
|
|
baseUrl += '/';
|
|
|
|
}
|
|
|
|
|
2020-04-19 17:28:56 +00:00
|
|
|
return applicationBuilder
|
2020-04-21 22:15:31 +00:00
|
|
|
.UseSwagger(c =>
|
|
|
|
{
|
|
|
|
c.RouteTemplate = $"/{baseUrl}api-docs/{{documentName}}/openapi.json";
|
|
|
|
})
|
2020-04-19 16:51:51 +00:00
|
|
|
.UseSwaggerUI(c =>
|
|
|
|
{
|
2020-04-21 22:19:26 +00:00
|
|
|
c.DocumentTitle = "Jellyfin API v1";
|
2020-04-21 22:15:31 +00:00
|
|
|
c.SwaggerEndpoint($"/{baseUrl}api-docs/v1/openapi.json", "Jellyfin API v1");
|
|
|
|
c.RoutePrefix = $"{baseUrl}api-docs/v1/swagger";
|
2020-04-19 16:51:51 +00:00
|
|
|
})
|
|
|
|
.UseReDoc(c =>
|
|
|
|
{
|
2020-04-21 22:15:31 +00:00
|
|
|
c.DocumentTitle = "Jellyfin API v1";
|
|
|
|
c.SpecUrl($"/{baseUrl}api-docs/v1/openapi.json");
|
|
|
|
c.RoutePrefix = $"{baseUrl}api-docs/v1/redoc";
|
2020-04-19 16:51:51 +00:00
|
|
|
});
|
2019-11-23 18:43:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|