mastra 0.1.57-unstable.35 → 0.1.57-unstable.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -16
- package/node_modules/express/History.md +0 -3647
- package/node_modules/express/LICENSE +0 -24
- package/node_modules/express/Readme.md +0 -260
- package/node_modules/express/index.js +0 -11
- package/node_modules/express/lib/application.js +0 -661
- package/node_modules/express/lib/express.js +0 -116
- package/node_modules/express/lib/middleware/init.js +0 -43
- package/node_modules/express/lib/middleware/query.js +0 -47
- package/node_modules/express/lib/request.js +0 -525
- package/node_modules/express/lib/response.js +0 -1179
- package/node_modules/express/lib/router/index.js +0 -673
- package/node_modules/express/lib/router/layer.js +0 -181
- package/node_modules/express/lib/router/route.js +0 -230
- package/node_modules/express/lib/utils.js +0 -303
- package/node_modules/express/lib/view.js +0 -182
- package/node_modules/express/package.json +0 -98
- package/node_modules/express-jsdoc-swagger/.all-contributorsrc +0 -168
- package/node_modules/express-jsdoc-swagger/.eslintignore +0 -6
- package/node_modules/express-jsdoc-swagger/.eslintrc.json +0 -37
- package/node_modules/express-jsdoc-swagger/CODE_OF_CONDUCT.md +0 -76
- package/node_modules/express-jsdoc-swagger/CONTRIBUTING.md +0 -55
- package/node_modules/express-jsdoc-swagger/LICENSE.md +0 -21
- package/node_modules/express-jsdoc-swagger/README.md +0 -376
- package/node_modules/express-jsdoc-swagger/commitlint.config.js +0 -24
- package/node_modules/express-jsdoc-swagger/config/default.js +0 -18
- package/node_modules/express-jsdoc-swagger/config/swaggerEvents.js +0 -5
- package/node_modules/express-jsdoc-swagger/consumers/getOnlyComments.js +0 -21
- package/node_modules/express-jsdoc-swagger/consumers/globFilesMatches.js +0 -50
- package/node_modules/express-jsdoc-swagger/consumers/jsdocInfo.js +0 -20
- package/node_modules/express-jsdoc-swagger/consumers/readFiles.js +0 -9
- package/node_modules/express-jsdoc-swagger/consumers/utils/getComments.js +0 -13
- package/node_modules/express-jsdoc-swagger/consumers/utils/readFile.js +0 -15
- package/node_modules/express-jsdoc-swagger/index.d.ts +0 -65
- package/node_modules/express-jsdoc-swagger/index.js +0 -60
- package/node_modules/express-jsdoc-swagger/package.json +0 -59
- package/node_modules/express-jsdoc-swagger/processSwagger.js +0 -45
- package/node_modules/express-jsdoc-swagger/swaggerEvents.js +0 -35
- package/node_modules/express-jsdoc-swagger/transforms/basic/contact.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/basic/index.js +0 -10
- package/node_modules/express-jsdoc-swagger/transforms/basic/info.js +0 -26
- package/node_modules/express-jsdoc-swagger/transforms/basic/license.js +0 -14
- package/node_modules/express-jsdoc-swagger/transforms/basic/servers.js +0 -20
- package/node_modules/express-jsdoc-swagger/transforms/components/index.js +0 -130
- package/node_modules/express-jsdoc-swagger/transforms/index.js +0 -13
- package/node_modules/express-jsdoc-swagger/transforms/paths/content.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/paths/examples.js +0 -98
- package/node_modules/express-jsdoc-swagger/transforms/paths/formParams.js +0 -40
- package/node_modules/express-jsdoc-swagger/transforms/paths/index.js +0 -127
- package/node_modules/express-jsdoc-swagger/transforms/paths/parameters.js +0 -80
- package/node_modules/express-jsdoc-swagger/transforms/paths/requestBody.js +0 -65
- package/node_modules/express-jsdoc-swagger/transforms/paths/responses.js +0 -55
- package/node_modules/express-jsdoc-swagger/transforms/paths/schema.js +0 -33
- package/node_modules/express-jsdoc-swagger/transforms/paths/security.js +0 -31
- package/node_modules/express-jsdoc-swagger/transforms/paths/validStatusCodes.js +0 -64
- package/node_modules/express-jsdoc-swagger/transforms/security/index.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/tags/index.js +0 -41
- package/node_modules/express-jsdoc-swagger/transforms/utils/arrays.js +0 -12
- package/node_modules/express-jsdoc-swagger/transforms/utils/combineSchema.js +0 -67
- package/node_modules/express-jsdoc-swagger/transforms/utils/enumValues.js +0 -6
- package/node_modules/express-jsdoc-swagger/transforms/utils/errorMessage.js +0 -8
- package/node_modules/express-jsdoc-swagger/transforms/utils/formatDescription.js +0 -35
- package/node_modules/express-jsdoc-swagger/transforms/utils/formatExamples.js +0 -25
- package/node_modules/express-jsdoc-swagger/transforms/utils/generator.js +0 -6
- package/node_modules/express-jsdoc-swagger/transforms/utils/httpMethods.js +0 -18
- package/node_modules/express-jsdoc-swagger/transforms/utils/mapDescription.js +0 -5
- package/node_modules/express-jsdoc-swagger/transforms/utils/refSchema.js +0 -48
- package/node_modules/express-jsdoc-swagger/transforms/utils/setProperty.js +0 -25
- package/node_modules/express-jsdoc-swagger/transforms/utils/tags.js +0 -16
- package/node_modules/express-jsdoc-swagger/transforms/utils/validateTypes.js +0 -11
- package/node_modules/serverless-http/LICENSE.txt +0 -33
- package/node_modules/serverless-http/README.md +0 -117
- package/node_modules/serverless-http/lib/finish.js +0 -42
- package/node_modules/serverless-http/lib/framework/get-framework.js +0 -79
- package/node_modules/serverless-http/lib/provider/aws/clean-up-event.js +0 -98
- package/node_modules/serverless-http/lib/provider/aws/create-request.js +0 -110
- package/node_modules/serverless-http/lib/provider/aws/format-response.js +0 -45
- package/node_modules/serverless-http/lib/provider/aws/index.js +0 -15
- package/node_modules/serverless-http/lib/provider/aws/is-binary.js +0 -42
- package/node_modules/serverless-http/lib/provider/aws/sanitize-headers.js +0 -21
- package/node_modules/serverless-http/lib/provider/azure/clean-up-request.js +0 -41
- package/node_modules/serverless-http/lib/provider/azure/create-request.js +0 -45
- package/node_modules/serverless-http/lib/provider/azure/format-response.js +0 -18
- package/node_modules/serverless-http/lib/provider/azure/index.js +0 -13
- package/node_modules/serverless-http/lib/provider/azure/is-binary.js +0 -42
- package/node_modules/serverless-http/lib/provider/azure/sanitize-headers.js +0 -23
- package/node_modules/serverless-http/lib/provider/azure/set-cookie.json +0 -1
- package/node_modules/serverless-http/lib/provider/get-provider.js +0 -17
- package/node_modules/serverless-http/lib/request.js +0 -38
- package/node_modules/serverless-http/lib/response.js +0 -135
- package/node_modules/serverless-http/package.json +0 -93
- package/node_modules/serverless-http/serverless-http.d.ts +0 -41
- package/node_modules/serverless-http/serverless-http.js +0 -23
- package/node_modules/swagger-ui-express/LICENSE +0 -22
- package/node_modules/swagger-ui-express/README.md +0 -360
- package/node_modules/swagger-ui-express/index.js +0 -311
- package/node_modules/swagger-ui-express/package.json +0 -58
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
const swaggerUi = require('swagger-ui-express');
|
|
2
|
-
const merge = require('merge');
|
|
3
|
-
|
|
4
|
-
const defaultOptions = require('./config/default');
|
|
5
|
-
const swaggerEventsOptions = require('./config/swaggerEvents');
|
|
6
|
-
const processSwagger = require('./processSwagger');
|
|
7
|
-
const swaggerEvents = require('./swaggerEvents');
|
|
8
|
-
|
|
9
|
-
const expressJSDocSwagger = app => (userOptions = {}, userSwagger = {}) => {
|
|
10
|
-
const events = swaggerEvents(swaggerEventsOptions(userOptions));
|
|
11
|
-
const { instance } = events;
|
|
12
|
-
let swaggerObject = {};
|
|
13
|
-
|
|
14
|
-
const options = {
|
|
15
|
-
...defaultOptions,
|
|
16
|
-
...userOptions,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
processSwagger(options, events.processFile)
|
|
20
|
-
.then(result => {
|
|
21
|
-
swaggerObject = {
|
|
22
|
-
...swaggerObject,
|
|
23
|
-
...result.swaggerObject,
|
|
24
|
-
};
|
|
25
|
-
swaggerObject = merge.recursive(true, swaggerObject, userSwagger);
|
|
26
|
-
events.finish(swaggerObject, {
|
|
27
|
-
jsdocInfo: result.jsdocInfo,
|
|
28
|
-
getPaths: result.getPaths,
|
|
29
|
-
getComponents: result.getComponents,
|
|
30
|
-
getTags: result.getTags,
|
|
31
|
-
});
|
|
32
|
-
})
|
|
33
|
-
.catch(events.error);
|
|
34
|
-
|
|
35
|
-
if (options.exposeSwaggerUI) {
|
|
36
|
-
app.use(options.swaggerUIPath, (req, res, next) => {
|
|
37
|
-
swaggerObject = {
|
|
38
|
-
...swaggerObject,
|
|
39
|
-
host: req.get('host'),
|
|
40
|
-
};
|
|
41
|
-
req.swaggerDoc = swaggerObject;
|
|
42
|
-
next();
|
|
43
|
-
}, swaggerUi.serve, swaggerUi.setup(undefined, options.swaggerUiOptions));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (options.exposeApiDocs) {
|
|
47
|
-
app.get(options.apiDocsPath, (req, res) => {
|
|
48
|
-
res.json({
|
|
49
|
-
...swaggerObject,
|
|
50
|
-
// we skipped this as is not a valid prop in OpenAPI
|
|
51
|
-
// This is only being used in the SwaggerUI Library
|
|
52
|
-
host: undefined,
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return instance;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
module.exports = expressJSDocSwagger;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "express-jsdoc-swagger",
|
|
3
|
-
"version": "1.8.0",
|
|
4
|
-
"description": "Swagger OpenAPI 3.x generator",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"dependencies": {
|
|
7
|
-
"chalk": "^4.1.0",
|
|
8
|
-
"doctrine": "^3.0.0",
|
|
9
|
-
"express": "^4.17.1",
|
|
10
|
-
"glob": "^7.1.6",
|
|
11
|
-
"merge": "^2.1.1",
|
|
12
|
-
"swagger-ui-express": "^4.3.0"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@commitlint/cli": "^11.0.0",
|
|
16
|
-
"@commitlint/config-conventional": "^11.0.0",
|
|
17
|
-
"eslint": "^7.19.0",
|
|
18
|
-
"eslint-config-airbnb-base": "^14.2.1",
|
|
19
|
-
"eslint-plugin-import": "^2.22.1",
|
|
20
|
-
"eslint-plugin-jest": "^24.1.3",
|
|
21
|
-
"husky": "^4.3.8",
|
|
22
|
-
"jest": "^26.6.3"
|
|
23
|
-
},
|
|
24
|
-
"engines": {
|
|
25
|
-
"node": ">= 10.0.0"
|
|
26
|
-
},
|
|
27
|
-
"scripts": {
|
|
28
|
-
"test": "jest",
|
|
29
|
-
"lint": "./node_modules/.bin/eslint ."
|
|
30
|
-
},
|
|
31
|
-
"husky": {
|
|
32
|
-
"hooks": {
|
|
33
|
-
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
34
|
-
"pre-commit": "npm run lint",
|
|
35
|
-
"pre-push": "npm run test"
|
|
36
|
-
}
|
|
37
|
-
},
|
|
38
|
-
"repository": {
|
|
39
|
-
"type": "git",
|
|
40
|
-
"url": "git+https://github.com/brikev/express-jsdoc-swagger.git"
|
|
41
|
-
},
|
|
42
|
-
"keywords": [
|
|
43
|
-
"swagger",
|
|
44
|
-
"swagger-generator",
|
|
45
|
-
"express",
|
|
46
|
-
"jsdoc",
|
|
47
|
-
"node",
|
|
48
|
-
"docs",
|
|
49
|
-
"documentation",
|
|
50
|
-
"swagger-ui",
|
|
51
|
-
"OpenAPI"
|
|
52
|
-
],
|
|
53
|
-
"author": "BRIKEV (https://github.com/brikev)",
|
|
54
|
-
"license": "MIT",
|
|
55
|
-
"bugs": {
|
|
56
|
-
"url": "https://github.com/brikev/express-jsdoc-swagger/issues"
|
|
57
|
-
},
|
|
58
|
-
"homepage": "https://brikev.github.io/express-jsdoc-swagger-docs/#/"
|
|
59
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
const readFiles = require('./consumers/readFiles');
|
|
2
|
-
const globFilesMatches = require('./consumers/globFilesMatches');
|
|
3
|
-
const getOnlyComments = require('./consumers/getOnlyComments');
|
|
4
|
-
const jsdocInfo = require('./consumers/jsdocInfo');
|
|
5
|
-
const {
|
|
6
|
-
getBasicInfo,
|
|
7
|
-
getSecuritySchemes,
|
|
8
|
-
getPaths,
|
|
9
|
-
getComponents,
|
|
10
|
-
getTags,
|
|
11
|
-
} = require('./transforms');
|
|
12
|
-
|
|
13
|
-
const defaultLogger = () => null;
|
|
14
|
-
|
|
15
|
-
const processSwagger = (options, logger = defaultLogger) => {
|
|
16
|
-
let swaggerObject = {
|
|
17
|
-
openapi: '3.0.0',
|
|
18
|
-
info: options.info,
|
|
19
|
-
servers: options.servers,
|
|
20
|
-
security: options.security,
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
swaggerObject = getBasicInfo(swaggerObject);
|
|
24
|
-
logger({ entity: 'basicInfo', swaggerObject });
|
|
25
|
-
swaggerObject = getSecuritySchemes(swaggerObject);
|
|
26
|
-
logger({ entity: 'securitySchemas', swaggerObject });
|
|
27
|
-
|
|
28
|
-
return globFilesMatches(options.baseDir, options.filesPattern)
|
|
29
|
-
.then(readFiles)
|
|
30
|
-
.then(getOnlyComments)
|
|
31
|
-
.then(jsdocInfo())
|
|
32
|
-
.then(data => {
|
|
33
|
-
swaggerObject = getPaths(swaggerObject, data);
|
|
34
|
-
logger({ entity: 'paths', swaggerObject });
|
|
35
|
-
swaggerObject = getComponents(swaggerObject, data, options);
|
|
36
|
-
logger({ entity: 'components', swaggerObject });
|
|
37
|
-
swaggerObject = getTags(swaggerObject, data);
|
|
38
|
-
logger({ entity: 'tags', swaggerObject });
|
|
39
|
-
return {
|
|
40
|
-
swaggerObject, jsdocInfo, getPaths, getComponents, getTags,
|
|
41
|
-
};
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
module.exports = processSwagger;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const { EventEmitter } = require('events');
|
|
2
|
-
|
|
3
|
-
const ERROR_EVENT_NAME = 'error';
|
|
4
|
-
const PROCESS_EVENT_NAME = 'process';
|
|
5
|
-
const FINISH_EVENT_NAME = 'finish';
|
|
6
|
-
|
|
7
|
-
let api = null;
|
|
8
|
-
|
|
9
|
-
const error = eventEmitter => errorInfo => (
|
|
10
|
-
eventEmitter.emit(ERROR_EVENT_NAME, errorInfo)
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
const processFile = eventEmitter => info => (
|
|
14
|
-
eventEmitter.emit(PROCESS_EVENT_NAME, info)
|
|
15
|
-
);
|
|
16
|
-
|
|
17
|
-
const finish = eventEmitter => (info, methods) => (
|
|
18
|
-
eventEmitter.emit(FINISH_EVENT_NAME, info, methods)
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
const swaggerEvents = ({ multiple } = {}) => {
|
|
22
|
-
if (api && !multiple) return api;
|
|
23
|
-
const instance = new EventEmitter();
|
|
24
|
-
|
|
25
|
-
api = {
|
|
26
|
-
instance,
|
|
27
|
-
error: error(instance),
|
|
28
|
-
processFile: processFile(instance),
|
|
29
|
-
finish: finish(instance),
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
return api;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
module.exports = swaggerEvents;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const setProperty = require('../utils/setProperty')('contact');
|
|
2
|
-
|
|
3
|
-
const getContact = (options = {}) => ({
|
|
4
|
-
name: setProperty(options, 'name', {
|
|
5
|
-
type: 'string',
|
|
6
|
-
required: true,
|
|
7
|
-
}),
|
|
8
|
-
url: setProperty(options, 'url', {
|
|
9
|
-
type: 'string',
|
|
10
|
-
defaultValue: '',
|
|
11
|
-
}),
|
|
12
|
-
email: setProperty(options, 'email', {
|
|
13
|
-
type: 'string',
|
|
14
|
-
defaultValue: '',
|
|
15
|
-
}),
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
module.exports = getContact;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const info = require('./info');
|
|
2
|
-
const servers = require('./servers');
|
|
3
|
-
|
|
4
|
-
const getBasicInfo = (swaggerObjet = {}) => ({
|
|
5
|
-
...swaggerObjet,
|
|
6
|
-
info: { ...info(swaggerObjet.info) },
|
|
7
|
-
servers: servers(swaggerObjet.servers),
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
module.exports = getBasicInfo;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const setProperty = require('../utils/setProperty')('info');
|
|
2
|
-
const getContact = require('./contact');
|
|
3
|
-
const license = require('./license');
|
|
4
|
-
|
|
5
|
-
const getInfo = (options = {}) => ({
|
|
6
|
-
title: setProperty(options, 'title', {
|
|
7
|
-
type: 'string',
|
|
8
|
-
required: true,
|
|
9
|
-
}),
|
|
10
|
-
description: setProperty(options, 'description', {
|
|
11
|
-
type: 'string',
|
|
12
|
-
defaultValue: 'Add your description',
|
|
13
|
-
}),
|
|
14
|
-
...(options.contact ? { contact: getContact(options.contact) } : {}),
|
|
15
|
-
...(options.license ? { license: license(options.license) } : {}),
|
|
16
|
-
termsOfService: setProperty(options, 'termsOfService', {
|
|
17
|
-
type: 'string',
|
|
18
|
-
defaultValue: '',
|
|
19
|
-
}),
|
|
20
|
-
version: setProperty(options, 'version', {
|
|
21
|
-
type: 'string',
|
|
22
|
-
required: true,
|
|
23
|
-
}),
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
module.exports = getInfo;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
const setProperty = require('../utils/setProperty')('license');
|
|
2
|
-
|
|
3
|
-
const getContact = (options = {}) => ({
|
|
4
|
-
name: setProperty(options, 'name', {
|
|
5
|
-
type: 'string',
|
|
6
|
-
required: true,
|
|
7
|
-
}),
|
|
8
|
-
url: setProperty(options, 'url', {
|
|
9
|
-
type: 'string',
|
|
10
|
-
defaultValue: '',
|
|
11
|
-
}),
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
module.exports = getContact;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
const setProperty = require('../utils/setProperty')('servers');
|
|
2
|
-
|
|
3
|
-
const setServer = (server = {}) => ({
|
|
4
|
-
url: setProperty(server, 'url', {
|
|
5
|
-
type: 'string',
|
|
6
|
-
required: true,
|
|
7
|
-
}),
|
|
8
|
-
description: setProperty(server, 'description', {
|
|
9
|
-
type: 'string',
|
|
10
|
-
defaultValue: '',
|
|
11
|
-
}),
|
|
12
|
-
...(server.variables ? { variables: server.variables } : {}),
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const setServers = (servers = []) => {
|
|
16
|
-
if (!servers || !Array.isArray(servers)) return [];
|
|
17
|
-
return servers.map(setServer);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
module.exports = setServers;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
const { getTagInfo, getTagsInfo } = require('../utils/tags');
|
|
2
|
-
const mapDescription = require('../utils/mapDescription');
|
|
3
|
-
const { refSchema, formatRefSchema } = require('../utils/refSchema');
|
|
4
|
-
const addEnumValues = require('../utils/enumValues');
|
|
5
|
-
const formatDescription = require('../utils/formatDescription');
|
|
6
|
-
const combineSchema = require('../utils/combineSchema');
|
|
7
|
-
const validateTypes = require('../utils/validateTypes');
|
|
8
|
-
|
|
9
|
-
const REQUIRED = 'required';
|
|
10
|
-
|
|
11
|
-
const getPropertyName = ({ name: propertyName }) => {
|
|
12
|
-
const [name] = propertyName.split('.');
|
|
13
|
-
return name;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
const addTypeApplication = (applications, expression) => {
|
|
17
|
-
if (!applications && !expression) return {};
|
|
18
|
-
return {
|
|
19
|
-
type: expression.name.toLowerCase(),
|
|
20
|
-
items: {
|
|
21
|
-
type: applications[0].name,
|
|
22
|
-
},
|
|
23
|
-
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const addRefSchema = (typeName, applications, elements) => {
|
|
27
|
-
if (!typeName && !elements) return { items: formatRefSchema(applications) };
|
|
28
|
-
return {};
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
const formatProperties = (properties, options = {}) => {
|
|
32
|
-
if (!properties || !Array.isArray(properties)) return {};
|
|
33
|
-
return properties.reduce((acum, property) => {
|
|
34
|
-
const name = getPropertyName(property);
|
|
35
|
-
const isRequired = property.name.includes(REQUIRED);
|
|
36
|
-
const {
|
|
37
|
-
name: typeName, applications, expression, elements,
|
|
38
|
-
} = property.type;
|
|
39
|
-
const [descriptionValue, enumValues, jsonOptions] = formatDescription(property.description);
|
|
40
|
-
const [description, format] = mapDescription(descriptionValue);
|
|
41
|
-
return {
|
|
42
|
-
...acum,
|
|
43
|
-
[name]: {
|
|
44
|
-
description,
|
|
45
|
-
...refSchema(typeName),
|
|
46
|
-
...combineSchema(elements),
|
|
47
|
-
...addTypeApplication(applications, expression),
|
|
48
|
-
...addRefSchema(typeName, applications, elements),
|
|
49
|
-
...(format ? { format } : {}),
|
|
50
|
-
...addEnumValues(enumValues),
|
|
51
|
-
|
|
52
|
-
// Add nullable to non-required fields if option to do that is enabled
|
|
53
|
-
...(options.notRequiredAsNullable && !isRequired ? {
|
|
54
|
-
nullable: true,
|
|
55
|
-
} : {}),
|
|
56
|
-
...(jsonOptions || {}),
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}, {});
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const getRequiredProperties = properties => (
|
|
63
|
-
properties.filter(({ name }) => name.includes(REQUIRED))
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const formatRequiredProperties = requiredProperties => requiredProperties.map(getPropertyName);
|
|
67
|
-
|
|
68
|
-
const addDictionaryAdditionalProperties = typedef => {
|
|
69
|
-
if (
|
|
70
|
-
typedef.type.expression
|
|
71
|
-
&& typedef.type.expression.name === 'Dictionary'
|
|
72
|
-
) {
|
|
73
|
-
const typeName = typedef.type.applications[0].name;
|
|
74
|
-
const isPrimitive = validateTypes(typeName);
|
|
75
|
-
|
|
76
|
-
return {
|
|
77
|
-
additionalProperties: {
|
|
78
|
-
...(isPrimitive ? { type: typeName } : { $ref: `#/components/schemas/${typeName}` }),
|
|
79
|
-
},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {};
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const parseSchema = (schema, options = {}) => {
|
|
87
|
-
const typedef = getTagInfo(schema.tags, 'typedef');
|
|
88
|
-
const propertyValues = getTagsInfo(schema.tags, 'property');
|
|
89
|
-
const requiredProperties = getRequiredProperties(propertyValues);
|
|
90
|
-
const [descriptionValue, enumValues, jsonOptions] = formatDescription(schema.description);
|
|
91
|
-
const [description, format] = mapDescription(descriptionValue);
|
|
92
|
-
if (!typedef || !typedef.name) return {};
|
|
93
|
-
const {
|
|
94
|
-
elements,
|
|
95
|
-
} = typedef.type;
|
|
96
|
-
const type = typedef.type.name || 'object';
|
|
97
|
-
return {
|
|
98
|
-
[typedef.name]: {
|
|
99
|
-
...combineSchema(elements),
|
|
100
|
-
description,
|
|
101
|
-
...(requiredProperties.length ? {
|
|
102
|
-
required: formatRequiredProperties(requiredProperties),
|
|
103
|
-
} : {}),
|
|
104
|
-
type,
|
|
105
|
-
...(type === 'object' ? {
|
|
106
|
-
properties: formatProperties(propertyValues, options),
|
|
107
|
-
} : {}),
|
|
108
|
-
...(format ? { format } : {}),
|
|
109
|
-
...addEnumValues(enumValues),
|
|
110
|
-
...addDictionaryAdditionalProperties(typedef),
|
|
111
|
-
...(jsonOptions || {}),
|
|
112
|
-
},
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
const parseComponents = (swaggerObject = {}, components = [], options = {}) => {
|
|
117
|
-
if (!components || !Array.isArray(components)) return { components: { schemas: {} } };
|
|
118
|
-
const componentSchema = components.reduce((acum, item) => ({
|
|
119
|
-
...acum, ...parseSchema(item, options),
|
|
120
|
-
}), {});
|
|
121
|
-
return {
|
|
122
|
-
...swaggerObject,
|
|
123
|
-
components: {
|
|
124
|
-
...swaggerObject.components,
|
|
125
|
-
schemas: componentSchema,
|
|
126
|
-
},
|
|
127
|
-
};
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
module.exports = parseComponents;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const getBasicInfo = require('./basic');
|
|
2
|
-
const getSecuritySchemes = require('./security');
|
|
3
|
-
const getPaths = require('./paths');
|
|
4
|
-
const getComponents = require('./components');
|
|
5
|
-
const getTags = require('./tags');
|
|
6
|
-
|
|
7
|
-
module.exports = {
|
|
8
|
-
getBasicInfo,
|
|
9
|
-
getPaths,
|
|
10
|
-
getComponents,
|
|
11
|
-
getTags,
|
|
12
|
-
getSecuritySchemes,
|
|
13
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const getSchema = require('./schema');
|
|
2
|
-
|
|
3
|
-
const DEFAULT_CONTENT_TYPE = 'application/json';
|
|
4
|
-
|
|
5
|
-
const getContent = entity => (type, contentType, originalValue, examples, extendSchema = {}) => {
|
|
6
|
-
const schema = getSchema(entity, originalValue)(type);
|
|
7
|
-
return {
|
|
8
|
-
[contentType || DEFAULT_CONTENT_TYPE]: {
|
|
9
|
-
schema: {
|
|
10
|
-
...schema,
|
|
11
|
-
...extendSchema,
|
|
12
|
-
},
|
|
13
|
-
...(examples ? { examples } : {}),
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
module.exports = getContent;
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const STATUS_CODES = require('./validStatusCodes');
|
|
2
|
-
|
|
3
|
-
const errorMessage = require('../utils/errorMessage');
|
|
4
|
-
const mapDescription = require('../utils/mapDescription');
|
|
5
|
-
const generator = require('../utils/generator');
|
|
6
|
-
|
|
7
|
-
const REQUEST_BODY = 'request';
|
|
8
|
-
const RESPONSE_BODY = 'response';
|
|
9
|
-
|
|
10
|
-
// Generates a new object with information on a request body example
|
|
11
|
-
const parseRequestPayloadExample = (description, content) => {
|
|
12
|
-
const [summary] = description;
|
|
13
|
-
return {
|
|
14
|
-
type: REQUEST_BODY,
|
|
15
|
-
summary,
|
|
16
|
-
value: content,
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const showError = message => {
|
|
21
|
-
errorMessage(message);
|
|
22
|
-
return {};
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
// Generates a new object with information on a response body example
|
|
26
|
-
const parseResponsePayloadExample = (description, content) => {
|
|
27
|
-
const [status, summary] = description;
|
|
28
|
-
if (!STATUS_CODES[status]) {
|
|
29
|
-
return showError(`${status} is not a valid status for a response`);
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
type: RESPONSE_BODY,
|
|
33
|
-
status,
|
|
34
|
-
summary,
|
|
35
|
-
value: content,
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const getParsedExample = ({ type, metadata, content }) => {
|
|
40
|
-
const types = {
|
|
41
|
-
[REQUEST_BODY]: () => parseRequestPayloadExample(metadata, content),
|
|
42
|
-
[RESPONSE_BODY]: () => parseResponsePayloadExample(metadata, content),
|
|
43
|
-
default: () => showError(`Cannot determine where to use example of type ${type}`),
|
|
44
|
-
};
|
|
45
|
-
return (types[type] || types.default)();
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Parses a single example tag contents. Depending on the type (response or
|
|
50
|
-
* request), the expected data and returned structure will be different.
|
|
51
|
-
*
|
|
52
|
-
* To prevent compatibility issues between SO, all `\r\n` instances (used in
|
|
53
|
-
* Windows by default as end of line sequence) will be replaced by `\n`.
|
|
54
|
-
*
|
|
55
|
-
* @param {string} exampleTagDescription - Text passed to the example tag.
|
|
56
|
-
*
|
|
57
|
-
* @return {object} Structured information about the example, including the
|
|
58
|
-
* example type (request or response), summary, status code (only applicable to
|
|
59
|
-
* response types) and the example code itself.
|
|
60
|
-
*/
|
|
61
|
-
const parseExample = ({ description: exampleTagDescription }) => {
|
|
62
|
-
const formattedTagDescription = exampleTagDescription.replace(/\r\n/gi, '\n');
|
|
63
|
-
|
|
64
|
-
// The example content starts right after the first end of line character
|
|
65
|
-
const contentStartIndex = formattedTagDescription.indexOf('\n');
|
|
66
|
-
const content = formattedTagDescription.substring(contentStartIndex + 1);
|
|
67
|
-
const description = formattedTagDescription.substring(0, contentStartIndex);
|
|
68
|
-
|
|
69
|
-
const [type, ...metadata] = mapDescription(description);
|
|
70
|
-
|
|
71
|
-
return getParsedExample({ type, metadata, content });
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
/**
|
|
75
|
-
* This receives a set of values extracted from "example" tags, and translates
|
|
76
|
-
* them to objects with the example type (request or response), summary, status
|
|
77
|
-
* code (only applicable to response types) and the example code itself.
|
|
78
|
-
*
|
|
79
|
-
* @param {object[]} exampleTags - Set of example tags, which description are
|
|
80
|
-
* expected to have the following information in order to be parsed properly:
|
|
81
|
-
*
|
|
82
|
-
* > For request body examples:
|
|
83
|
-
*
|
|
84
|
-
* response - [example summary]
|
|
85
|
-
* [example content]
|
|
86
|
-
*
|
|
87
|
-
* > For response examples:
|
|
88
|
-
*
|
|
89
|
-
* response - [http status code] - [example summary]
|
|
90
|
-
* [example content]
|
|
91
|
-
*
|
|
92
|
-
* @return {object[]} List of objects containing the example type (request or
|
|
93
|
-
* response), summary, status code (only applicable to response types) and
|
|
94
|
-
* the example code itself.
|
|
95
|
-
*/
|
|
96
|
-
const exampleGenerator = generator(parseExample, 'type');
|
|
97
|
-
|
|
98
|
-
module.exports = exampleGenerator;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
const merge = require('merge');
|
|
2
|
-
const getContent = require('./content')('@paramFormBody');
|
|
3
|
-
const mapDescription = require('../utils/mapDescription');
|
|
4
|
-
|
|
5
|
-
const DEFAULT_CONTENT_TYPE = 'application/json';
|
|
6
|
-
|
|
7
|
-
const getRequiredValues = (currentState, contentType, key, isRequired) => {
|
|
8
|
-
const paramContentType = contentType || DEFAULT_CONTENT_TYPE;
|
|
9
|
-
if (currentState.content[paramContentType]) {
|
|
10
|
-
return [
|
|
11
|
-
...(currentState.content[paramContentType].schema.required || []),
|
|
12
|
-
key,
|
|
13
|
-
];
|
|
14
|
-
}
|
|
15
|
-
return isRequired ? [key] : [];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const formParams = (currentState, key, body, isRequired, requestExamples) => {
|
|
19
|
-
const [description, contentType] = mapDescription(body.description);
|
|
20
|
-
const schema = {
|
|
21
|
-
properties: {
|
|
22
|
-
[key]: {
|
|
23
|
-
type: body.type.name,
|
|
24
|
-
description,
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
required: getRequiredValues(currentState, contentType, key, isRequired),
|
|
28
|
-
};
|
|
29
|
-
return {
|
|
30
|
-
content: {
|
|
31
|
-
...merge.recursive(
|
|
32
|
-
true,
|
|
33
|
-
currentState.content,
|
|
34
|
-
getContent({ name: 'object' }, contentType, description, requestExamples, schema),
|
|
35
|
-
),
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
module.exports = formParams;
|