Django Swagger not showing urls without permission Class

Viewed 3161

I am setting up Django-rest-swagger for my project. I have following settings for Django-restframework.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'oauth2_provider.contrib.rest_framework.OAuth2Authentication',
    ),
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
}

Now, when I have View with some permission class like this

class CreateUserView(viewsets.ModelViewSet):
    serializer_class = UserServiceSerializer
    authentication_classes = []
    permission_classes = []

class UserProfileView(viewsets.ModelViewSet):

    serializer_class = UserProfileSerializer
    serializer_class_2 = UserServiceSerializer

I see following view

enter image description here

But when add permission_classes in both view like this

class CreateUserView(viewsets.ModelViewSet):
    serializer_class = UserServiceSerializer
    authentication_classes = []
    permission_classes = []

class UserProfileView(viewsets.ModelViewSet):

    serializer_class = UserProfileSerializer
    serializer_class_2 = UserServiceSerializer
    permission_classes = []

I see view like this

enter image description here

I do not want to add permission class in every view as I have same class for all my view and I have mentioned that in my rest-framework setting. How can I do that?

2 Answers

seems like you have applied default permission classes to make APIs non public so one way to overcome this is to apply "AllowAny" as default permission class but this way all your APIs will be public, so another solution you can try is put swagger setting in you settings.py

SWAGGER_SETTINGS = {

'SECURITY_DEFINITIONS': {
'api_key': {
    'type': 'apiKey',
    'in': 'header',
    'name': 'Authorization'
}
},

this will ask for token in browser while using that API.

Related