swagger-api / swagger-api/swagger-ui

filtering with multiple values not working

Open
#5,349 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
29k
Forks
9.3k
Avg merge
2d 23h
Merged PRs (30d)
25

Description

Hello,

I'm currently using Swagger with Django to test my data but the filter doesn't seem to work.
Indeed, i want to filter by the field 'number' which is an int and i'm using the parameter 'in'.

It seems like swagger doesn't recognize comma separators because it works with one value like 1 or 1.2 but not with 1,2 or 1,2,3.

1

2

It seems it is expecting int values so thats why it doesn't work with 1,2.

I'm pretty sure the problem is from Swagger because the filtering with multiple parameters works fine via url.

Here is the structure of my model:

class GSClass(models.Model):

  number = models.IntegerField(
      unique=True,
      help_text="number of the class."
      )

  heading = models.TextField(
     max_length=4092,
      help_text="heading of the class.")

Here is my view:

class ClassList(generics.ListCreateAPIView):

    queryset = GSClass.objects.all()
    serializer_class = GSClassSerializer
    permission_classes = [permissions.IsAuthenticatedOrReadOnly]
    filter_backends = [filters.SearchFilter, django_filters.rest_framework.DjangoFilterBackend]
    filterset_class = GSClassFilter
    search_fields = ['heading','note','terms__text']

    def perform_create(self, serializer):
        serializer.save(owner=self.request.user)

And my filter:

class GSClassFilter(rest_framework.FilterSet):

class Meta:
    model = GSClass
    fields = {
        'number':['in'],
    }

Thank you for your help.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No source file or test is named. Start by reproducing the Django filter case in Swagger UI and inspect the generated request for the number[in] parameter with one value versus comma-separated values. Done means the multi-value request matches the behavior that already works when called directly by URL.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.