Skip to content

Commit

Permalink
Merge pull request #1011 from tfranzel/smart_list_serializer_check
Browse files Browse the repository at this point in the history
selectively distinguish real serializers from mocked ones #1006
  • Loading branch information
tfranzel authored Jun 20, 2023
2 parents ae52f23 + 5fe55a1 commit e768e5e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drf_spectacular/plumbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def force_instance(serializer_or_field):
return serializer_or_field


def is_serializer(obj) -> bool:
def is_serializer(obj, strict=False) -> bool:
from drf_spectacular.serializers import OpenApiSerializerExtension
return (
isinstance(force_instance(obj), serializers.BaseSerializer)
or bool(OpenApiSerializerExtension.get_match(obj))
or (bool(OpenApiSerializerExtension.get_match(obj)) and not strict)
)


Expand All @@ -119,7 +119,7 @@ def get_list_serializer(obj):

def is_list_serializer_customized(obj) -> bool:
return (
is_serializer(obj)
is_serializer(obj, strict=True)
and get_class(get_list_serializer(obj)).to_representation # type: ignore
is not serializers.ListSerializer.to_representation
)
Expand Down

0 comments on commit e768e5e

Please sign in to comment.