![](/img/trans.png)
[英]How swagger's response schema's code matches node.js' response status code?
[英]Node js swagger response description
我已經使用Node Js和Express開發了REST服務。 我已經集成了Swagger來定義api doc。 關於登錄服務,這是我使用的大刀闊斧的定義:
/**
* @swagger
* /api/v1.0/login:
* post:
* tags:
* - Login
* description: Login into system
* produces:
* - application/json
* parameters:
* - username: User
* description: The username of user
* in: body
* required: true
* - password: password
* description: Password of user
* in: body
* required: true
*
* responses:
* 200:
* description: Successfully login
*/
但是我的服務給了我這個響應json:
{
"status": "ok",
"data": {
"auth": true,
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjViYzg3ZDFkOWNhNmRkNDM5MDI1YjA1MCIsImlhdCI6MTU0MTA5MzMxMSwiZXhwIjoxNTQxMTc5NzExfQ.3BIl0dIQg-cEU9fyM7BocKLHEugH8cws5_E-dmRVHZM",
"faId": "HSo7q2o0",
"roles": "Owner"
}
}
我如何將這個響應描述為敏捷的響應描述? 謝謝
您可以在線學習有關如何使用實際規范來格式化Swagger定義的很多知識: https : //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responsesDefinitionsObject
所需內容的真正簡化版本如下所示:
responses:
200:
description: Successfully login
schema:
properties:
status:
type: string
data:
type: object
properties:
auth:
type: boolean
token:
type: string
faId:
type: string
roles:
type: string
您可能需要填寫更多信息,包括描述,所需的屬性等。您可以在上面的鏈接中了解這些含義。
此外,Swagger中的模型是使用JSON模式詞匯表定義的,您可以在此處閱讀更多內容。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.