Skip to content
This repository has been archived by the owner on May 10, 2023. It is now read-only.

tags display a string in swagger but in fact a list #47

Open
ollie-zhang opened this issue Feb 20, 2020 · 6 comments
Open

tags display a string in swagger but in fact a list #47

ollie-zhang opened this issue Feb 20, 2020 · 6 comments

Comments

@ollie-zhang
Copy link

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!

@yswtrue
Copy link

yswtrue commented Jan 12, 2021

same problem

@ysomad
Copy link

ysomad commented May 15, 2021

same problem. Any solutions for this?

@ndjman7
Copy link

ndjman7 commented Apr 13, 2022

same problem.

@cezar77
Copy link

cezar77 commented Oct 12, 2022

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

@onekiloparsec
Copy link

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

@janrito
Copy link

janrito commented Oct 27, 2022

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants