Open ckcollab opened 7 years ago
Same here, djangorestframework: 3.3.2 drfdocs: 0.0.9
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 thanks! Can you fork + make a PR for this?
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!
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.
Guys after a month someone could tell me if this is fixed? I'm struggling to make it works!
No, no updates here. We need a way to help maintainers get updates through... some kind of reward system...
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:
Looks like I can only do GET/OPTIONS?
Here's some code:
It's probably something silly I'm overlooking, thanks!