使用正文

时间:2016-06-10 14:15:46

标签: swagger

我正在使用Ruby on Rails为客户端构建Rest API并尝试使用SwaggerHub来记录它。

我想知道如何使用BODY中的正确参数记录后期操作。到目前为止,我已经创建了操作,需要为我的开发人员描述以下参数。

{"user": {"email":"999999@gmail.com", "password":"12345678", "password_confirmation":"12345678"}}

我已经开始使用这个作为我的帖子了:

 "post": {
  "description": "Creates a user",
  "produces": [
    "application/json"
  ],
  "consumes": [
    "application/json"
    ],
  "responses": {
    "201": {
      "description": "Creates an instance of User",
    },
    "422": {
      "description": "Bad syntax, user not created"
    }
  }
}

使用参数"很容易记录。在PATH中,如Get或Delete操作,其中包含像这样的参数中的用户ID

 "delete": {
  "description": "Destroy a user",
  "produces": [
    "application/json"
  ],
  "consumes": [
    "application/json"
    ],
  "responses": {
    "200": {
      "description": "destory a single user",
    },
    "404": {
      "description": "user not found"
    }
  }
},
  "parameters": [
  {
    "name": "id",
    "in": "path",
    "description": "ID of user to use for action",
    "required": true,
    "type": "array",
    "items": {
      "type": "integer"
    }

如何使用params""" body"来记录参数。 ?

1 个答案:

答案 0 :(得分:0)

您只需在帖子中添加一个参数列表,并将一个参数添加到body中。

swagger: "2.0"

info:
  version: 1.0.0
  title: Simple API
  description: A parameter body example  

paths:
  /users:
    post:
      description: creates a user
      produces:
        - application/json
      consumes:
        - application/json
      parameters:
        - name: user
          in: body
          schema:
            properties:
              user:
                properties:
                  email:
                    type: string
                  password:
                    type: string
                  password_confirmation:
                    type: string
      responses:
        201:
          description: Creates an instance of User
        422:
          description: Bad syntax, user not created

您可以通过阅读the specification descriptionthis tutorial(披露:我写过)来找到有关OpenAPI(fka.Swagger)规范的许多信息。