I use drf-yasg to generate swagger docs for my Django REST API. I have a couple of endpoints, items/ with GET, POST and DELETE methods; and items/<uuid:itemID> with DELETE method only. However, the generated swagger docs erroneously include also GET and POST for the latter endpoint.
This is a snippet of what I have in urls.py:
urlpatters = [
url(r'^items/$', views.ItemViewSet.as_view()),
path('items/<uuid:itemID>', views.ItemViewSet.as_view()),
]
views.py contains something like:
class ItemViewSet(mixins.DestroyModelMixin, GenericAPIView):
def get(self, request):
# ...
return Response(HTTP_200_OK)
def post(self, request):
# ...
return Response(status=status.HTTP_201_CREATED)
def delete(self, request, itemID):
# ...
return Response(status=status.HTTP_204_NO_CONTENT)
def delete(self, request):
# ...
return Response(status=status.HTTP_204_NO_CONTENT)
How can I exclude GET and POST from items/<uuid:itemID> documentation?
I have read through https://github.com/axnsan12/drf-yasg/blob/master/docs/custom_spec.rst and Exclude URLs from Django REST Swagger but haven't found a working solution yet.
get_operation()
. I'll post this as an answer later, unless a better solution comes up. – Shrink