fixed swagger

This commit is contained in:
JiriUhlir
2026-06-12 14:29:01 +02:00
parent 06b22dfa4e
commit aad8ba3d03
3 changed files with 26 additions and 5 deletions
+12 -4
View File
@@ -80,17 +80,25 @@ var app = builder.Build();
if (!string.IsNullOrWhiteSpace(settings.RootPath))
{
app.UsePathBase(settings.RootPath);
// UsePathBase requires a leading slash; tolerate ROOT_PATH configured without one.
var basePath = settings.RootPath.StartsWith('/') ? settings.RootPath : "/" + settings.RootPath;
app.UsePathBase(basePath);
}
app.UseMiddleware<ExceptionHandlingMiddleware>();
app.UseSwagger();
// Serve the OpenAPI document under the same /docs prefix as the UI so a relative endpoint
// resolves correctly both locally and behind a reverse-proxy path base (ROOT_PATH).
app.UseSwagger(options =>
{
options.RouteTemplate = "docs/{documentName}/swagger.json";
});
app.UseSwaggerUI(options =>
{
// Serve the interactive docs at /docs (matching the sibling microsoft-365-service).
// Interactive docs at /docs (matching the sibling microsoft-365-service).
options.RoutePrefix = "docs";
options.SwaggerEndpoint("/swagger/v1/swagger.json", $"{settings.AppName} v1");
// Relative endpoint — resolves to {pathBase}/docs/v1/swagger.json in the browser.
options.SwaggerEndpoint("v1/swagger.json", $"{settings.AppName} v1");
options.DocumentTitle = $"{settings.AppName} API docs";
});