diff --git a/src/Swashbuckle.AspNetCore.ReDoc/ReDocBuilderExtensions.cs b/src/Swashbuckle.AspNetCore.ReDoc/ReDocBuilderExtensions.cs index a234117fc4..77b639782a 100644 --- a/src/Swashbuckle.AspNetCore.ReDoc/ReDocBuilderExtensions.cs +++ b/src/Swashbuckle.AspNetCore.ReDoc/ReDocBuilderExtensions.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Routing; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Swashbuckle.AspNetCore.ReDoc; @@ -52,7 +53,20 @@ public static IEndpointConventionBuilder MapReDoc( .UseReDoc(options) .Build(); - return endpoints.Map(GetRoutePattern(options.RoutePrefix), pipeline); + return endpoints.Map(GetRoutePattern(options.RoutePrefix), async (context) => + { + var endpoint = context.GetEndpoint(); + context.SetEndpoint(null); + + try + { + await pipeline(context); + } + finally + { + context.SetEndpoint(endpoint); + } + }); } private static ReDocOptions ResolveOptions(IServiceProvider serviceProvider, Action setupAction) diff --git a/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs b/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs index 0da63214ee..f5bb59f77a 100644 --- a/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs +++ b/src/Swashbuckle.AspNetCore.Swagger/DependencyInjection/SwaggerBuilderExtensions.cs @@ -1,7 +1,7 @@ +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.AspNetCore.Routing.Patterns; using Microsoft.AspNetCore.Routing.Template; -using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; using Swashbuckle.AspNetCore.Swagger; @@ -47,7 +47,20 @@ public static IEndpointConventionBuilder MapSwagger( .UseSwagger(Configure) .Build(); - return endpoints.MapMethods(pattern, [HttpMethods.Get, HttpMethods.Head], pipeline); + return endpoints.MapMethods(pattern, [HttpMethods.Get, HttpMethods.Head], async (context) => + { + var endpoint = context.GetEndpoint(); + context.SetEndpoint(null); + + try + { + await pipeline(context); + } + finally + { + context.SetEndpoint(endpoint); + } + }); void Configure(SwaggerOptions options) { diff --git a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIBuilderExtensions.cs b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIBuilderExtensions.cs index c5b71615ba..b15c44ed75 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIBuilderExtensions.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIBuilderExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -60,7 +61,20 @@ public static IEndpointConventionBuilder MapSwaggerUI( .UseSwaggerUI(options) .Build(); - return endpoints.Map(GetRoutePattern(options.RoutePrefix), pipeline); + return endpoints.Map(GetRoutePattern(options.RoutePrefix), async (context) => + { + var endpoint = context.GetEndpoint(); + context.SetEndpoint(null); + + try + { + await pipeline(context); + } + finally + { + context.SetEndpoint(endpoint); + } + }); } private static SwaggerUIOptions ResolveOptions(IServiceProvider serviceProvider, Action setupAction)