Skip to content

Commit 4ad59b1

Browse files
committed
Optimize swagger
1 parent 9a82e01 commit 4ad59b1

File tree

1 file changed

+6
-21
lines changed

1 file changed

+6
-21
lines changed

src/JoinRpg.Portal/Infrastructure/XApi/Swagger.cs

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ namespace JoinRpg.Portal.Infrastructure
1717

1818
internal class Swagger
1919
{
20-
private const string ForwardedPrefixHeader = "X-Forwarded-Prefix";
21-
2220
internal static void ConfigureSwagger(SwaggerGenOptions c)
2321
{
2422
var securityScheme = new OpenApiSecurityScheme
@@ -52,33 +50,20 @@ internal static void ConfigureSwagger(SwaggerGenOptions c)
5250
c.DocumentFilter<SwaggerXGameApiFilter>();
5351
}
5452

55-
internal static void Configure(SwaggerOptions options) => options.PreSerializeFilters.Add(ReverseProxyPreSerializeFilter);
53+
internal static void Configure(SwaggerOptions options) { }
5654

57-
internal static void ConfigureUI(SwaggerUIOptions c) => c.SwaggerEndpoint("v1/swagger.json", "My API V1");
55+
internal static void ConfigureUI(SwaggerUIOptions c)
56+
{
57+
c.SwaggerEndpoint("v1/swagger.json", "My API V1");
58+
c.ConfigObject.DeepLinking = true;
59+
}
5860

5961
internal static Task RedirectToSwagger(HttpContext ctx)
6062
{
6163
ctx.Response.Redirect("swagger/");
6264
return Task.CompletedTask;
6365
}
6466

65-
private static void ReverseProxyPreSerializeFilter(OpenApiDocument document, HttpRequest request)
66-
{
67-
string prefix;
68-
if (!request.Headers.TryGetValue(ForwardedPrefixHeader, out var prefixHeaderValues) ||
69-
prefixHeaderValues.Count == 0 ||
70-
string.IsNullOrEmpty(prefix = prefixHeaderValues[0]))
71-
{
72-
return;
73-
}
74-
75-
document.Servers.Add(new OpenApiServer
76-
{
77-
Url = prefix,
78-
Description = "Reverse proxy server",
79-
});
80-
}
81-
8267
private class SwaggerXGameApiFilter : IDocumentFilter
8368
{
8469
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)

0 commit comments

Comments
 (0)