Drf-spectacular not recognizing file upload type

I have a Django endpoint that takes a file upload

My annotations look like this


@extend_schema(
    request=UploadObservationalSerializer,
    responses={
        200: GenericResponseSerializer,
        400: OpenApiResponse(
            response=ErrorResponseSerializer,
            description="Validation error or parsing error"
        ),
        500: ErrorResponseSerializer
    },
    description="Allow user to upload observational data"
)

Here is my serializer:

class UploadObservationalSerializer(BaseSerializer):
    calibration_run_id = serializers.IntegerField(required=True)
    observational_user_file_path = serializers.CharField(required=True)
    observational_file = serializers.FileField(required=True)

    def validate_observational_file(self, value):
        request = self.context.get('request')
        files = request.FILES.getlist('observational_file')
        if len(files) != 1:
            raise serializers.ValidationError("Only one observational file should be uploaded.")
        return value

But in the Swagger, drf-spectacular lists observational_file as a String, not a File Field

{
  "calibration_run_id": 0,
  "observational_user_file_path": "string",
  "observational_file": "string"
}

Why is drf-spectacular not recognizing the file field?

Back to Top