Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Choice fields don't generate the proper schema #1297

Closed
SafaAlfulaij opened this issue Nov 28, 2020 · 2 comments
Closed

Multiple Choice fields don't generate the proper schema #1297

SafaAlfulaij opened this issue Nov 28, 2020 · 2 comments

Comments

@SafaAlfulaij
Copy link

SafaAlfulaij commented Nov 28, 2020

FilterSet

class ObjectsFilterSet(FilterSet):
    type = MultipleChoiceFilter(
        field_name='type',
        label='Type of object',
        choices=(
            ('A', 'A'),
            ('B', 'B'),
            ('C', 'C')
        ),
    )

Current result

      - name: type
        required: false
        in: query
        description: Type of object
        schema:
          type: string
          enum:
            - A
            - B
            - C

Expected result

      - name: type
        required: false
        in: query
        description: Type of object
        schema:
          type: array
          items:
            type: string
            enum:
            - A
            - B
            - C

Proposed solution

Fix https://github.com/carltongibson/django-filter/blob/master/django_filters/rest_framework/backends.py#L168:

            if field.extra and 'choices' in field.extra:
                parameter['schema']['enum'] = [c[0] for c in field.extra['choices']]

            if isinstance(field, (MultipleChoiceFilter, ModelMultipleChoiceFilter)):
                parameter['schema'] = {
                    'type': 'array',
                    'items': parameter['schema']
                }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants