将
multipart/form-data
用作将请求主体传输到操作的
Content-Type
很常见。与2.0相比,当使用
multipart
内容时,
REQUIRED
使用
schema
来定义操作的输入参数。这支持复杂结构以及支持多种文件上传的机制。
在传递
multipart
类型时,可以使用边界
MAY
来分隔正在传输的内容部分——因此,为
multipart
定义了以下默认
Content-Type
如果属性是原始类型,或原始值的数组,则默认 Content-Type 为
text/plain
如果属性是复杂类型,或复杂值的数组,则默认 Content-Type 为
application/json
如果属性是
type: string
且
format: binary
或
format: base64
(也称为文件对象),则默认 Content-Type 为
application/octet-stream
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
type: string
format: uuid
address:
# default Content-Type for objects is `application/json`
type: object
properties: {}
profileImage:
# default Content-Type for string/binary is `application/octet-stream`
type: string
format: binary
children:
# default Content-Type for arrays is based on the `inner` type (text/plain here)
type: array
items:
type: string
addresses:
# default Content-Type for arrays is based on the `inner` type (object shown, so `application/json` in this example)
type: array
items:
type: '#/components/schemas/Address'
引入了一个encoding属性,用于控制multipart请求主体部分的序列化。此属性仅适用于multipart和application/x-www-form-urlencoded请求主体。