drf-yasg icon indicating copy to clipboard operation
drf-yasg copied to clipboard

Can't describe GET Method for detail, and list in APIView class based views.

Open SzateX opened this issue 4 years ago • 1 comments

Hi,

I have problem, and I didn't see way to annotate class which inheriting from API View, when get method for list and detail are merged together in one class. For example:

` class CompanyView(APIView): company_serializer_class = CompanySerializer single_company_serializer_class = SingleCompanySerializer

def get(self, request, pk=None, format=None):
    if pk:
        serializer = self.get_single(request, pk, format)
    else:
        serializer = self.get_many(request, format)
    return Response(serializer.data, status=status.HTTP_200_OK)

@swagger_auto_schema(operation_description="GET /company/", responses={200: SingleCompanySerializer()})
def get_single(self, request, pk, format=None):
    company = Company.objects.get(id=pk)
    return self.single_company_serializer_class(company)

@swagger_auto_schema(operation_description="GET /company/{pk}/", responses={200: CompanySerializer(many=True)})
def get_many(self, request, format=None):
    companies = Company.objects.all()
    return self.company_serializer_class(companies, many=True)

`

I have tried, as you can see above, but there is no any update in swagger. When I move swagger_auto_schema decorator into get method, I get error that duplicated decorator applied.

Could you solve this problem?

SzateX avatar Oct 24 '20 17:10 SzateX

When you say there's no update in swagger are you getting anything listed for that view? Can you post a screenshot?

JoelLefkowitz avatar Oct 27 '20 13:10 JoelLefkowitz