By default, django rest swagger doesn’t displayed the Serializer in DELETE method. But, for some reason I need to implement prevent deletion & force deletion case.

So, basicly to implement it, we need to add e.g this example inside the request body:

  "forceDelete": true

I’m trying to update the serializer inside get_serializer_class function, but it still doesn’t work properly.

class ForceDeleteSerializer(serializers.Serializer):
    force_delete = serializers.BooleanField(default=False)

class GroupViewSet(ModelViewSet):
    permission_classes = (IsOrganizationAdmin,)
    serializer_class = GroupSerializer
    search_fields = ('display_name',)

    def get_serializer_class(self):
        if self.action == 'destroy':
            return ForceDeleteSerializer
        return self.serializer_class

delete action

Finally, as suggested by @LinhNguyen to use drf-yasg, and using swagger_auto_schema it worked.

from drf_yasg.utils import swagger_auto_schema

def destroy(self, request, *args, **kwargs):


146 7 7 0