From 119046109d117edbbf5dac55a4e190c596596402 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 16 Jun 2026 14:41:25 +0100 Subject: [PATCH] Fix ExposeSwaggerDocumentUrlsRoute behaviour Fix `SwaggerUIOptions.ExposeSwaggerDocumentUrlsRoute` not being respected. Fixes #3983. --- .../SwaggerUIMiddleware.cs | 11 +++++++---- .../SwaggerUIOptionsExtensions.cs | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs index 35493feff1..29493b539c 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs @@ -63,11 +63,14 @@ public async Task Invoke(HttpContext httpContext) return; } - var pattern = $"^/?{Regex.Escape(_options.RoutePrefix)}/{_options.SwaggerDocumentUrlsPath}/?$"; - if (Regex.IsMatch(path, pattern, RegexOptions.IgnoreCase)) + if (_options.ExposeSwaggerDocumentUrlsRoute) { - await RespondWithDocumentUrls(httpContext); - return; + var pattern = $"^/?{Regex.Escape(_options.RoutePrefix)}/{_options.SwaggerDocumentUrlsPath}/?$"; + if (Regex.IsMatch(path, pattern, RegexOptions.IgnoreCase)) + { + await RespondWithDocumentUrls(httpContext); + return; + } } } diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptionsExtensions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptionsExtensions.cs index 7801cacb42..84ab62d486 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptionsExtensions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIOptionsExtensions.cs @@ -329,7 +329,7 @@ public static void UseResponseInterceptor(this SwaggerUIOptions options, string /// /// Function to enable the option to expose the available - /// Swagger document urls to external parties. + /// Swagger document URLs to external parties. /// /// public static void EnableSwaggerDocumentUrlsEndpoint(this SwaggerUIOptions options)