Search code examples
node.jssails.jsswaggerswagger-uisails-mongo

Sails swagger api documentation


I am using sails in my node js application. And want to implement swagger api documentation. And I follow Swagger Sails JS document. I got the result from my api doc. And my expected result from api doc . I have write the route in router.js file like below

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

If I had write wrong in my routes. Then how to write the routes, so that I will get my expected result from api docs?

Thanks!


Solution

  • You can try using this.

    And I suppose router file should be like this:

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