drf-spectacular icon indicating copy to clipboard operation
drf-spectacular copied to clipboard

Allow to set the deprecated flag on filters

Open nils-van-zuijlen opened this issue 3 years ago • 1 comments

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"))

nils-van-zuijlen avatar Nov 14 '22 16:11 nils-van-zuijlen

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 of django-filter as the kwarg must be stripped the BaseFilter.__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_field to wrap around filters. However, it is missing a deprecated argument. We do have it in deprecate_fields in @extend_schema_serializer but 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.

tfranzel avatar Nov 14 '22 18:11 tfranzel