Skip to content
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

Add support for herited action methods #180

Open
Kaon68 opened this issue Apr 8, 2021 · 0 comments
Open

Add support for herited action methods #180

Kaon68 opened this issue Apr 8, 2021 · 0 comments

Comments

@Kaon68
Copy link

Kaon68 commented Apr 8, 2021

Hi there

I've noticed that herited action method does not show the lock icon with SecurityRequirementsOperationFilter.

For the moment, I have bypassed this issue by cloning your SecurityRequirementsOperationFilter (generic and non generic) classes and replaced extension method GetControllerAndActionAttributes by this one :

   public static IEnumerable<T> GetControllerAndActionAttributes<T>(this OperationFilterContext context) where T : Attribute
        {
            var controllerAttributes = context.GetControllerTypeInfos().GetTypeInfo().GetCustomAttributes<T>();
            var actionAttributes = context.MethodInfo.GetCustomAttributes<T>();

            var result = new List<T>(controllerAttributes);
            result.AddRange(actionAttributes);
            return result;
        }

        public static TypeInfo GetControllerTypeInfos(this OperationFilterContext context)
        {
            ControllerActionDescriptor controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor;
            TypeInfo controllerType = controllerActionDescriptor?.ControllerTypeInfo;
            controllerType ??= context.MethodInfo.DeclaringType?.GetTypeInfo();

            return controllerType;
        }

maybe quick & dirty, but it works ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant