Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

selectively distinguish real serializers from mocked ones #1006 #1011

Merged
merged 1 commit into from
Jun 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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