Swagger标题定义

yen*_*nox 4 swagger swagger-ui swagger-2.0

我似乎无法找到是否可以声明头对象以便在响应头中重用它,有一些示例为响应模式定义对象,但它不会转置到响应头.我只设法制作一个可重用的响应对象,如下所示:

responses:
  DownloadOk:
    description: Dowload Ok
    headers:
      Content-Length:
        description: response length
        type: integer 
      Document-Length:
        description: document length
        type: integer 
Run Code Online (Sandbox Code Playgroud)

但正如我所说,我只想保留标题部分.

这是我想要使用它的地方:

responses:
    200:
      description: Dowload Ok
      headers:
        $ref: '#/definitions/DowloadOk'
Run Code Online (Sandbox Code Playgroud)

com*_*tus 5

根据Swagger/OpenAPI规范你不能.定义必须包含Schema Objects,并且那些不允许任意属性,而是JSON Schema的特定子集(请参阅链接).

您可以定义响应对象并引用它,因为Swagger对象具有全局responses属性.标题没有这样的东西.反正不是在这个时候.要求这样的功能可能是值得的.