Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add note about extensions registering themselves #581

Merged
merged 1 commit into from
Oct 27, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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