Swagger 标头定义 [英] Swagger header definitions

查看:40
本文介绍了Swagger 标头定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I can't seem to find if it is possible to declare a header object in order to reuse it in response headers, there are examples defining objects for response schemas, but it doesn't transpose to response headers. I have only managed to make a reusable response object like this:

responses:
  DownloadOk:
    description: Dowload Ok
    headers:
      Content-Length:
        description: response length
        type: integer 
      Document-Length:
        description: document length
        type: integer 

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

But as I said, I'd like to keep the header part only.

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

Here is where I would like to use it:

responses:
    200:
      description: Dowload Ok
      headers:
        $ref: '#/definitions/DowloadOk'

推荐答案

根据 Swagger/OpenAPI 规范,您不能.Definitions 必须包含 架构对象,并且不允许任意属性,而是 JSON 架构的特定子集(请参阅 链接).

According to Swagger/OpenAPI spec you can't. Definitions must contain Schema Objects, and those do not allow arbitrary properties, but specific subset of JSON Schema (see the link).

您可以定义一个响应对象并引用它,因为Swagger Object 具有全局 responses 属性.标题没有这样的事情.反正不是这个时候.请求此类功能可能是值得的.

You were able to define a Response Object and reference that, because the Swagger Object has global responses property. No such thing for headers. Not at this time, anyway. It could be worth to request such feature.

这篇关于Swagger 标头定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆