[英]How to create api using post request with json as payload using swagger
我嘗試使用swagger為發布請求創建api,但無法確定為創建此API而應在swagger中配置的參數。
我使用郵遞員來獲取有關響應的所有信息並大刀闊斧地實施。
'/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 /標簽
帶有這些標題:
X-訪問令牌
並以該主體作為有效載荷:
{
"device_ids":["ea4b9daa-07cd-4cd6-981f-c86e1e81f04c"],
"name":"labelName"
}
預期結果是:201(創建)
您labelRequest
,只需將labelRequest
模式更改為:
definitions:
labelRequest:
type: object
properties:
device_ids:
type: array
items:
type: string
# Array item example should NOT be enclosed in []
example: "9bc11e25-4db2-4780-b761-390e3806082a"
format: uuid
name:
type: string
example: new_label
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.