You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a field serializer that has no fields (just defines to_internal_value), so any field that uses it will be missing from the schema. I'm trying to override this with @extend_schema_field but that's not working if the serializer is used with many=True.
To Reproduce
fromdrf_spectacular.typesimportOpenApiTypesfromdrf_spectacular.utilsimportextend_schema_fieldfromrest_frameworkimportserializers@extend_schema_field(OpenApiTypes.INT64)classRangeSerializer(serializers.Serializer):
defto_internal_value(self, data):
returndata# usually there is more happening hereclassModelSerializer(serializers.Serializer):
ranges=RangeSerializer(many=True)
Expected behavior
I expect the generated schema for ModelSerializer to be roughly this:
I looked at this a little bit with a debugger and was able to find that this is related to how the many=True causes drf to wrap the serializer in a ListSerializer which hides the override annotation. In _unwrap_list_serializer (source) the code is directly calling resolve_serializer directly instead of checking for overrides again.
The text was updated successfully, but these errors were encountered:
unfortunately the extend_schema_field decorator is not meant to be used on serializer. As the name suggests it is meant to be used with serializer fields. extend_schema_serializer, which would be the right decorator, does not allow this kind of manipulation.
I get this is a simplified example but are you not using a IntegerField instead of RangeSerializer?
Describe the bug
I have a field serializer that has no fields (just defines
to_internal_value
), so any field that uses it will be missing from the schema. I'm trying to override this with@extend_schema_field
but that's not working if the serializer is used withmany=True
.To Reproduce
Expected behavior
I expect the generated schema for
ModelSerializer
to be roughly this:this could be related to #694
I looked at this a little bit with a debugger and was able to find that this is related to how the
many=True
causes drf to wrap the serializer in aListSerializer
which hides the override annotation. In_unwrap_list_serializer
(source) the code is directly callingresolve_serializer
directly instead of checking for overrides again.The text was updated successfully, but these errors were encountered: