Reputation: 2940
I used Django REST Swagger in my Django project. It is able to show all the URL with views which does not have
permission_classes = [IsAuthenticated]
. While the view with permission_classes = [IsAuthenticated]
is not shown in the list-api.
Here is an example:
class EquipmentCategoryViewSet(ResponseMixin, viewsets.ModelViewSet):
queryset = EquipmentCategory.objects.all()
serializer_class = EquipmentCategorySerializer
permission_classes = [IsAuthenticated]
if i remove permission_classes = [IsAuthenticated]
, it is shown in the swagger list-api.
I downgraded swagger to 2.1.2 and clicked on authorized and passed the token.
The strange thing is I have a prefix 'Token' in my value. When i login with Token<tokenvalue>
login fails. But when I pass <tokenvalue>
it gets authenticated but the views with isAuthenticated is not shown.
Please suggest what should be done to show views with isAuthenticated added.
Upvotes: 4
Views: 2421
Reputation: 3156
you can just override the schema
from rest_framework.schemas import get_schema_view
from rest_framework_swagger import renderers
schema_view = get_schema_view(title="Fbs Api Docs", public=True, renderer_classes=[renderers.OpenAPIRenderer, renderers.SwaggerUIRenderer])
you pass the public=True it will allow all api to list, in urls.py include below
path('docs/', schema_view),
Upvotes: 2
Reputation: 1608
In document API top right corner there is a option for authorise or to log in. Do provide valid token in it or login. This will list other endpoints.
Use swagger 2.1.2.
The latest django swagger version 2.2 has some issue with authorization. Refer: https://github.com/marcgibbons/django-rest-swagger/issues/762
Upvotes: 2