django-taggit-serializer
django-taggit-serializer copied to clipboard
tags display a string in swagger but in fact a list
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!
same problem
same problem. Any solutions for this?
same problem.
The problem is still there. We reproduced it using drf-spectacular.
Same here. We should probably write a OpenApiSerializerFieldExtension
or a OpenApiSerializerExtension
, see drf-spectacular docs but I have no idea how.
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