def _map_serializer(self, method, serializer): serializer = force_instance(serializer) serializer_extension = OpenApiSerializerExtension.get_match(serializer) if serializer_extension: return serializer_extension.map_serializer(self, method) else: return self._map_basic_serializer(method, serializer)
def _get_serializer_name(self, method, serializer): serializer_extension = OpenApiSerializerExtension.get_match(serializer) if serializer_extension and serializer_extension.get_name(): return serializer_extension.get_name() name = serializer.__class__.__name__ if name.endswith('Serializer'): name = name[:-10] if method == 'PATCH' and not serializer.read_only: # TODO maybe even use serializer.partial name = 'Patched' + name return name
def _get_serializer_name(self, serializer, direction): serializer_extension = OpenApiSerializerExtension.get_match(serializer) if serializer_extension and serializer_extension.get_name(): return serializer_extension.get_name() name = serializer.__class__.__name__ if name.endswith('Serializer'): name = name[:-10] if self.method == 'PATCH' and not serializer.read_only and direction == 'request': name = 'Patched' + name return name
def is_serializer(obj) -> bool: from drf_spectacular.serializers import OpenApiSerializerExtension return (isinstance(force_instance(obj), serializers.BaseSerializer) or bool(OpenApiSerializerExtension.get_match(obj)))