oxan / djangorestframework-dataclasses

Dataclasses serializer for Django REST framework
BSD 3-Clause "New" or "Revised" License
431 stars 28 forks source link

Support union field #76

Closed panchock closed 1 year ago

panchock commented 1 year ago

Resolves #63

oxan commented 1 year ago

I've decided to implement union type support using a homegrown UnionField (#82) instead of a solution based on this PR/django-rest-polymorphic. The main reason for that is that such a field turns out to be less code than the InlinePolymorphicSerializer needed here to fixup the mismatch with django-rest-polymorphic assumptions, while also being more flexible (it supports e.g. unions of primitives). It also avoids the dependency.

panchock commented 1 year ago

I've decided to implement union type support using a homegrown UnionField (#82) instead of a solution based on this PR/django-rest-polymorphic. The main reason for that is that such a field turns out to be less code than the InlinePolymorphicSerializer needed here to fixup the mismatch with django-rest-polymorphic assumptions, while also being more flexible (it supports e.g. unions of primitives). It also avoids the dependency.

@oxan This solution also supports drf spectacular? What will happens if someone will try to generate openapi schema now?

oxan commented 1 year ago

I don't know, I haven't tested it as I don't use drf-spectacular. However, if it doesn't work, the best way to fix it would be by extending drf-spectactular's rest_framework_dataclasses plugin.