Describe the bug
When the schema for a view using the PolymorphicSerializer from django-rest-polymorphic is generated, it uses the serializer's resource_type_field_name for the discriminator but the property under the same name is not added to the components generated from the sub-serializers.
This causes it to not be included in the schema in swagger/redoc and a mismatch between what the api expects.
To Reproduce
run generation on
from django.db import models
from polymorphic.models import PolymorphicModel
from rest_framework.generics import CreateAPIView
from rest_framework.serializers import ModelSerializer
from rest_polymorphic.serializers import PolymorphicSerializer
class ExampleModel(PolymorphicModel):
...
class SubModel1(ExampleModel):
field1 = models.CharField()
class SubModel2(ExampleModel):
field2 = models.CharField()
class SubModel1Serializer(ModelSerializer):
class Meta:
model = SubModel1
exclude = ("polymorphic_ctype",)
class SubModel2Serializer(ModelSerializer):
class Meta:
model = SubModel2
exclude = ("polymorphic_ctype",)
class ExampleModelSerializer(PolymorphicSerializer):
model_serializer_mapping = {
SubModel1: SubModel1Serializer,
SubModel2: SubModel2Serializer,
}
class ExampleView(CreateAPIView):
queryset = ExampleModel.objects.all()
serializer_class = ExampleModelSerializer
Expected behavior
string property under the same name as resource_type_field_name added to components generator for polymorphic serializer so tooling picks it up
Describe the bug
When the schema for a view using the PolymorphicSerializer from django-rest-polymorphic is generated, it uses the serializer's
resource_type_field_namefor the discriminator but the property under the same name is not added to the components generated from the sub-serializers.This causes it to not be included in the schema in swagger/redoc and a mismatch between what the api expects.
To Reproduce
run generation on
Expected behavior
string property under the same name as
resource_type_field_nameadded to components generator for polymorphic serializer so tooling picks it up