Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django REST Swagger hiding ModelViewSet with permission_classes=[IsAuthenticated]

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.

like image 605
shrestha rohit Avatar asked Sep 14 '25 04:09

shrestha rohit


1 Answers

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

like image 152
a_k_v Avatar answered Sep 16 '25 21:09

a_k_v