简体   繁体   English

Node js swagger响应描述

[英]Node js swagger response description

i have developed a REST Service using Node Js and Express. 我已经使用Node Js和Express开发了REST服务。 I have integrate Swagger to define api doc. 我已经集成了Swagger来定义api doc。 About login service this is the swagger definition that i used: 关于登录服务,这是我使用的大刀阔斧的定义:

/**
* @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
*/

But my service gives me this response json: 但是我的服务给了我这个响应json:

{
"status": "ok",
"data": {
    "auth": true,
    "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjViYzg3ZDFkOWNhNmRkNDM5MDI1YjA1MCIsImlhdCI6MTU0MTA5MzMxMSwiZXhwIjoxNTQxMTc5NzExfQ.3BIl0dIQg-cEU9fyM7BocKLHEugH8cws5_E-dmRVHZM",
    "faId": "HSo7q2o0",
    "roles": "Owner"
}

} }

How i can describe this response into swagger response description? 我如何将这个响应描述为敏捷的响应描述? Thanks 谢谢

You can learn a lot about how to format Swagger definitions using the actual specification online: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responsesDefinitionsObject 您可以在线学习有关如何使用实际规范来格式化Swagger定义的很多知识: https : //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#responsesDefinitionsObject

A really simplified version of what you want would look something like this: 所需内容的真正简化版本如下所示:

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

You would probably want to fill in more information as far as descriptions, which properties are required, etc. You can read about what those mean in the link above. 您可能需要填写更多信息,包括描述,所需的属性等。您可以在上面的链接中了解这些含义。

Also, models in Swagger are defined using the JSON Schema vocabulary, which you can read more about here . 此外,Swagger中的模型是使用JSON模式词汇表定义的,您可以在此处阅读更多内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM