Skip to content

Commit

Permalink
Merge branch 'pr951'
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzel committed Mar 1, 2023
2 parents eeb8a11 + 71038e9 commit 15012d9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion drf_spectacular/contrib/django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def resolve_filter_field(self, auto_schema, model, filterset_class, field_name,
schema = build_basic_type(annotation)
else:
# allow injecting raw schema via @extend_schema_field decorator
schema = annotation
schema = annotation.copy()
elif filter_method_hint is not _NoHint:
if is_basic_type(filter_method_hint):
schema = build_basic_type(filter_method_hint)
Expand Down
34 changes: 34 additions & 0 deletions tests/contrib/test_django_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,3 +343,37 @@ def retrieve(self, request, *args, **kwargs):
'explode': False,
'style': 'form'
}


@pytest.mark.contrib('django_filter')
def test_filters_raw_schema_decoration_isolation(no_warnings):
from django_filters import FilterSet
from django_filters.rest_framework import DjangoFilterBackend

class SimpleFilterSet(FilterSet):
filter_field = NumberFilter(method='filter_method')

@extend_schema_field({'description': 'raw schema', 'type': 'integer'})
def filter_method(self, queryset, name, value):
pass # pragma: no cover

class Meta:
model = Product
fields = []

class XViewset(viewsets.GenericViewSet):
queryset = Product.objects.all()
serializer_class = SimpleSerializer
filterset_class = SimpleFilterSet
filter_backends = [DjangoFilterBackend]

def list(self, request, *args, **kwargs):
pass # pragma: no cover

expected = [
{'in': 'query', 'name': 'filter_field', 'schema': {'type': 'integer'}, 'description': 'raw schema'}
]
schema = generate_schema('/x', XViewset)
assert schema['paths']['/x/']['get']['parameters'] == expected
schema = generate_schema('/x', XViewset)
assert schema['paths']['/x/']['get']['parameters'] == expected

0 comments on commit 15012d9

Please sign in to comment.