【发布时间】:2019-11-01 23:48:44
【问题描述】:
我尝试使用 swagger 为发布请求创建 api,但无法确定我应该在 swagger 中配置哪些参数才能创建此 API。
我使用邮递员来获取有关响应的所有信息并大张旗鼓地实施。
'/api/v1/labels':
post:
tags:
- devices
summary: 'create new label'
description: 'create new label to a given device'
operationId: createNewLabel
produces:
- application/json
parameters:
- name: x-access-token
description: 'cognito token'
in: header
type: string
required: true
- in: body
name: body
description: add label details
required: true
schema:
$ref: '#/definitions/labelRequest'
responses:
'201':
schema:
$ref: '#/definitions/labelRequest'
description: Created
这是我写的定义:
labelRequest:
type: object
items:
$ref: '#/definitions/labelRequestBody'
labelRequestBody:
type: object
properties:
device_ids:
type: array
items:
type: string
example: ["9bc11e25-4db2-4780-b761-390e3806082a"]
format: uuid
name:
type: string
example: new_label
这是 API 调用:
https:///api/v1/labels
带有这些标题:
x-access-token
并以这个主体作为有效负载:
{
"device_ids":["ea4b9daa-07cd-4cd6-981f-c86e1e81f04c"],
"name":"labelName"
}
预期结果是:201(已创建)
【问题讨论】: