-
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
Make IDocumentFilter async compatible #1661
Comments
I've had a look at the code and it seems implementing must be done wisely to not break anything. I'd propose to implement this in the following way:
Would you accept a PR implementing this? I think this will get important as in .Net Core 3.0 a lot of synchronous code is considered bad practice and this could hurt some more complex IDocumentFilter implementations |
@aersamkull - sounds good, do you want to get an initial PR submitted and we can iterate on the specifics? I'll keep an eye out for it as this does feel like a high priority. |
I've added PR #1817 which should implement it in a backward-compatible way. The only thing that might is critical is that DocumentProvider now expects IAsyncSwaggerProvider, I hope that is ok? |
Is this issue resolved? I want to create a public interface IAsyncSwaggerProvider
{
Task<OpenApiDocument> GetSwaggerAsync(
string documentName,
string? host = null,
string? basePath = null);
} and also of Before: var swagger = swaggerProvider.GetSwagger(
documentName,
host: null,
basePath); After: var swagger = await swaggerProvider.GetSwaggerAsync(
documentName,
host: null,
basePath); I think it is possible to create a backward compatible code to introduce such a change into the library. SwaggerUI does not get affected by this changes
|
Hi @domaindrivendev, I've added PR #2635. It is slightly different approach from @aersam 's. It adds a separate IDocumentAsyncFilter that is its own type and does not extend IDocumentFilter. In this way, it is still backward compatible, but those using IDocumentAsyncFilter do not have to wonder what to implement for the unused "void Apply()" method. I also saw a lot of discussion about naming, and thankfully, in the last couple years, some other naming precedent and changes have already occurred in the project, and I tried to follow in that same vein. Of note is that to help developers be clear about the intent of this new filter, I named it very similar to the old one, and only added Async to the name. |
Any status on this issue? I see no new commits since over a year on Swashbuckle, has the library been abandoned? |
|
Hi, in our application we want to support feature flag (https://docs.microsoft.com/en-us/azure/azure-app-configuration/use-feature-flags-dotnet-core) and some endpoint will be activate/deactivate based on the maturity of the feature or the target environment (Dev, SIT, UAT, Prod, ...), we want to remove the endpoint from the Swagger UI when the feature endpoint is not active. I use the IDocumentFilter to do so, but feature flag is Task-based, so i had to use GetAwaiter().GetResult() to make it work, but it would be better to have a async version of the IDocumentFilter like IActionFilter/IAsyncFilter of aspnetcore (https://docs.microsoft.com/en-us/aspnet/core/mvc/controllers/filters?view=aspnetcore-3.1#implementation). Here the code that i use as an example :
The text was updated successfully, but these errors were encountered: