[英]Django rest framework drf-yasg swagger multiple file upload error for ListField serializer
I am trying to make upload file input from swagger (with drf-yasg
), but when I use MultiPartParser
class it gives me the below error:我正在尝试从swagger (使用
drf-yasg
)输入上传文件,但是当我使用MultiPartParser
class 时,出现以下错误:
drf_yasg.errors.SwaggerGenerationError: FileField is supported only in a formData Parameter or response Schema
My view:我的看法:
class AddExperience(generics.CreateAPIView):
parser_classes = [MultiPartParser]
permission_classes = [IsAuthenticated]
serializer_class = DoctorExperienceSerializer
My serializer:我的序列化器:
class DoctorExperienceSerializer(serializers.Serializer):
diploma = serializers.ListField(
child=serializers.FileField(allow_empty_file=False)
)
education = serializers.CharField(max_length=1000)
work_experience = serializers.CharField(max_length=1000)
I also tried FormParser
but it still gives me the same error.我也试过
FormParser
但它仍然给我同样的错误。 Also: FileUploadParser
parser but it works like JsonParser
:另外:
FileUploadParser
解析器,但它的工作方式类似于JsonParser
:
The OpenAPISchema
( OAS
) 2 doesn't support the multiple file upload (see issue #254 ); OpenAPISchema
( OAS
) 2 不支持多文件上传(参见 issue #254 ); but OAS 3
supports it (you can use this YML spec on a live swagger editer ( see this result )).但
OAS 3
支持它(您可以在实时 swagger 编辑器上使用此 YML 规范(参见此结果))。
Comes to the real issue, there is a section in the drf-yasg's doc ,谈到真正的问题, drf-yasg 的文档中有一节,
If you are looking to add Swagger/OpenAPI support to a new project you might want to take a look at drf-spectacular, which is an actively maintained new library that shares most of the goals of this project, while working with OpenAPI 3.0 schemas.
如果您希望将 Swagger/OpenAPI 支持添加到新项目,您可能想看看 drf-spectacular,这是一个积极维护的新库,它共享该项目的大部分目标,同时使用 OpenAPI 3.0 模式。
OpenAPI 3.0 provides a lot more flexibility than 2.0 in the types of API that can be described.
OpenAPI 3.0 在可描述的 API 类型上提供了比 2.0 更大的灵活性。 drf-yasg is unlikely to soon, if ever, get support for OpenAPI 3.0.
drf-yasg 不太可能很快(如果有的话)获得对 OpenAPI 3.0 的支持。
That means the package drf-yasg
doesn't have support for OAS3
and thus, it won't support the "multiple file upload" feature.这意味着 package
drf-yasg
不支持OAS3
,因此,它不支持“多文件上传”功能。
You can consider migrating from drf-yasg
to drf-spectacular
.您可以考虑从
drf-yasg
迁移到drf-spectacular
。 But, also note that, drf-spectacular
is also dealing the FileUpload in a different way .但是,还要注意,
drf-spectacular
也以不同的方式处理 FileUpload。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.