django-rest-framework-docs icon indicating copy to clipboard operation
django-rest-framework-docs copied to clipboard

DRFDocs not showing delete, post, etc. options but regular docs do?

Open ckcollab opened this issue 7 years ago • 7 comments

Heyo! Thanks so much for releasing this, it is beautiful.

I am a little confused on why I'm not seeing POST/DELETE/etc. on the DRF docs version, but I can see it on the regular API docs:

image

image

Looks like I can only do GET/OPTIONS?

Here's some code:

from rest_framework import viewsets, mixins

from api import serializers
from competitions.models import Competition


class CompetitionViewSet(mixins.ListModelMixin,
                         mixins.CreateModelMixin,
                         mixins.UpdateModelMixin,
                         mixins.DestroyModelMixin,
                         viewsets.GenericViewSet):
    """Tyler loves pizza!!!"""
    queryset = Competition.objects.all()
    serializer_class = serializers.CompetitionSerializer
from django.conf.urls import url, include
from rest_framework import routers

from . import views


router = routers.DefaultRouter()
router.register(r'competitions', views.CompetitionViewSet)

urlpatterns = [
    url(r'^', include(router.urls)),

    url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')),

    url(r'^docs/', include('rest_framework_docs.urls')),
]

It's probably something silly I'm overlooking, thanks!

ckcollab avatar Aug 13 '17 02:08 ckcollab

Same here, djangorestframework: 3.3.2 drfdocs: 0.0.9

mertsalik avatar Aug 25 '17 09:08 mertsalik

still an issue on drfdocs: 0.0.11 but corrected in current master files.

but still an issue: @detail_route and @list_route don't show the correct methods

edit need to correct myself: in the current master files, they are fixed for ModelViewSet but not for GenericViewSet with mixins

edit 2 my hotfix: installed via pip, replaced the files with the current master-branch files and in api-endpoints.py at line 42:

    def is_method_allowed(self, callback_cls, method_name):
        has_attr = hasattr(callback_cls, method_name)

        viewset_method = ( (issubclass(callback_cls, ModelViewSet) or
                            issubclass(callback_cls, GenericViewSet))and   # fix for GenericViewSet
                          method_name in VIEWSET_METHODS.get(self.callback.suffix, []))

        try:  # fix for detail_routes and list_routes
            b = method_name in self.callback.actions
        except AttributeError:
            b = False

        return has_attr or viewset_method or b

its probably not the nicest way to do it, but it works for me

soraphis avatar Aug 25 '17 11:08 soraphis

@soraphis thanks! Can you fork + make a PR for this?

ckcollab avatar Aug 29 '17 22:08 ckcollab

there already is a PR open that should fix this: #132 its open since 2016 though.

and it should be noted, that i've made a dirty fix for the most obvious probablems, but there are still problems left regarding this, e.g.:

class MyViewSet(viewsets.ModelViewSet):
    serializer_class = ser.MySerializer

    # ...

    @detail_route(methods=['post'], serializer_class=ser.AnotherSerializer)
    def my_detail_route(self, request, pk=None):
        # ...

my quick-and-dirty fix will not show the serializer fields of AnotherSerializer in the docs (but it will show the post method available)

it currently does not bother me enough to fix this - sorry. but for a PR this should be addressed too!

soraphis avatar Aug 30 '17 18:08 soraphis

Using this combination of classes seems to work:

from rest_framework.viewsets import GenericViewSet
from rest_framework.generics import ListAPIView, CreateAPIView, RetrieveAPIView, DestroyAPIView


class DataViewSet(ListAPIView, CreateAPIView, RetrieveAPIView, DestroyAPIView, GenericViewSet):
    pass

I think that this is about the same behavior, just different classes.. that seem to work? This is for a simple dummy app that does nothing, so I'm not sure if this breaks other things.

ckcollab avatar Aug 30 '17 18:08 ckcollab

Guys after a month someone could tell me if this is fixed? I'm struggling to make it works!

realnot avatar Sep 28 '17 14:09 realnot

No, no updates here. We need a way to help maintainers get updates through... some kind of reward system...

ckcollab avatar Sep 28 '17 15:09 ckcollab