Skip to content

Commit

Permalink
Add note about extensions registering themselves
Browse files Browse the repository at this point in the history
  • Loading branch information
johnthagen committed Oct 19, 2021
1 parent 59f9749 commit 45e675e
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/customization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ schema closer to your API.
Sane fallbacks are used wherever possible and some warnings might not even be relevant to you.
The remaining issues can be solved with the following steps.


Step 1: ``queryset`` and ``serializer_class``
---------------------------------------------
Introspection heavily relies on those two attributes. ``get_serializer_class()``
Expand Down Expand Up @@ -148,6 +147,13 @@ All extensions work on the same principle. You provide a ``target_class`` (impor
string or actual class) and then state what `drf-spectcular` should use instead of what
it would normally discover.

.. note:: The extensions register themselves automatically. Just be sure that the Python
interpreter sees them at least once.
To that end, we suggest creating a ``PROJECT/schema.py`` file and importing it in your
``PROJECT/__init__.py`` (same directory as ``settings.py`` and ``urls.py``)
with ``import PROJECT.schema``. Please do not import the file in
``settings.py`` as this may potentially lead to cyclic import issues. Now you are all set.

.. note:: Only the first Extension matching the criteria is used. By setting the ``priority`` attribute
on your extension, you can influence the matching order (default ``0``).
Built-in Extensions have a priority of ``-1``. If you subclass built-in Extensions, don't forget to
Expand Down

0 comments on commit 45e675e

Please sign in to comment.