django-rest-swagger icon indicating copy to clipboard operation
django-rest-swagger copied to clipboard

How to specify POST/PUT parameters in v2

Open yspreen opened this issue 5 years ago • 4 comments

Using generic api views works fine, the parameters are recognized from the serializer.

But what about views that don't have a serializer? What if I want to give a rating to an item for example.
It will be something like

curl -X PUT "/api/items/6/rate" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"rating\": 4}"

How do I specify this with django rest swagger? The docs don't help with this usecase, and old docs for v0.3 are not working anymore.

class RatingView(views.APIView):
    def put(self, request, pk, format=None):
        """
        Your docs
        ---
        parameters:
            - name: foobar
            description: test
            required: true
            type: integer
            paramType: query
        """
        item = self.get_object(pk)
        Ratings.rate(item, request.data.get("rating", 0))
        return Response("ok")

The parameter does not show up.

yspreen avatar Nov 06 '18 22:11 yspreen

I found an ugly workaround, but surely there is a better way:

  def get_serializer(*_, **__):
       class MySerializer(serializers.Serializer):
           rating = serializers.IntegerField()

       return MySerializer()

yspreen avatar Nov 06 '18 22:11 yspreen

use coreapi

class S2ViewList(GenericAPIView):#

serializer_class = S2createSerializer #



schema = AutoSchema (

manual_fields=[

coreapi.Field (name='vxnet',required=False,location='query',description='',type='string'),

coreapi.Field (name='service_type',required=False,location='query',description='',

type='string'),

]

) image

Doctor-DC avatar Nov 14 '18 08:11 Doctor-DC

I found this in stackoverflow, and I hope it helps you.

https://stackoverflow.com/questions/38542690/django-rest-framework-swagger-2-0

wdschn avatar Nov 15 '18 03:11 wdschn

image image i tried many way to solve this problem , now here is the solution

Jazzy818 avatar Jan 11 '19 03:01 Jazzy818