Open golgor opened 1 month ago
Hi, serializer explosion was added as a convenience feature. Never tought many people would use it. It was never meant to be used indirectly through serializer extensions for other classes like pydantic. However, it turns out not that much was actually missing to make it work.
Keep in mind this is a shortcut of a shortcut and the schema might not be 100%, so give it a sanity check first.
@tfranzel Awesome, thanks a lot for looking into this.
Describe the bug I can get both responses and requests to work fine using pydantic by simply using a pydantic BaseModel instead of a
rest_framework.serializers.Serializer
. However, when I try to do the same for Parameters in a GET-function it doesn't work. I have tried many ways, but either there is no result showing it the Schema generation fails.I'm currently using:
To Reproduce Working good:
But if I change from
QueryParamsSerializer
toQueryParams
, I first of all get a type error and it is not possible to generate any schema when I try to open up theSpectacularAPIView.as_view()
orSpectacularSwaggerView.as_view()
.I can use the same pydantic class as a response serializer, but not for parameters.
If I try to use a POST-function everything works fine as well.
I have also tried to search the documentation about this and also for issues here in the Github repo, as well as extensively trying to interrogate various AI resources and searching on Google.
To be honest, I don't know if this is a bug or if I am doing it wrong, but I honestly feel a bit lost here on how to do in that case. Can anyone please advise?
Expected behavior That using a pydantic model for query parameters generate the correct schema and swagger view as using a
rest_framework.serializers.Serializer
.