Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

drf-spectacular not recognizing file upload #1285

Open
peterkronenberg opened this issue Sep 4, 2024 · 0 comments
Open

drf-spectacular not recognizing file upload #1285

peterkronenberg opened this issue Sep 4, 2024 · 0 comments

Comments

@peterkronenberg
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant