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

Swagger Schema Generation generates the wrong fields for gets

Open efagerberg opened this issue 6 years ago • 0 comments

Full disclosure I am seeing this using a filterset from djangorestframework-filters

I noticed when setting up a filter with all lookup fields on a viewset that all the filters end up in the get method. These filters are most likely useless for gets and should not be included as parameters.

class Person(filters.FilterSet):

    class Meta:
        model = Node
        fields = {
            'id': '__all__',
            'name': '__all__',
        }

A serializer like this

class PersonSerializer(serializers.ModelSerializer):
    class Meta:
        model = Person
        fields = ('id', 'name')

and finally a viewset like this

class PersonViewSet(viewsets.ReadOnlyModelViewSet):

    queryset = Person.objects.all()
    serializer_class = PersonSerializer
    filter_class = PersonFilter

If I register this to my urls I would get a route for a list view and a get similar to this api/person/ and api/person/{id}

And if I go to say swagger and check the get Person API out I would notice that I have filter options for the get like this screenshot. screen shot 2018-03-28 at 11 48 44 am

The issue here is, get requires an id and you usually do not need more than that, so these filter options are superfluous.

efagerberg avatar Mar 29 '18 02:03 efagerberg