Search code examples
django-rest-frameworkswaggerswagger-ui

Django drf-spectacular show permissions for each view


I'd like to show the necessary permissions for each API endpoint in my Swagger UI. I'm not finding any relevant documentation.

So something like:

@extend_schema(
    description="Get all responsible parties",
    responses={200: ResponsiblePartySerializer},
    permissions=[responsible_party.can_view_responsible_party]
)

Does this exist or how would you accomplish showing the permissions for each API route?


Solution

  • I couldn't find any way of generating documentation at view level. Something here would've been ideal:

    enter image description here

    Nevertheless, I found it's possible to generate documentation that affects all of a view's endpoints:

    @extend_schema(summary='[IsSuperUser]')
    class ActionsController(RetrieveModelMixin, ListModelMixin, BatchCreateControllerMixin):
    

    Which results in:

    enter image description here

    Then, you can override this per endpoint when a different schema is needed. besides, extend_schema supports many parameters, in my case, only a string naming the permission sufficed.