OpenAPI 规范 2.0
在 Swagger 2.0 ( OpenAPI Specification 2.0 ) 中,使用设置为file的表单参数 ( in: formData
) 。此外,操作必须是.type
consumes
multipart/form-data
consumes:
- multipart/form-data
parameters:
- name: file
in: formData # <-----
description: The uploaded file data
required: true
type: file # <-----
OpenAPI 规范 3.0
在OpenAPI 规范 3.0中,文件被定义为二进制字符串,即type: string
+ format: binary
(或format: byte
,取决于用例)。文件输入/输出内容的描述与任何其他模式类型的语义相同(与 OpenAPI 2.0 不同):
多部分请求,单个文件:
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
# 'file' will be the field name in this multipart request
file:
type: string
format: binary
多部分请求,文件数组(在 Swagger UI 3.26.0+ 和 Swagger Editor 3.10.0+ 中支持):
requestBody:
content:
multipart/form-data:
schema:
type: object
properties:
# The property name 'file' will be used for all files.
file:
type: array
items:
type: string
format: binary
直接 POST/PUT 文件(请求正文是文件内容):
requestBody:
content:
application/octet-stream:
# any media type is accepted, functionally equivalent to `*/*`
schema:
# a binary file of any type
type: string
format: binary
注意:语义与其他 OpenAPI 3.0 模式类型相同:
# content transferred in binary (octet-stream):
schema:
type: string
format: binary
更多信息: