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

problem with many=True and multipart/form-data #1308

Open
hihello1123 opened this issue Oct 7, 2024 · 2 comments
Open

problem with many=True and multipart/form-data #1308

hihello1123 opened this issue Oct 7, 2024 · 2 comments

Comments

@hihello1123
Copy link

hihello1123 commented Oct 7, 2024

views.py

import json
from rest_framework.response import Response
from rest_framework.views import APIView
from drf_spectacular.utils import extend_schema
from test_app.serializer import *
class test_answer(APIView):
    @extend_schema(
        request={
            # "application/json": req_Serializer,
            "multipart/form-data": req_Serializer,
        },
        responses={"200": OK_response(), "400": ERROR_response()},
    )
    def post(self, req):
        data_list = req.data.get("list")
        post_list = req.POST.get("list")
        print("data ", data_list)
        print("post ", post_list)
        return Response({"message": "hi"})

serializer.py

from rest_framework import serializers

class item(serializers.Serializer):
    txt = serializers.CharField()

class req_Serializer(serializers.Serializer):
    list = item(many=True)

class OK_response(serializers.Serializer):
    status = serializers.IntegerField(default=200)

class ERROR_response(serializers.Serializer):
    status = serializers.IntegerField(default=400)

with these code i expected 2 item() objects in a list
like below:

list = [
    { "txt":"asdf"},{ "txt","qwer"}
]

But swagger-ui makes below:

'list=[{"txt":"asdf"},"{\n  \"txt\": \"qwer\"\n}"]'

image

how can i make it right?

@johnthagen
Copy link
Contributor

johnthagen commented Oct 16, 2024

FYI, if you wrap you code blocks with

```py

They will syntax highlight and make it easier for the maintainer to read.

@hihello1123
Copy link
Author

@johnthagen thx for letting me know.
I'm sorry that i'm not familiar with making a issue, Because this was my first Issue.
Thank you again to let me know

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

2 participants