diff --git a/django_filters/rest_framework/backends.py b/django_filters/rest_framework/backends.py index 835a67f9a..5ec8f735f 100644 --- a/django_filters/rest_framework/backends.py +++ b/django_filters/rest_framework/backends.py @@ -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): @@ -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 = { @@ -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: