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) <noreply@anthropic.com>
This commit is contained in:
@@ -92,6 +92,13 @@ app.UseMiddleware<ExceptionHandlingMiddleware>();
|
|||||||
app.UseSwagger(options =>
|
app.UseSwagger(options =>
|
||||||
{
|
{
|
||||||
options.RouteTemplate = "docs/{documentName}/swagger.json";
|
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<OpenApiServer> { new() { Url = basePath } };
|
||||||
|
});
|
||||||
});
|
});
|
||||||
app.UseSwaggerUI(options =>
|
app.UseSwaggerUI(options =>
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user