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