示例#1
0
    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)
示例#2
0
    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
示例#3
0
    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
示例#4
0
def is_serializer(obj) -> bool:
    from drf_spectacular.serializers import OpenApiSerializerExtension
    return (isinstance(force_instance(obj), serializers.BaseSerializer)
            or bool(OpenApiSerializerExtension.get_match(obj)))