Swagger 发送 body 和 formData 参数 [英] Swagger send body and formData parameter
问题描述
我使用的是 Swagger 2.0,但在发送多个 post 参数时遇到问题.我有一个招摇的错误 Operation cannot have a body parameter and a formData parameter
我不知道如何解决它.在我的定义中,我有一个 body 参数,这个参数需要 JSON 格式,但另一方面我还有其他参数,比如要上传的文件和文件名.
I'm using Swagger 2.0 and I have a problem to send multiple post parameters. I have a swagger error Operation cannot have a body parameter and a formData parameter
and I don't know how to fix it. In my definition I have a body parameter and this parameter need a JSON format but a side I have other parameter like files to upload and filename.
如何同时发送 body 和 formData 参数?
How can I do to send body and formData parameters both ?
这是网络服务定义:
/updateDatas:
post:
summary: Upadate datas
description: |
Update datas
consumes:
- multipart/form-data
produces:
- application/json
parameters:
- name: firstFileName
in: formData
description: First file name.
required: true
type: string
- name: secondFileName
in: formData
description: Second file name.
required: true
type: string
- name: datas
in: body
description: Json object informations.
required: true
schema:
$ref: '#/definitions/Datas'
- name: firstFile
in: formData
description: First file .jpg
required: true
type: file
- name: clientFile
in: formData
description: Second file .jpg
required: true
type: file
tags:
- Application
responses:
'200':
description: Uploaded
schema:
$ref: '#/definitions/Upload'
'401':
description: Unauthorized Bad Token
推荐答案
根据swagger规范see, type:body
和 type:formData
不能同时存在于同一个操作中.
According to the swagger specifications see, type:body
and type:formData
cannot exist together for the same operation.
这篇关于Swagger 发送 body 和 formData 参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!