Skip to content

Commit

Permalink
Document extend_schema_view support for @action (#1178)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
johnthagen and tfranzel authored Feb 20, 2024
1 parent f9f0336 commit ef82c0e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 <drf_spectacular.utils.extend_schema>` on views
to attach annotations to all methods in that view (e.g. tags). Method annotations will take precedence
over view annotation.
Expand Down
2 changes: 2 additions & 0 deletions drf_spectacular/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down

0 comments on commit ef82c0e

Please sign in to comment.