如何将标题信息放入swagger json [英] How to put header information in swagger json

查看:97
本文介绍了如何将标题信息放入swagger json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我点击了swagger文档中的以下链接,为我的rest api创建了swagger json.

I followed the following link from swagger documentation to create swagger json for my rest api.

https://swagger.io/docs/specification/2-0/describing-request-body/

在我的rest api中,我具有请求正文和与服务请求一起出现的HTTP标头,例如Content-Type和Authorization.

In my rest api, I have request body and http headers like Content-Type and Authorization that go along with the service request.

我想知道是否可以在swagger json中包含请求正文和http标头信息?我没能在庞大的文档中看到这些信息.

I was wondering if there is a way to include request body and http header information in the swagger json ? I don't see that information in the swagger docs.

推荐答案

请求和响应的 Content-Type 头由 consumps 定义,并且 produces关键字.可以在操作级别或规范的根级别上指定它们.

The Content-Type header of requests and responses is defined by the consumes and produces keywords, respectively. They can be specified on the operation level or on the root level of the spec.

Authorization 标头是使用 securityDefinitions security 关键字定义的.OpenAPI/Swagger 2.0支持基本身份验证,API密钥和OAuth 2.

The Authorization header is defined using the securityDefinitions and security keywords. OpenAPI/Swagger 2.0 supports Basic authentication, API keys and OAuth 2.

其他标头可以定义为 in:标头参数.

Other headers can be defined as in: header parameters.

例如,如果某个操作发布JSON并使用基本身份验证,则可以将其描述如下:

For example, if an operation POSTs JSON and uses Basic auth, you can describe it as follows:

swagger: '2.0'
...

securityDefinitions:   # Authorization, part 1
  basicAuth:
    type: basic

paths:
  /something:
    post:
      summary: POST some JSON
      consumes:
        - application/json  # Request Content-Type
      produces:
        - application/json  # Response Content-Type
      security:
        - basicAuth: []     # Authorization, part 2
      parameters:
        - in: body
          name: body
          required: true
          schema:
            $ref: '#/definitions/Something'
      responses:
        200:
          description: OK

相关文档:
MIME类型
身份验证
描述参数

这篇关于如何将标题信息放入swagger json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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