Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ckcollab opened this issue Aug 13, 2017 · 7 comments
Open

Comments

@ckcollab
Copy link

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!

@mertsalik
Copy link

Same here,
djangorestframework: 3.3.2
drfdocs: 0.0.9

@soraphis
Copy link

soraphis commented Aug 25, 2017

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

@ckcollab
Copy link
Author

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

@soraphis
Copy link

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!

@ckcollab
Copy link
Author

ckcollab commented Aug 30, 2017

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.

@realnot
Copy link

realnot commented Sep 28, 2017

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

@ckcollab
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants