forked from theoomoregbee/sails-hook-swagger-generator
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
58 lines (48 loc) · 1.44 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* Our hook
*/
const _path = require('path');
var swaggerDoc = require("./lib/swaggerDoc");
module.exports = function (sails) {
let routes = [];
return {
// capture the bound Sails routes
_routes: routes,
defaults: {
disabled: false,
__configKey__: {
swaggerJsonPath: _path.join(sails.config.appPath, '/swagger/swagger.json'),
swagger: {
openapi: '3.0.0',
info: {
title: 'Swagger Json',
description: 'This is a generated swagger json for your sails project',
termsOfService: 'http://example.com/terms',
contact: {
name: 'Theophilus Omoregbee',
url: 'http://github.com/theo4u',
email: '[email protected]'
},
license: { name: 'Apache 2.0', url: 'http://www.apache.org/licenses/LICENSE-2.0.html' },
version: '1.0.0'
},
servers: [
{ url: 'http://localhost:1337/' }
],
externalDocs: { url: 'http://theophilus.ziippii.com' }
}
}
},
// Run when sails loads-- be sure and call `next()`.
initialize: function (next) {
// https://github.com/balderdashy/sails/blob/master/lib/EVENTS.md#routerbind
sails.on('router:bind', (routeObj) => {
routes.push(routeObj);
});
sails.after('ready', () => {
swaggerDoc(sails, routes, this);
});
next();
}
};
};