【问题标题】:Node js swagger response descriptionNode js 招摇响应说明
【发布时间】:2019-04-05 23:45:40
【问题描述】:

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

}

我如何将这个响应描述为大摇大摆的响应描述? 谢谢

【问题讨论】:

    标签: node.js express swagger


    【解决方案1】:

    您可以在线了解如何使用实际规范格式化 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 Schema 词汇定义的,您可以阅读有关 here 的更多信息。

    【讨论】:

      猜你喜欢
      • 2017-01-27
      • 2017-12-24
      • 1970-01-01
      • 2021-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多