pythondjangodjango-rest-frameworkdjango-swagger

Django REST Swagger not showing POST methods


I'm having problem with Django REST Swagger. I've created a simple viewset for users using DRF (just for showing my problem), where AppUser is my custom user model and it is not showing the POST method in my documentation, but I can call it with Postman and create a new resource.

I'm using:

Here is my code:

views.py

class UserViewSet(viewsets.ModelViewSet):

    queryset = AppUser.objects.all()
    serializer_class = UserSerializer

serializers.py

class UserSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = AppUser
        fields = '__all__'

urls.py

from django.conf.urls import url, include
from rest_framework.routers import SimpleRouter
from rest_framework_swagger.views import get_swagger_view
import app.views as app

# creating router
router = SimpleRouter()
router.register(r'users', app.UserViewSet)

schema_view = get_swagger_view(title='My app API')

# register urls
urlpatterns = [
    url(r'^', include(router.urls)),
    url(r'^docs', schema_view) 
]

Here you can see what my app documentation looks like:

actual API documentation

I would like to get something like this:

ideal documentation

I've tried multiple tutorials on creating Swagger documentation and I was trying it on User model, but I still get only the GET request. What am I doing wrong?

Thank you for your help.


Solution

  • I've figured it out. I haven't been logged in properly so I haven't been authenticated against permissions listed in DEFAULT_PERMISSION_CLASSES setting for DRF in settings.py.

    REST_FRAMEWORK = {
        'DEFAULT_PERMISSION_CLASSES':
            ('rest_framework.permissions.IsAuthenticatedOrReadOnly',),
    }
    

    HTTP methods POST, PUT, PATCH, etc. are checked using has_permission() against list of permissions defined there.

    After logging in it works well.

    EDIT: Problem with login was, that Django-rest-swagger 2.2.0 is not working correctly with JWT authentication, so I downgraded to 2.1.2.