mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 03:26:07 +02:00
Fix apidoc routes with base url
This commit is contained in:
parent
2d198292a3
commit
0b38ac9a8a
1 changed files with 22 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
|
using System.Collections.Generic;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
namespace Jellyfin.Server.Extensions
|
namespace Jellyfin.Server.Extensions
|
||||||
{
|
{
|
||||||
|
@ -22,6 +24,7 @@ namespace Jellyfin.Server.Extensions
|
||||||
// specifying the Swagger JSON endpoint.
|
// specifying the Swagger JSON endpoint.
|
||||||
|
|
||||||
var baseUrl = serverConfigurationManager.Configuration.BaseUrl.Trim('/');
|
var baseUrl = serverConfigurationManager.Configuration.BaseUrl.Trim('/');
|
||||||
|
var apiDocBaseUrl = serverConfigurationManager.Configuration.BaseUrl;
|
||||||
if (!string.IsNullOrEmpty(baseUrl))
|
if (!string.IsNullOrEmpty(baseUrl))
|
||||||
{
|
{
|
||||||
baseUrl += '/';
|
baseUrl += '/';
|
||||||
|
@ -32,6 +35,25 @@ namespace Jellyfin.Server.Extensions
|
||||||
{
|
{
|
||||||
// Custom path requires {documentName}, SwaggerDoc documentName is 'api-docs'
|
// Custom path requires {documentName}, SwaggerDoc documentName is 'api-docs'
|
||||||
c.RouteTemplate = $"/{baseUrl}{{documentName}}/openapi.json";
|
c.RouteTemplate = $"/{baseUrl}{{documentName}}/openapi.json";
|
||||||
|
c.PreSerializeFilters.Add((swagger, httpReq) =>
|
||||||
|
{
|
||||||
|
swagger.Servers = new List<OpenApiServer> { new OpenApiServer { Url = $"{httpReq.Scheme}://{httpReq.Host.Value}{apiDocBaseUrl}" } };
|
||||||
|
|
||||||
|
// BaseUrl is empty, ignore
|
||||||
|
if (apiDocBaseUrl.Length != 0)
|
||||||
|
{
|
||||||
|
// Update all relative paths to remove baseUrl.
|
||||||
|
var updatedPaths = new OpenApiPaths();
|
||||||
|
foreach (var (key, value) in swagger.Paths)
|
||||||
|
{
|
||||||
|
var relativePath = key;
|
||||||
|
relativePath = relativePath.Remove(0, apiDocBaseUrl.Length);
|
||||||
|
updatedPaths.Add(relativePath, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
swagger.Paths = updatedPaths;
|
||||||
|
}
|
||||||
|
});
|
||||||
})
|
})
|
||||||
.UseSwaggerUI(c =>
|
.UseSwaggerUI(c =>
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue