0

I have a Django project with various REST APIs. The permission to access those APIs are defined throught rest_framework permission classes and django.contrib.auth.models Permission model.

The documentation of those apis is automatically generated using drf_yasg library, i need to find a way to inlcude in the schema generated from drf-yasg the needed permission to access every api without the need to write id down manually. Anyone can give me an hint?

Shad
  • 11
  • 4

1 Answers1

0

You'll need to take a look at SchemaGenerator and AutoSchema classes.

However, please be very careful when updating or manipulating these as their whole purpose is generating OpenAPI3 compliant schemas.

And whilst it might seem very helpful and useful to have some kinds of permissions inspectors, after all inspects many things, however permissions sadly isn't one of them.

I had a little Google around and I found a github post discussing this very topic, and whilst it's fairly bad practice to link to external sites, I think this can be an exceptional circumstance as the poster of the comment has articulated the answer in a way I don't understand, but does satisfy your question (maybe with some customisations).

https://github.com/axnsan12/drf-yasg/issues/358#issuecomment-545827035

Swift
  • 1,663
  • 1
  • 10
  • 21