-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: SwaggerUIMiddleware is now internal #3144
Comments
This isn't a bug as it was an intentional change as having it public made it harder to change implementation details in previous minor releases, and it had no virtual members so the need to use/derive from it seemed to be non-existent. Shipping a new major version also gave us the opportunity to make the breaking change. However, I'm open to adding functionality/API that enables your use case of having multiple middlewares for different APIs. Could you share some more details about exactly what it is that you do in your application with 6.x? That will give us more idea about how we could enable this in an easier to maintain way than the previous design. |
Each tenant has its own OAuth authorization server and we wanted to provide useable swaggers to the users of different tenants. So in order to make the Swagger UI be able to deal with this:
(sorry for slow reply; I was just ready updating to .NET 9 and was 1 am here. Didn't expected a reply would came that quickly) |
Off the top of my head without trying it, it sounds like you could achieve the same thing with string[] prefixes = ["foo", "bar"];
foreach (var prefix in prefixes)
{
app.UseSwaggerUI(new() { RoutePrefix = prefix });
} Would this work for you? |
we have now about 5000 tenants where it needs to work? is that large? For me feels quiet some overhead in the number of middlewares running; but I have no idea on the impact of that |
5,000 does sound "large" - if this approach doesn't work, then I think the path forward would be to allow more configurability, rather than just re-expose the class. It was made internal as it created issues when we wanted to change constructor parameters to add new dependencies, and I'd rather not reintroduce that problem. IMHO, the middleware class itself is an implementation detail. |
Do you have an approach in mind? (maybe i can help implement it). Last night I tried to use RoutePrefix with a regex in it. But noticed that RoutePrefix is Escaped so that didnt work. And I am not sure about the implications to the rest of the code of this approach. Another approach might be to extract the logic of the middleware and expose it as a Render Util class that external ones can use instead of the standard middleware? |
I was thinking about something like extracting the "is this a request I should respond to" logic here into its own callback: Swashbuckle.AspNetCore/src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIMiddleware.cs Lines 66 to 94 in be0090d
Then we could add a new options property that allows you to provide a custom implementation of that, which would then in theory mean you're effectively injecting the logic of your custom wrapping class into our middleware itself and the end result is the same as what you were doing with v6. |
Yea think I got it. let me give it a try |
Describe the bug
With the release of Swashbuckle 7
SwaggerUIMiddleware
became internal. This is blocking us from upgrade.We have a multi tenant solution and to make swagger run a little bit different for each tenant we build a custom routing to end up the swagger ui. The url became /tenantname/swagger.
We achieved that by a Post Configure on the
SwaggerUIOptions
and have our own scoped middleware that passed this settings object to theSwaggerUIMiddleware
. But now the middleware became internal this is no longer possible.We are not really aware of other approaches that let us run multiple a swagger UI per tenant
Expected behavior
SwaggerUIMiddleware is public
Actual behavior
SwaggerUIMiddleware is internal
Steps to reproduce
No response
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
No response
.NET Version
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: