from typing import List, Any
from drf_spectacular.openapi import AutoSchema as _AutoSchema


class AutoSchema(_AutoSchema):
    def get_filter_backends(self) -> List[Any]:
        return getattr(self.view, "filter_backends", [])

    def get_description(self) -> str:
        description = super().get_description()
        permissions = []
        for perm in self.view.permission_classes:
            if hasattr(perm, "get_resource_permissions"):
                permissions = perm.get_resource_permissions(self.view, self.method)

        if not permissions:
            return description

        permissions_string = ' '.join([f'`{p}`' for p in permissions])
        description = f'**Permissions**: {permissions_string}\n\n{description}'
        return description
