I am using the drf-spectacular
library together with Swagger-UI to document my Django Rest serializers (schemas).
What I have noticed is that if I set the read_only=True
or allow_null=True
attribute of any nested serializer fields, the name of that nested serializer disappears from the schema view in Swagger-UI. If I remove those attributes or set them to False
, the names re-appear. Not sure why this is happening?
class MySerializerSerializer(serializers.ModelSerializer):
read_only_field = MyReadOnlySerializerSerializer(read_only=True) #--> 'MyReadOnlySerializer' name is not shown
null_field = MyNullSerializerSerializer(read_only=False, allow_null=True) #--> 'MyNullSerializer' name is not shown
normal_field = MyOtherSerializerSerializer(read_only=False) #--> 'MyOtherSerializer" name is shown