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

Primary key is not detected as GET parameter

Open yspreen opened this issue 5 years ago • 2 comments

This is the output: image

these are the URLS:

    path('items/<int:pk>/', ItemDetail.as_view()),
    path('items/<int:pk>/set_rating/', ItemRating.as_view()),

ItemDetail uses the GenericAPIView as a base class, with a ModelSerializer as serializer_class. Here swagger detects that the pk param inside the URL is a UUID.
For ItemRating, I added get_serializer manually, and it returns

        class MySerializer(serializers.Serializer):
            pk = serializers.UUIDField(format='hex_verbose', read_only=True)
            rating = serializers.IntegerField()

        return MySerializer()

Is there any way to tell swagger that pk is a UUID primary key for the object in the GET parameter?

(I tried pk, id and uuid as field names for the ItemRating view. No change)

yspreen avatar Nov 06 '18 22:11 yspreen

Hey, I am facing the same issue. The only difference is my URL has string and swagger asks me to input int. @y-spreen How could you resolve this?

ShubhankarKapoor avatar Apr 03 '19 01:04 ShubhankarKapoor

@ShubhankarKapoor I think I ended up just using the Model Serializer at all times. Simply for the url param, without any additional fields used.

yspreen avatar Apr 16 '19 08:04 yspreen