Sails swagger api文档

时间:2018-02-07 14:17:37

标签: node.js sails.js swagger swagger-ui sails-mongo

我在我的节点js应用程序中使用sails。并希望实现swagger api文档。我按照Swagger Sails JS文件。我从api doc得到了结果。我的预期结果来自api doc。我已在 router.js 文件中编写路线,如下所示

'post /login': {
    controller: 'user/UserController',
    action: 'login',
    skipAssets: 'true',
    //swagger path object
    "get": {
      "tags": [
        "Users"
      ],
      "description": "Get a login user data",
      "parameters": [{
        "email": "abc@gmail.com",
        "password": "12345678y",
        "deviceToken": "12345678y",
        "deviceType": 2
      }],
      "responses": {
        "200": {
          "statusCode": 0,
          "status": true,
          "message": "string",
          "result": {}
        }
      }
    }
  }

如果我在路线上写错了。然后如何编写路由,以便我从api docs获得我期望的结果?

谢谢!

1 个答案:

答案 0 :(得分:1)

您可以尝试使用this

我认为路由器文件应该是这样的:

'post /login': {
    controller: 'user/UserController',
    action: 'login',
    skipAssets: 'true',
    swagger: {
        methods: ["get"],
        tags: ["Users"],
        description: "Get a login user data",
        parameters: [{
            email: "abc@gmail.com",
            password: "12345678y",
            deviceToken: "12345678y",
            deviceType: 2
        }],
        responses: {
            '200': {
                statusCode: 0,
                status: true,
                message: "string",
                result: {}
            }
        }
    }
}