drf-spectacular
drf-spectacular copied to clipboard
Allow to set the deprecated flag on filters
Describe the bug I cannot easily add the deprecated flag to a specific filter in a django-filter Filterset
Expected behavior
It would be nice if adding a deprecated=True extra kwarg to the filter would mark it as deprecated in the schema.
It would also be possible to use a decorator on the filter, but I currently do not have a working implementation for it.
Which one would be the prefered route?
class FooFilterSet(FilterSet):
# extra kwarg
bar = filters.CharFilter(field_name="bar", help_text=_("Filter on bar"), deprecated=True)
# decorator
@deprecated_filter
baz = filters.CharFilter(field_name="baz", help_text=_("Filter on baz"))
Hi! I get your point. There is no easy way to do this.
- extra_kwargs: the idea is good but it will fail with
Field.__init__() got an unexpected keyword argument 'deprecated'. This would require cooperation from the maintainer ofdjango-filteras the kwarg must be stripped theBaseFilter.__init__. If I had to guess, he will likely reject this proposal as it is a non-functional complication to the package. - decorator: your decorator example is invalid syntax but I see what you mean. We already allow
@extend_schema_fieldto wrap around filters. However, it is missing adeprecatedargument. We do have it indeprecate_fieldsin@extend_schema_serializerbut that is not applicable here.
The problem is that I don't want to broaden extend_schema_field as it would we also need to behave properly with non-django-filter usages. The django-filter case is merely a special case in a wider array of use cases.