django-taggit-serializer icon indicating copy to clipboard operation
django-taggit-serializer copied to clipboard

tags display a string in swagger but in fact a list

Open ollie-zhang opened this issue 5 years ago • 6 comments

I use drf-yasg to create the swagger page,but it shows that tags filed is a string. And I tried to make a new filed by: class MyTagListSerializerField(TagListSerializerField, serializers.ListField): pass and it worked. So i think is the TagListSerializerField should Inherit from serializers.ListField but not serializers.Field will be better. Sure, it's just an immature idea. Waitting for your help!

ollie-zhang avatar Feb 20 '20 06:02 ollie-zhang

same problem

yswtrue avatar Jan 12 '21 16:01 yswtrue

same problem. Any solutions for this?

ysomad avatar May 15 '21 09:05 ysomad

same problem.

ndjman7 avatar Apr 13 '22 07:04 ndjman7

The problem is still there. We reproduced it using drf-spectacular.

cezar77 avatar Oct 12 '22 13:10 cezar77

Same here. We should probably write a OpenApiSerializerFieldExtension or a OpenApiSerializerExtension, see drf-spectacular docs but I have no idea how.

onekiloparsec avatar Oct 16 '22 09:10 onekiloparsec

This worked for me:

from drf_spectacular.extensions import OpenApiSerializerFieldExtension
from drf_spectacular.openapi import AutoSchema
from drf_spectacular.plumbing import build_array_type, build_basic_type  # type: ignore
from drf_spectacular.types import OpenApiTypes
from drf_spectacular.utils import Direction


class TagListSerializerFieldFix(OpenApiSerializerFieldExtension):
    target_class = "taggit.serializers.TagListSerializerField"

    def map_serializer_field(self, auto_schema: AutoSchema, direction: Direction):

        return build_array_type(build_basic_type(OpenApiTypes.STR))

@tfranzel suggests here that this can be also achieved with a ListField – which wouldn't require us to ignore types – but I couldn't figure it out

janrito avatar Oct 27 '22 13:10 janrito