如何描述使用的OpenAPI(扬鞭)一个多反应?

Vis*_*lPi 3 multipart swagger openapi

我有一个创建包含以下内容的多部分文件的服务:

  • 代表图像缓冲区的数据字节数组
  • 一个JSON表示关于图像(坐标,格式等)的信息

是否有可能使用YAML在提供的OpenAPI(扬鞭)定义这个自定义响应模型,?

Hel*_*len 6

可以使用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:
                  ... 
Run Code Online (Sandbox Code Playgroud)

可选encoding键可用于覆盖Content-Typefor子部件或添加子部件的标题(例如Content-Disposition)。