Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separate by apps in drf-spectacular

Tags:

django

Here it is the UI i can get from drf-spectacular redoc: screenshot As you can see the only way to know the apps is from the names: v1_foo_foodcourtrests_des v1_ord_customer_basket_li Here foo and ord are app names.

But I want to have a separator or something to separate these by the app names

Here is what I got so far and still no luck: https://drf-spectacular.readthedocs.io/en/latest/settings.html#settings

like image 699
Setare Kalantari Avatar asked Jan 27 '26 04:01

Setare Kalantari


1 Answers

take a look at the answers to this question

one of the possible solutions is to use tags and operation_id in the extend_schema decorator to achieve the desired outcome.

for example:

from drf_spectacular.utils import extend_schema

@extend_schema(tags=['Users App'])
class UserView(APIView):

    @extend_schema(operation_id='Get the user Details')
    def get(self, request, *args, **kwargs):
        # response

will result in:

enter image description here

another more streamlined solution if all of the urls have the same starting part like /v1/ is to change the drf spectacular settings:

SPECTACULAR_SETTINGS = {
    'SCHEMA_PATH_PREFIX': r'/v1/',
}

this will generate new sections based on each app initial url part, like foo, ord, etc.

like image 199
Alireza Mastery Avatar answered Jan 28 '26 20:01

Alireza Mastery