pythondjangorestdjango-rest-frameworkdjango-swagger

Django REST Swagger: List and Retrieve functions are not detected by Swagger


I'm using django-rest-swagger version: 2.0.5 and django-rest-framework version: 3.4.6.

I realiased that when I use list or retrieve functions the Swagger can not detect them as new endpoints.

I have the following code in my views.py file:

from rest_framework.viewsets import ViewSet

class OrdersViewSet(ViewSet):
    lookup_field = 'uuid'

    def list(self, request: Request, *args, **kwargs):
        try:
            changeset = OrderSyncHelper().get_order_list_data()
            return Response(status=HTTP_200_OK, data=changeset)
        except (KeyError, ValueError) as e:
            return Response(status=HTTP_400_BAD_REQUEST, data=e.args)

    def retrieve(self, request: Request, uuid: str, *args, **kwargs):
        try:
            changeset = OrderSyncHelper().get_order_data(uuid)
            return Response(status=HTTP_200_OK, data=changeset)
        except (KeyError, ValueError) as e:
            return Response(status=HTTP_400_BAD_REQUEST, data=e.args)

I was expecting to see in the openapi.json file the following endpoints:

But they are not presented. Should I add something specific to these functions in order to be detected by Swagger?


Solution

  • The issue fixed when I tried to upgrade the django-rest-swagger to version 2.1.1.

    So in version 2.1.1 the Swagger is able to detect endpoints which are implemented using retrieve or list functions