-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.ts
52 lines (45 loc) · 1.53 KB
/
index.ts
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
import * as path from 'path';
import swaggerDoc from './lib/swagger-doc';
import { SwaggerGenerator } from './lib/interfaces';
module.exports = (sails: Sails.Sails): Sails.Hook<SwaggerGenerator> => {
const routes: Sails.Route[] = [];
return {
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: 'theo4u@ymail.com'
},
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: 'https://theoomoregbee.github.io/' }
},
excludeDeprecatedPutBlueprintRoutes: true,
}
},
// Run when sails loads-- be sure and call `next()`.
initialize: function (next): void {
// https://github.com/balderdashy/sails/blob/master/lib/EVENTS.md#routerbind
sails.on('router:bind', routeObj => {
routes.push(routeObj);
});
sails.after('ready', async () => {
await swaggerDoc(sails, routes, this);
});
next();
}
};
}