Skip to content

Commit ef82c0e

Browse files
johnthagentfranzel
andauthored
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 <tfranzel@users.noreply.github.com>
1 parent f9f0336 commit ef82c0e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

docs/customization.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,18 @@ discovered in the introspection.
7474
class XViewset(mixins.ListModelMixin, viewsets.GenericViewSet):
7575
...
7676
77+
This also supports annotating extra user-defined DRF ``@action``\s
78+
79+
.. code-block:: python
80+
81+
@extend_schema_view(
82+
notes=extend_schema(description='text')
83+
)
84+
class XViewset(mixins.ListModelMixin, viewsets.GenericViewSet):
85+
@action(detail=False)
86+
def notes(self, request):
87+
...
88+
7789
.. note:: You may also use :py:func:`@extend_schema <drf_spectacular.utils.extend_schema>` on views
7890
to attach annotations to all methods in that view (e.g. tags). Method annotations will take precedence
7991
over view annotation.

drf_spectacular/utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -644,6 +644,8 @@ def extend_schema_view(**kwargs) -> Callable[[F], F]:
644644
This decorator also takes care of safely attaching annotations to derived view methods,
645645
preventing leakage into unrelated views.
646646
647+
This decorator also supports custom DRF ``@action`` with the method name as the key.
648+
647649
:param kwargs: method names as argument names and :func:`@extend_schema <.extend_schema>`
648650
calls as values
649651
"""

0 commit comments

Comments
 (0)