我有一个服务,该服务创建一个包含:
的多部分文件- 代表图像缓冲区的数据字节数组
- 表示有关图像(坐标,格式等)的信息的JSON
使用yaml?
可以使用OpenAPI 3.0来描述多部分响应,而不是OpenAPI 2.0(FKA Swagger 2.0)。
openapi: 3.0.0
...
paths:
/something:
get:
responses:
'200':
description: OK
content:
multipart/mixed: # <-- Content-Type of the response
schema:
type: object
properties:
# Part 1 - application/octet-stream
file: # <-- part name
type: string
format: binary
# Part 2 - application/json
metadata: # <-- part name
type: object
properties:
foo:
type: string
example: bar
required:
- foo
# Optional, see https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#encoding-object
encoding:
file:
...
metadata:
...
可选的encoding
键可用于覆盖子部分的Content-Type
或为子部分添加标头(例如Content-Disposition
)。