From ef82c0e5cd61815519f160355c5ebdd73d99651d Mon Sep 17 00:00:00 2001 From: johnthagen Date: Tue, 20 Feb 2024 16:38:38 -0500 Subject: [PATCH] Document `extend_schema_view` support for `@action` (#1178) * Document extend_schema_view support for @action * Fix formatting * Update customization.rst fix rst syntax * Update utils.py * Update utils.py oh boy --------- Co-authored-by: T. Franzel --- docs/customization.rst | 12 ++++++++++++ drf_spectacular/utils.py | 2 ++ 2 files changed, 14 insertions(+) diff --git a/docs/customization.rst b/docs/customization.rst index 212e6a7f..04373c45 100644 --- a/docs/customization.rst +++ b/docs/customization.rst @@ -74,6 +74,18 @@ discovered in the introspection. class XViewset(mixins.ListModelMixin, viewsets.GenericViewSet): ... + This also supports annotating extra user-defined DRF ``@action``\s + + .. code-block:: python + + @extend_schema_view( + notes=extend_schema(description='text') + ) + class XViewset(mixins.ListModelMixin, viewsets.GenericViewSet): + @action(detail=False) + def notes(self, request): + ... + .. note:: You may also use :py:func:`@extend_schema ` on views to attach annotations to all methods in that view (e.g. tags). Method annotations will take precedence over view annotation. diff --git a/drf_spectacular/utils.py b/drf_spectacular/utils.py index 6fef226b..8689aec6 100644 --- a/drf_spectacular/utils.py +++ b/drf_spectacular/utils.py @@ -644,6 +644,8 @@ def extend_schema_view(**kwargs) -> Callable[[F], F]: This decorator also takes care of safely attaching annotations to derived view methods, preventing leakage into unrelated views. + This decorator also supports custom DRF ``@action`` with the method name as the key. + :param kwargs: method names as argument names and :func:`@extend_schema <.extend_schema>` calls as values """