diff --git a/rest_framework/schemas/coreapi.py b/rest_framework/schemas/coreapi.py index 657178304a..4a1ecc0f29 100644 --- a/rest_framework/schemas/coreapi.py +++ b/rest_framework/schemas/coreapi.py @@ -11,7 +11,10 @@ from .generators import BaseSchemaGenerator from .inspectors import ViewInspector -from .utils import get_pk_description, is_list_view +from .utils import ( + ALLOW_FILTER_ACTIONS, ALLOW_FILTER_METHODS, get_pk_description, + is_list_view +) def common_path(paths): @@ -522,9 +525,9 @@ def _allows_filters(self, path, method): return False if hasattr(self.view, 'action'): - return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"] + return self.view.action in ALLOW_FILTER_ACTIONS - return method.lower() in ["get", "put", "patch", "delete"] + return method.lower() in ALLOW_FILTER_METHODS def get_filter_fields(self, path, method): if not self._allows_filters(path, method): diff --git a/rest_framework/schemas/openapi.py b/rest_framework/schemas/openapi.py index eb7dc909d9..b84702fe88 100644 --- a/rest_framework/schemas/openapi.py +++ b/rest_framework/schemas/openapi.py @@ -18,7 +18,10 @@ from .generators import BaseSchemaGenerator from .inspectors import ViewInspector -from .utils import get_pk_description, is_list_view +from .utils import ( + ALLOW_FILTER_ACTIONS, ALLOW_FILTER_METHODS, get_pk_description, + is_list_view +) class SchemaGenerator(BaseSchemaGenerator): @@ -320,8 +323,8 @@ def allows_filters(self, path, method): if getattr(self.view, 'filter_backends', None) is None: return False if hasattr(self.view, 'action'): - return self.view.action in ["list", "retrieve", "update", "partial_update", "destroy"] - return method.lower() in ["get", "put", "patch", "delete"] + return self.view.action in ALLOW_FILTER_ACTIONS + return method.lower() in ALLOW_FILTER_METHODS def get_pagination_parameters(self, path, method): view = self.view diff --git a/rest_framework/schemas/utils.py b/rest_framework/schemas/utils.py index 60ed698294..84690670e7 100644 --- a/rest_framework/schemas/utils.py +++ b/rest_framework/schemas/utils.py @@ -39,3 +39,7 @@ def get_pk_description(model, model_field): value_type=value_type, name=model._meta.verbose_name, ) + + +ALLOW_FILTER_ACTIONS = {"list", "retrieve", "update", "partial_update", "destroy"} +ALLOW_FILTER_METHODS = {"get", "put", "patch", "delete"}