【发布时间】:2022-01-25 11:17:54
【问题描述】:
无法在请求中生成具有 multipart/form-data 内容类型的 swagger 文件
说明
我有一个上传文档的 POST 请求,我将在其中发送以 multipart/form-data 发送的文档。我试图这样描述表单数据这就是我的请求在邮递员中的样子
当我尝试生成一个 swagger 文件时。它给了我以下错误 drf_yasg.errors.SwaggerGenerationError:当请求有请求体时无法添加表单参数;您是否忘记在视图上设置适当的解析器类?
最小复制
@swagger_auto_schema(
operation_id='Create a document',
operation_description='Create a document by providing file and s3_key',
manual_parameters=[
openapi.Parameter('file', openapi.IN_FORM, type=openapi.TYPE_FILE, description='Document to be uploaded'),
openapi.Parameter('s3_key', openapi.IN_FORM, type=openapi.TYPE_STRING, description='S3 Key of the Document '
'(folders along with name)')
],
responses={
status.HTTP_200_OK: openapi.Response(
'Success', schema=openapi.Schema(type=openapi.TYPE_OBJECT, properties={
'doc_id': openapi.Schema(type=openapi.TYPE_STRING, description='Document ID'),
'mime_type': openapi.Schema(type=openapi.TYPE_STRING, description='Mime Type of the Document'),
'version_id': openapi.Schema(type=openapi.TYPE_STRING, description='S3 version ID of the document')
})
)
}
)
【问题讨论】:
标签: django-rest-framework swagger drf-yasg