Skip to content

Add Support for Async OperationFilters #2430

@Danielku15

Description

@Danielku15

I searched for issues related to this topic but could not find any discussion with the keywords I used. Hence I open this new discussion.

Description
More and more ASP.net core APIs tend to be async only and do not provide sync overloads anymore. The filters in Swashbuckle like the IOperationFilter are sync which makes it hard to call over to certian ASP.net core APIs to obtain data you might need for generating the Swagger document you want to have.

It would be great if Swashbuckle could provide async variants for all filters so we can await calls over to the ASP.net core infrastructure.

Concrete use case/example:
We want to extend our API documentation with RBAC information. To load certain aspects of the authorization rules defined in the API APIs like the IAuthorizationPolicyProvider need to be used. Here an example how ASP.net core is building the overall policy for an endpoint in the related AuthorizationMiddleware:

https://github.com/dotnet/aspnetcore/blob/d02dca7d2285090888fa18bd7789c94504c97191/src/Security/Authorization/Policy/src/AuthorizationMiddleware.cs#L58-L63

The same code cannot be placed inside an IOperationFilter to build the policy for an endpoint because only async overloads exist.

Current Workaround
Use some mechanisms like described here to call async code from sync code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions