Search code examples
c#asp.net-core.net-6.0swashbuckle

Where is the GetCustomAttributes method of the ActionDescriptor with Swashbuckle in asp.net core 6.0?


Old ASP.NET Web API 2:

apiDescription.ActionDescriptor.GetCustomAttributes<MyCustomAttribute>();

apiDescription is a parameter from the interface IOperationFilter method

public void Apply(Operation operation, SchemaRegistry schemaRegistry, ApiDescription apiDescription)

ASP.NET Core 6 Web API (does not work):

public void Apply(OpenApiOperation operation, OperationFilterContext context)
    

context.ApiDescription.GetCustomAttributes<MyCustomAttribute>());

Where did they hide the GetCustomAttributes method?


Solution

  • Try using OperationFilterContext.MethodInfo:

    context.MethodInfo.GetCustomAttributes<MyCustomAttribute>();