Recently wanted to use Sails JS framework which runs on Node. I have heard a lot about it and wanted to check it out. I also wanted to be able to use swagger-ui with it. I saw the plugin available but ran into a glitch. This should be resolved *hopefully* soon. In the meantime if you want them to work together here is what one will need to do:
—–
Since I am not running off master for either project. I combined comments from this thread and hope it helps others:
1) npm install –save lodash
2) Created the controller
1
2
3
4
5
6
7
8
9 // api/controllers/SwaggerController.js
var _ = require('lodash');
var _super = require('sails-swagger/dist/api/controllers/SwaggerController');
_.merge(exports, _super);
_.merge(exports, {
// Extend with custom logic here by adding additional fields, methods, etc.
});
3) Created the installHooks.js
1
2
3
4
5
6
7 // config/installedHooks.js
module.exports.installedHooks = {
"sails-swagger": {
// load the hook into sails.hooks.swagger instead of sails.hooks['sails-swagger']
"name": "swagger"
}
};
4) Create swagger.js hook:
1
2
3
4
5
6
7
8
9
10 // config/swagger.js
module.exports.swagger = {
/**
* require() the package.json file for your Sails app.
*/
pkg: require('../package'),
ui: {
url: 'http://swagger.balderdash.io'
}
};
5) Downloaded swagger-ui and copy the dist/ contents to assets/docs under my current webapp. I am sure using docker works well but I didn’t try it as I wanted it all under the same app.
6) Done. (At least I hope I got everything).