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

Respect to non-string filter types while output OpenAPI parameters #1306

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion django_filters/rest_framework/backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
from .. import compat, utils
from . import filters, filterset

_FILTERS_OPANAPI_TYPE_MAP = {
filters.CharFilter: 'string',
filters.BooleanFilter: 'boolean',
filters.NumberFilter: 'number',
}


# TODO: remove metaclass in 2.1
class RenameAttributes(utils.RenameAttributesBase, RenameMethodsBase):
Expand Down Expand Up @@ -153,6 +159,12 @@ def get_schema_operation_parameters(self, view):
if not filterset_class:
return []

def get_filter_openapi_type(filter):
for filter_type, openapi_type in _FILTERS_OPANAPI_TYPE_MAP.items():
if isinstance(filter, filter_type):
return openapi_type
return 'string'

parameters = []
for field_name, field in filterset_class.base_filters.items():
parameter = {
Expand All @@ -161,7 +173,7 @@ def get_schema_operation_parameters(self, view):
'in': 'query',
'description': field.label if field.label is not None else field_name,
'schema': {
'type': 'string',
'type': get_filter_openapi_type(field),
},
}
if field.extra and 'choices' in field.extra:
Expand Down