From b01c09006acb4c4bfbdfd6ed8603057a80958848 Mon Sep 17 00:00:00 2001 From: JiriUhlir <149317995+JiriUhlir@users.noreply.github.com> Date: Mon, 15 Jun 2026 08:20:14 +0200 Subject: [PATCH] swagger: advertise PathBase as OpenAPI server so Try-it-out targets the proxy prefix Swagger UI was calling the host root (services.csbot.cz/contacts) instead of services.csbot.cz/apps/idoklad/contacts. Emit servers=[{url: PathBase}] so the same base that /docs runs under is prefixed to the API requests too. Co-Authored-By: Claude Opus 4.8 (1M context) --- Program.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Program.cs b/Program.cs index dd6d069..55cb27b 100644 --- a/Program.cs +++ b/Program.cs @@ -92,6 +92,13 @@ app.UseMiddleware(); app.UseSwagger(options => { options.RouteTemplate = "docs/{documentName}/swagger.json"; + // Advertise the request path base (e.g. /apps/idoklad behind the portal proxy) as the + // OpenAPI server so Swagger UI "Try it out" targets {pathBase}/contacts, not the host root. + options.PreSerializeFilters.Add((swaggerDoc, httpReq) => + { + var basePath = httpReq.PathBase.HasValue ? httpReq.PathBase.Value : "/"; + swaggerDoc.Servers = new List { new() { Url = basePath } }; + }); }); app.UseSwaggerUI(options => {