django-rest-swagger
django-rest-swagger copied to clipboard
Swagger Schema Generation generates the wrong fields for gets
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.
The issue here is, get requires an id and you usually do not need more than that, so these filter options are superfluous.