Node js swagger响应描述

时间:2018-11-01 17:42:41

标签: node.js express swagger

我已经使用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"
}

}

我如何将这个响应描述为昂扬的响应描述? 谢谢

1 个答案:

答案 0 :(得分:1)

您可以通过在线https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responsesDefinitionsObject

了解更多有关如何使用实际规范格式化Swagger定义的知识。

您想要的东西的简化版本看起来像这样:

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模式词汇定义的,您可以阅读有关here的更多信息。

相关问题