forked from BRIKEV/express-jsdoc-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
processSwagger.js
45 lines (40 loc) · 1.38 KB
/
processSwagger.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
const readFiles = require('./consumers/readFiles');
const globFilesMatches = require('./consumers/globFilesMatches');
const getOnlyComments = require('./consumers/getOnlyComments');
const jsdocInfo = require('./consumers/jsdocInfo');
const {
getBasicInfo,
getSecuritySchemes,
getPaths,
getComponents,
getTags,
} = require('./transforms');
const defaultLogger = () => null;
const processSwagger = (options, logger = defaultLogger) => {
let swaggerObject = {
openapi: '3.0.0',
info: options.info,
servers: options.servers,
security: options.security,
};
swaggerObject = getBasicInfo(swaggerObject);
logger({ entity: 'basicInfo', swaggerObject });
swaggerObject = getSecuritySchemes(swaggerObject);
logger({ entity: 'securitySchemas', swaggerObject });
return globFilesMatches(options.baseDir, options.filesPattern)
.then(readFiles)
.then(getOnlyComments)
.then(jsdocInfo())
.then(data => {
swaggerObject = getPaths(swaggerObject, data);
logger({ entity: 'paths', swaggerObject });
swaggerObject = getComponents(swaggerObject, data, options);
logger({ entity: 'components', swaggerObject });
swaggerObject = getTags(swaggerObject, data);
logger({ entity: 'tags', swaggerObject });
return {
swaggerObject, jsdocInfo, getPaths, getComponents, getTags,
};
});
};
module.exports = processSwagger;