Sunday, 30 September 2018

how to configure swagger UI to allow user to entry multiple values for query string parameter

I am using django-rest-swagger==2.1.2 and djangorestframework==3.7.7 and I have a view that looks like this:

class PendingRequests(generics.GenericAPIView):
    ...
    filter_backends = (PendingRequestsFilter,)

    def get(self, request):
        ...
        request_status = request.GET.getlist('status')
        request_start_date = request.GET.get('start_date')
        request_end_date = request.GET.get('end_date')
        ...

and I have defined a filter like so:

class PendingRequestsFilter(BaseFilterBackend):
    def get_schema_fields(self, view):
        fields = [
            coreapi.Field(name="status", description="Statuses of the Requests", required=False, location='query', example='active'),
            coreapi.Field(name="status", description="Statuses of the Requests", required=False, location='query', example='pending'),
            coreapi.Field(name="status", description="Statuses of the Requests", required=False, location='query', example='inactive'),
            coreapi.Field(name="start_date", description="Start Date of the Request (YYYY-MM-DD)", required=False, location='query', example='2525-12-25'),
            coreapi.Field(name="end_date", description="End Date of the Request (YYYY-MM-DD)", required=False, location='query', example='2525-12-26'),
        ]
        return fields

This results in my swagger UI for this view looking like this:

enter image description here

But when I enter different status like so ...

enter image description here

... and click 'try it out' I get a Request URL that looks like this:

http://myserver:4800/api/v1/sudorequests/requests/?status=pending&status=pending&status=pending

Note that status=pending is repeated three times. I wanted to get a Request URL that looks more like this:

http://myserver:4800/api/v1/sudorequests/requests/?status=inactive&status=active&status=pending



from how to configure swagger UI to allow user to entry multiple values for query string parameter

No comments:

Post a Comment