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.
Files changed (97) hide show
  1. package/package.json +2 -16
  2. package/node_modules/express/History.md +0 -3647
  3. package/node_modules/express/LICENSE +0 -24
  4. package/node_modules/express/Readme.md +0 -260
  5. package/node_modules/express/index.js +0 -11
  6. package/node_modules/express/lib/application.js +0 -661
  7. package/node_modules/express/lib/express.js +0 -116
  8. package/node_modules/express/lib/middleware/init.js +0 -43
  9. package/node_modules/express/lib/middleware/query.js +0 -47
  10. package/node_modules/express/lib/request.js +0 -525
  11. package/node_modules/express/lib/response.js +0 -1179
  12. package/node_modules/express/lib/router/index.js +0 -673
  13. package/node_modules/express/lib/router/layer.js +0 -181
  14. package/node_modules/express/lib/router/route.js +0 -230
  15. package/node_modules/express/lib/utils.js +0 -303
  16. package/node_modules/express/lib/view.js +0 -182
  17. package/node_modules/express/package.json +0 -98
  18. package/node_modules/express-jsdoc-swagger/.all-contributorsrc +0 -168
  19. package/node_modules/express-jsdoc-swagger/.eslintignore +0 -6
  20. package/node_modules/express-jsdoc-swagger/.eslintrc.json +0 -37
  21. package/node_modules/express-jsdoc-swagger/CODE_OF_CONDUCT.md +0 -76
  22. package/node_modules/express-jsdoc-swagger/CONTRIBUTING.md +0 -55
  23. package/node_modules/express-jsdoc-swagger/LICENSE.md +0 -21
  24. package/node_modules/express-jsdoc-swagger/README.md +0 -376
  25. package/node_modules/express-jsdoc-swagger/commitlint.config.js +0 -24
  26. package/node_modules/express-jsdoc-swagger/config/default.js +0 -18
  27. package/node_modules/express-jsdoc-swagger/config/swaggerEvents.js +0 -5
  28. package/node_modules/express-jsdoc-swagger/consumers/getOnlyComments.js +0 -21
  29. package/node_modules/express-jsdoc-swagger/consumers/globFilesMatches.js +0 -50
  30. package/node_modules/express-jsdoc-swagger/consumers/jsdocInfo.js +0 -20
  31. package/node_modules/express-jsdoc-swagger/consumers/readFiles.js +0 -9
  32. package/node_modules/express-jsdoc-swagger/consumers/utils/getComments.js +0 -13
  33. package/node_modules/express-jsdoc-swagger/consumers/utils/readFile.js +0 -15
  34. package/node_modules/express-jsdoc-swagger/index.d.ts +0 -65
  35. package/node_modules/express-jsdoc-swagger/index.js +0 -60
  36. package/node_modules/express-jsdoc-swagger/package.json +0 -59
  37. package/node_modules/express-jsdoc-swagger/processSwagger.js +0 -45
  38. package/node_modules/express-jsdoc-swagger/swaggerEvents.js +0 -35
  39. package/node_modules/express-jsdoc-swagger/transforms/basic/contact.js +0 -18
  40. package/node_modules/express-jsdoc-swagger/transforms/basic/index.js +0 -10
  41. package/node_modules/express-jsdoc-swagger/transforms/basic/info.js +0 -26
  42. package/node_modules/express-jsdoc-swagger/transforms/basic/license.js +0 -14
  43. package/node_modules/express-jsdoc-swagger/transforms/basic/servers.js +0 -20
  44. package/node_modules/express-jsdoc-swagger/transforms/components/index.js +0 -130
  45. package/node_modules/express-jsdoc-swagger/transforms/index.js +0 -13
  46. package/node_modules/express-jsdoc-swagger/transforms/paths/content.js +0 -18
  47. package/node_modules/express-jsdoc-swagger/transforms/paths/examples.js +0 -98
  48. package/node_modules/express-jsdoc-swagger/transforms/paths/formParams.js +0 -40
  49. package/node_modules/express-jsdoc-swagger/transforms/paths/index.js +0 -127
  50. package/node_modules/express-jsdoc-swagger/transforms/paths/parameters.js +0 -80
  51. package/node_modules/express-jsdoc-swagger/transforms/paths/requestBody.js +0 -65
  52. package/node_modules/express-jsdoc-swagger/transforms/paths/responses.js +0 -55
  53. package/node_modules/express-jsdoc-swagger/transforms/paths/schema.js +0 -33
  54. package/node_modules/express-jsdoc-swagger/transforms/paths/security.js +0 -31
  55. package/node_modules/express-jsdoc-swagger/transforms/paths/validStatusCodes.js +0 -64
  56. package/node_modules/express-jsdoc-swagger/transforms/security/index.js +0 -18
  57. package/node_modules/express-jsdoc-swagger/transforms/tags/index.js +0 -41
  58. package/node_modules/express-jsdoc-swagger/transforms/utils/arrays.js +0 -12
  59. package/node_modules/express-jsdoc-swagger/transforms/utils/combineSchema.js +0 -67
  60. package/node_modules/express-jsdoc-swagger/transforms/utils/enumValues.js +0 -6
  61. package/node_modules/express-jsdoc-swagger/transforms/utils/errorMessage.js +0 -8
  62. package/node_modules/express-jsdoc-swagger/transforms/utils/formatDescription.js +0 -35
  63. package/node_modules/express-jsdoc-swagger/transforms/utils/formatExamples.js +0 -25
  64. package/node_modules/express-jsdoc-swagger/transforms/utils/generator.js +0 -6
  65. package/node_modules/express-jsdoc-swagger/transforms/utils/httpMethods.js +0 -18
  66. package/node_modules/express-jsdoc-swagger/transforms/utils/mapDescription.js +0 -5
  67. package/node_modules/express-jsdoc-swagger/transforms/utils/refSchema.js +0 -48
  68. package/node_modules/express-jsdoc-swagger/transforms/utils/setProperty.js +0 -25
  69. package/node_modules/express-jsdoc-swagger/transforms/utils/tags.js +0 -16
  70. package/node_modules/express-jsdoc-swagger/transforms/utils/validateTypes.js +0 -11
  71. package/node_modules/serverless-http/LICENSE.txt +0 -33
  72. package/node_modules/serverless-http/README.md +0 -117
  73. package/node_modules/serverless-http/lib/finish.js +0 -42
  74. package/node_modules/serverless-http/lib/framework/get-framework.js +0 -79
  75. package/node_modules/serverless-http/lib/provider/aws/clean-up-event.js +0 -98
  76. package/node_modules/serverless-http/lib/provider/aws/create-request.js +0 -110
  77. package/node_modules/serverless-http/lib/provider/aws/format-response.js +0 -45
  78. package/node_modules/serverless-http/lib/provider/aws/index.js +0 -15
  79. package/node_modules/serverless-http/lib/provider/aws/is-binary.js +0 -42
  80. package/node_modules/serverless-http/lib/provider/aws/sanitize-headers.js +0 -21
  81. package/node_modules/serverless-http/lib/provider/azure/clean-up-request.js +0 -41
  82. package/node_modules/serverless-http/lib/provider/azure/create-request.js +0 -45
  83. package/node_modules/serverless-http/lib/provider/azure/format-response.js +0 -18
  84. package/node_modules/serverless-http/lib/provider/azure/index.js +0 -13
  85. package/node_modules/serverless-http/lib/provider/azure/is-binary.js +0 -42
  86. package/node_modules/serverless-http/lib/provider/azure/sanitize-headers.js +0 -23
  87. package/node_modules/serverless-http/lib/provider/azure/set-cookie.json +0 -1
  88. package/node_modules/serverless-http/lib/provider/get-provider.js +0 -17
  89. package/node_modules/serverless-http/lib/request.js +0 -38
  90. package/node_modules/serverless-http/lib/response.js +0 -135
  91. package/node_modules/serverless-http/package.json +0 -93
  92. package/node_modules/serverless-http/serverless-http.d.ts +0 -41
  93. package/node_modules/serverless-http/serverless-http.js +0 -23
  94. package/node_modules/swagger-ui-express/LICENSE +0 -22
  95. package/node_modules/swagger-ui-express/README.md +0 -360
  96. package/node_modules/swagger-ui-express/index.js +0 -311
  97. package/node_modules/swagger-ui-express/package.json +0 -58
@@ -1,127 +0,0 @@
1
- const examplesGenerator = require('./examples');
2
- const responsesGenerator = require('./responses');
3
- const parametersGenerator = require('./parameters');
4
- const requestBodyGenerator = require('./requestBody');
5
- const { getTagInfo, getTagsInfo, formatDescriptionTag } = require('../utils/tags');
6
- const {
7
- validRequestBodyMethods: bodyMethods,
8
- validHTTPMethod,
9
- } = require('../utils/httpMethods');
10
- const formatSecurity = require('./security');
11
-
12
- const formatTags = (tags = []) => tags.map(({ description }) => {
13
- const { name } = formatDescriptionTag(description);
14
- return name;
15
- });
16
-
17
- const formatSummary = summary => (summary || {}).description || '';
18
-
19
- const formatDescription = description => (description || {}).description || undefined;
20
-
21
- const setRequestBody = (lowerCaseMethod, bodyValues, requestExamples) => {
22
- const hasBodyValues = bodyValues.length > 0;
23
- const requestBody = requestBodyGenerator(requestExamples, bodyValues);
24
- return bodyMethods[lowerCaseMethod] && hasBodyValues ? { requestBody } : {};
25
- };
26
-
27
- const bodyParams = ({ name }) => name.includes('request.body') || name.includes('.form');
28
-
29
- const getOperationId = operationIdTag => {
30
- if (!operationIdTag) return {};
31
- return {
32
- operationId: operationIdTag.description,
33
- };
34
- };
35
-
36
- const pathValues = tags => {
37
- const examplesValues = getTagsInfo(tags, 'example');
38
- const examples = examplesGenerator(examplesValues);
39
-
40
- const summary = getTagInfo(tags, 'summary');
41
- const description = getTagInfo(tags, 'description');
42
- const deprecated = getTagInfo(tags, 'deprecated');
43
- const isDeprecated = !!deprecated;
44
- /* Response info */
45
- const returnValues = [
46
- ...getTagsInfo(tags, 'return'),
47
- ...getTagsInfo(tags, 'returns'),
48
- ];
49
- const responseExamples = examples.filter(example => example.type === 'response');
50
- const responses = responsesGenerator(returnValues, responseExamples);
51
- /* Parameters info */
52
- const operationId = getTagsInfo(tags, 'operationId');
53
- const paramValues = getTagsInfo(tags, 'param');
54
- const parameters = parametersGenerator(paramValues);
55
- /* Tags info */
56
- const tagsValues = getTagsInfo(tags, 'tags');
57
- /* Security info */
58
- const securityValues = getTagsInfo(tags, 'security');
59
- /* Request body info */
60
- const bodyValues = paramValues.filter(bodyParams);
61
- return {
62
- summary,
63
- description,
64
- isDeprecated,
65
- responses,
66
- parameters,
67
- tagsValues,
68
- bodyValues,
69
- securityValues,
70
- examples,
71
- operationId: operationId[0],
72
- };
73
- };
74
-
75
- const parsePath = (path, state) => {
76
- if (!path.description || !path.tags) return {};
77
- const [method, endpoint] = path.description.split(' ');
78
- // if jsdoc comment does not contain structure <Method> - <Endpoint> is not valid path
79
- const lowerCaseMethod = method.toLowerCase();
80
- if (!validHTTPMethod(lowerCaseMethod)) return {};
81
- const { tags } = path;
82
- const {
83
- summary,
84
- description,
85
- bodyValues,
86
- isDeprecated,
87
- responses,
88
- parameters,
89
- tagsValues,
90
- securityValues,
91
- examples,
92
- operationId,
93
- } = pathValues(tags);
94
- const requestExamples = examples.filter(example => example.type === 'request');
95
- return {
96
- ...state,
97
- [endpoint]: {
98
- ...state[endpoint],
99
- [lowerCaseMethod]: {
100
- deprecated: isDeprecated,
101
- summary: formatSummary(summary),
102
- description: formatDescription(description),
103
- security: formatSecurity(securityValues),
104
- responses,
105
- parameters,
106
- tags: formatTags(tagsValues),
107
- ...(setRequestBody(lowerCaseMethod, bodyValues, requestExamples)),
108
- ...(getOperationId(operationId)),
109
- },
110
- },
111
- };
112
- };
113
-
114
- const getPathObject = paths => paths.reduce((acum, item) => ({
115
- ...acum, ...parsePath(item, acum),
116
- }), {});
117
-
118
- const parsePaths = (swaggerObject = {}, paths = []) => {
119
- if (!paths || !Array.isArray(paths)) return { paths: {} };
120
- const pathObject = getPathObject(paths);
121
- return {
122
- ...swaggerObject,
123
- paths: pathObject,
124
- };
125
- };
126
-
127
- module.exports = parsePaths;
@@ -1,80 +0,0 @@
1
- const errorMessage = require('../utils/errorMessage');
2
- const setProperty = require('../utils/setProperty')('parameter');
3
- const formatDescription = require('../utils/formatDescription');
4
- const getSchema = require('./schema');
5
- const generator = require('../utils/generator');
6
-
7
- const REQUIRED = 'required';
8
- const DEPRECATED = 'deprecated';
9
- const EXPLODE = 'explode';
10
- const NOEXPLODE = 'noexplode';
11
- const BODY_PARAM = 'body';
12
- const FORM_TYPE = 'form';
13
-
14
- const defaultParseParameter = {};
15
-
16
- const parameterPayload = (options, schema) => ({
17
- name: setProperty(options, 'name', {
18
- type: 'string',
19
- required: true,
20
- }),
21
- in: setProperty(options, 'in', {
22
- type: 'string',
23
- required: true,
24
- }),
25
- description: setProperty(options, 'description', {
26
- type: 'string',
27
- defaultValue: '',
28
- }),
29
- required: setProperty(options, 'required', {
30
- type: 'boolean',
31
- defaultValue: false,
32
- }),
33
- deprecated: setProperty(options, 'deprecated', {
34
- type: 'boolean',
35
- defaultValue: false,
36
- }),
37
- explode: setProperty(options, 'explode', {
38
- type: 'boolean',
39
- }),
40
- schema,
41
- });
42
-
43
- const wrongInOption = paramValue => {
44
- if (!paramValue.includes('request.body')) {
45
- errorMessage(`If you want to add one @param as body you must provide "request.body" instead of ${paramValue}`);
46
- }
47
- return defaultParseParameter;
48
- };
49
-
50
- const parseParameter = param => {
51
- const [name, inOption, ...extraOptions] = param.name.split('.');
52
- if (!name || !inOption || inOption === FORM_TYPE) {
53
- return defaultParseParameter;
54
- }
55
- if (inOption === BODY_PARAM) {
56
- return wrongInOption(param.name);
57
- }
58
- const isRequired = extraOptions.includes(REQUIRED);
59
- const isDeprecated = extraOptions.includes(DEPRECATED);
60
- const shouldExplode = extraOptions.includes(EXPLODE);
61
- const shouldNotExplode = extraOptions.includes(NOEXPLODE);
62
- const [description, enumValues, jsonOptions] = formatDescription(param.description);
63
- const options = {
64
- name,
65
- in: inOption,
66
- required: isRequired,
67
- deprecated: isDeprecated,
68
- description,
69
- };
70
- // Used this format because default when undefined is different depending on if it is a query/form or not
71
- if (shouldExplode) {
72
- options.explode = true;
73
- } else if (shouldNotExplode) {
74
- options.explode = false;
75
- }
76
- const schema = getSchema('@param', param.name)(param.type, enumValues, jsonOptions);
77
- return parameterPayload(options, schema);
78
- };
79
-
80
- module.exports = generator(parseParameter, 'name');
@@ -1,65 +0,0 @@
1
- const setProperty = require('../utils/setProperty')('parameter');
2
- const getContent = require('./content')('@paramBody');
3
- const mapDescription = require('../utils/mapDescription');
4
- const formParams = require('./formParams');
5
- const formatExampleValues = require('../utils/formatExamples')('requestBody');
6
-
7
- const REQUIRED = 'required';
8
- const FORM_TYPE = 'form';
9
-
10
- const formatExamples = (exampleValues = []) => exampleValues
11
- .reduce((exampleMap, example, i) => ({
12
- ...exampleMap,
13
- [`example${i + 1}`]: {
14
- summary: example.summary,
15
- value: example.value,
16
- },
17
- }), {});
18
-
19
- const checkExamples = examples => {
20
- const isExample = Array.isArray(examples) && examples.length > 0;
21
- return isExample ? formatExamples(examples) : undefined;
22
- };
23
-
24
- const parseBodyParameter = (currentState, body, examples) => {
25
- const [name, ...extraOptions] = body.name.split('.');
26
- const isRequired = extraOptions.includes(REQUIRED);
27
- const hasForm = extraOptions.includes(FORM_TYPE);
28
- const [description, contentType] = mapDescription(body.description);
29
- const options = { name, required: isRequired, description };
30
-
31
- const examplesParsed = examples.map(example => (
32
- formatExampleValues(example, contentType)
33
- ));
34
-
35
- if (hasForm) {
36
- return formParams(currentState, name, body, isRequired, checkExamples(examplesParsed));
37
- }
38
-
39
- return {
40
- ...currentState,
41
- description: setProperty(options, 'description', {
42
- type: 'string',
43
- }),
44
- required: setProperty(options, 'required', {
45
- type: 'boolean',
46
- defaultValue: false,
47
- }),
48
- content: {
49
- ...currentState.content,
50
- ...getContent(body.type, contentType, body.description, checkExamples(examplesParsed)),
51
- },
52
- };
53
- };
54
-
55
- const INITIAL_STATE = { content: {} };
56
-
57
- const requestBodyGenerator = (examples, params = []) => {
58
- if (!params || !Array.isArray(params)) return {};
59
-
60
- return params.reduce((acc, body) => (
61
- { ...acc, ...parseBodyParameter(acc, body, examples) }
62
- ), INITIAL_STATE);
63
- };
64
-
65
- module.exports = requestBodyGenerator;
@@ -1,55 +0,0 @@
1
- const errorMessage = require('../utils/errorMessage');
2
- const STATUS_CODES = require('./validStatusCodes');
3
- const mapDescription = require('../utils/mapDescription');
4
- const getContent = require('./content')('@return');
5
- const formatExampleValues = require('../utils/formatExamples')('responses');
6
-
7
- const DEFAULT_CONTENT_TYPE = 'application/json';
8
-
9
- const hasOldContent = (value, status) => (value[status] && value[status].content);
10
-
11
- const formatResponses = (values, examples) => values.reduce((acc, value) => {
12
- const [status, description, contentType] = mapDescription(value.description);
13
- if (!STATUS_CODES[status]) {
14
- errorMessage(`Status ${status} is not valid to create a response`);
15
- return {};
16
- }
17
-
18
- const exampleList = formatExampleValues(
19
- examples[status],
20
- contentType || DEFAULT_CONTENT_TYPE,
21
- status,
22
- );
23
-
24
- return {
25
- ...acc,
26
- [status]: {
27
- description,
28
- ...(value.type ? {
29
- content: {
30
- ...(hasOldContent(acc, status) ? { ...acc[status].content } : {}),
31
- ...getContent(value.type, contentType, value.description, exampleList),
32
- },
33
- } : {}),
34
- },
35
- };
36
- }, {});
37
-
38
- const formatExamples = (exampleValues = []) => exampleValues
39
- .reduce((exampleMap, example, i) => ({
40
- ...exampleMap,
41
- [example.status]: {
42
- ...exampleMap[example.status],
43
- [`example${i + 1}`]: {
44
- summary: example.summary,
45
- value: example.value,
46
- },
47
- },
48
- }), {});
49
-
50
- const responsesGenerator = (returnValues = [], exampleValues = []) => {
51
- if (!returnValues || !Array.isArray(returnValues)) return {};
52
- return formatResponses(returnValues, formatExamples(exampleValues));
53
- };
54
-
55
- module.exports = responsesGenerator;
@@ -1,33 +0,0 @@
1
- const errorMessage = require('../utils/errorMessage');
2
- const combineSchema = require('../utils/combineSchema');
3
- const addEnumValues = require('../utils/enumValues');
4
- const { refSchema, formatRefSchema } = require('../utils/refSchema');
5
-
6
- const getSchema = (entity, message) => (type, enumValues = [], jsonOptions = {}) => {
7
- if (!type) {
8
- return errorMessage(`Entity: ${entity} could not be parsed. Value: "${message}" is wrong`);
9
- }
10
- const nameType = type.name;
11
- let schema = {
12
- ...refSchema(nameType),
13
- };
14
-
15
- schema = {
16
- ...schema,
17
- ...combineSchema(type.elements),
18
- ...addEnumValues(enumValues),
19
- ...jsonOptions,
20
- };
21
- const notPrimitiveType = !nameType;
22
- if (notPrimitiveType && !type.elements) {
23
- const parseItems = formatRefSchema(type.applications);
24
- schema = {
25
- ...schema,
26
- type: type.expression.name.toLowerCase(),
27
- items: parseItems.items ? parseItems.items : parseItems,
28
- };
29
- }
30
- return schema;
31
- };
32
-
33
- module.exports = getSchema;
@@ -1,31 +0,0 @@
1
- const { flatArray } = require('../utils/arrays');
2
-
3
- const AND_SEPARATOR = ' & ';
4
- const OR_SEPARATOR = ' | ';
5
-
6
- const formatOrValues = ({ description }) => {
7
- if (!description) { return []; }
8
-
9
- const securityNames = description.split(OR_SEPARATOR);
10
- return securityNames.map(names => ({
11
- description: names,
12
- }));
13
- };
14
-
15
- const formatSecurity = (securityValues = []) => (
16
- flatArray(securityValues
17
- .map(formatOrValues))
18
- .map(({ description }) => {
19
- const securityNames = description.split(AND_SEPARATOR);
20
- return {
21
- ...securityNames.reduce((acum, names) => (
22
- {
23
- ...acum,
24
- [names]: [],
25
- }
26
- ), {}),
27
- };
28
- })
29
- );
30
-
31
- module.exports = formatSecurity;
@@ -1,64 +0,0 @@
1
- const STATUS_CODES = {
2
- 202: 'Accepted',
3
- 502: 'Bad Gateway',
4
- 400: 'Bad Request',
5
- 409: 'Conflict',
6
- 100: 'Continue',
7
- 201: 'Created',
8
- 417: 'Expectation Failed',
9
- 424: 'Failed Dependency',
10
- 403: 'Forbidden',
11
- 504: 'Gateway Timeout',
12
- 410: 'Gone',
13
- 505: 'HTTP Version Not Supported',
14
- 418: 'I\'m a teapot',
15
- 419: 'Insufficient Space on Resource',
16
- 507: 'Insufficient Storage',
17
- 500: 'Server Error',
18
- 411: 'Length Required',
19
- 423: 'Locked',
20
- 420: 'Method Failure',
21
- 405: 'Method Not Allowed',
22
- 301: 'Moved Permanently',
23
- 302: 'Moved Temporarily',
24
- 207: 'Multi-Status',
25
- 300: 'Multiple Choices',
26
- 511: 'Network Authentication Required',
27
- 204: 'No Content',
28
- 203: 'Non Authoritative Information',
29
- 406: 'Not Acceptable',
30
- 404: 'Not Found',
31
- 501: 'Not Implemented',
32
- 304: 'Not Modified',
33
- 200: 'OK',
34
- 206: 'Partial Content',
35
- 402: 'Payment Required',
36
- 308: 'Permanent Redirect',
37
- 412: 'Precondition Failed',
38
- 428: 'Precondition Required',
39
- 102: 'Processing',
40
- 407: 'Proxy Authentication Required',
41
- 431: 'Request Header Fields Too Large',
42
- 408: 'Request Timeout',
43
- 413: 'Request Entity Too Large',
44
- 414: 'Request-URI Too Long',
45
- 416: 'Requested Range Not Satisfiable',
46
- 205: 'Reset Content',
47
- 303: 'See Other',
48
- 503: 'Service Unavailable',
49
- 101: 'Switching Protocols',
50
- 307: 'Temporary Redirect',
51
- 429: 'Too Many Requests',
52
- 401: 'Unauthorized',
53
- 422: 'Unprocessable Entity',
54
- 415: 'Unsupported Media Type',
55
- 305: 'Use Proxy',
56
- '1XX': '1XX Range',
57
- '2XX': '2XX Range',
58
- '3XX': '3XX Range',
59
- '4XX': '4XX Range',
60
- '5XX': '5XX Range',
61
- default: 'Default response',
62
- };
63
-
64
- module.exports = STATUS_CODES;
@@ -1,18 +0,0 @@
1
- const formatSecurity = securitySchemes => {
2
- const securityTypes = Object.keys(securitySchemes);
3
- return securityTypes.map(type => ({ [type]: [] }));
4
- };
5
-
6
- const parseSecuritySchemas = (swaggerObject = {}) => {
7
- const { security } = swaggerObject;
8
- return {
9
- ...swaggerObject,
10
- ...(security ? { security: formatSecurity(security) } : {}),
11
- components: {
12
- ...swaggerObject.components,
13
- ...(security ? { securitySchemes: security } : {}),
14
- },
15
- };
16
- };
17
-
18
- module.exports = parseSecuritySchemas;
@@ -1,41 +0,0 @@
1
- const { getTagsInfo, formatDescriptionTag } = require('../utils/tags');
2
- const { flatArray, getIndexBy } = require('../utils/arrays');
3
-
4
- const FILTER_TAG_KEY = 'name';
5
-
6
- const formatTags = ({ tags = [] }) => {
7
- const infoTags = getTagsInfo(tags, 'tags');
8
- return infoTags.map(({ description: tagDescription }) => {
9
- const { name, description = '' } = formatDescriptionTag(tagDescription);
10
- return {
11
- name,
12
- description,
13
- };
14
- });
15
- };
16
-
17
- const sortByDescription = tags => [...tags].sort((a, b) => {
18
- if (!a.description && b.description) {
19
- return 1;
20
- }
21
- return -1;
22
- });
23
-
24
- const sortTagsByName = tags => [...tags].sort((a, b) => ((a.name > b.name) ? 1 : -1));
25
-
26
- const filterDuplicateTags = tags => (
27
- tags.filter(({ name }, i) => getIndexBy(tags, FILTER_TAG_KEY, name) === i)
28
- );
29
-
30
- const parseTags = (swaggerObject, data) => {
31
- if (!data || !Array.isArray(data)) return { tags: [] };
32
- const tags = flatArray(data.map(formatTags));
33
- const ordererTags = sortByDescription(tags);
34
- const uniqTags = filterDuplicateTags(ordererTags);
35
- return {
36
- ...swaggerObject,
37
- tags: sortTagsByName(uniqTags),
38
- };
39
- };
40
-
41
- module.exports = parseTags;
@@ -1,12 +0,0 @@
1
- const flatArray = elements => (
2
- elements.reduce((acc, val) => acc.concat(val), [])
3
- );
4
-
5
- const getIndexBy = (elements, key, value) => (
6
- elements.findIndex(element => element[key] === value)
7
- );
8
-
9
- module.exports = {
10
- flatArray,
11
- getIndexBy,
12
- };
@@ -1,67 +0,0 @@
1
- const { refSchema } = require('./refSchema');
2
-
3
- const VALID_TYPES = ['oneOf', 'anyOf', 'allOf'];
4
-
5
- /**
6
- * This method checks the first item of the data type list to validate if
7
- * it contains any of the keywords representing the different union types
8
- * in Swagger: 'oneOf', 'anyOf' or 'allOf'.
9
- *
10
- * @param {object[]} elements - List of data types for the property
11
- * @returns {string|null} Name of the union type (if any)
12
- */
13
- const getUnionType = elements => {
14
- const unionType = elements[0].name;
15
-
16
- if (!VALID_TYPES.includes(unionType)) {
17
- return null;
18
- }
19
-
20
- return unionType;
21
- };
22
-
23
- /**
24
- * This method receives an array of data types passed down to the
25
- * 'property' annotation, for example:
26
- *
27
- * > '{oneOf|string|null}'.
28
- *
29
- * The aim of this method is to process this array and generate
30
- * the schema for the property, including a list of its types.
31
- *
32
- * @param {object[]} elements - List of data types for the property
33
- * @returns Swagger schema for the property
34
- */
35
- const combineSchema = elements => {
36
- let schema = {};
37
- if (!elements || elements.length === 0) return schema;
38
-
39
- // Check if 'null' is part of the listed types and remove it from the array
40
- const nullIndex = elements.findIndex(el => el.type === 'NullLiteral');
41
- if (nullIndex > 0) {
42
- elements.splice(nullIndex, 1);
43
- schema = { nullable: true };
44
- }
45
-
46
- const unionType = getUnionType(elements);
47
- const types = !unionType ? elements : elements.slice(1);
48
-
49
- // If there are multiple types in the list, wrap them into a union type
50
- // ('oneOf' will be used by default if none is specified)
51
- if (types.length > 1 || unionType === 'allOf') {
52
- schema = {
53
- ...schema,
54
- [unionType || 'oneOf']: types.map(type => refSchema(type)),
55
- };
56
- } else {
57
- // If there's only a type in the list, don't wrap it in 'oneOf' or 'anyOf' blocks
58
- schema = {
59
- ...schema,
60
- ...refSchema(types[0]),
61
- };
62
- }
63
-
64
- return schema;
65
- };
66
-
67
- module.exports = combineSchema;
@@ -1,6 +0,0 @@
1
- const addEnumValues = (values = []) => {
2
- if (values.length === 0) return {};
3
- return { enum: values };
4
- };
5
-
6
- module.exports = addEnumValues;
@@ -1,8 +0,0 @@
1
- const chalk = require('chalk');
2
-
3
- const errorMessage = message => {
4
- // eslint-disable-next-line
5
- console.warn(chalk.yellow(`[express-jsdoc-swagger] ${message}`));
6
- };
7
-
8
- module.exports = errorMessage;
@@ -1,35 +0,0 @@
1
- const mapDescription = require('./mapDescription');
2
- const errorMessage = require('./errorMessage');
3
-
4
- const ENUM_IDENTIFIER = 'enum:';
5
- const JSON_IDENTIFIER = 'json:';
6
- const DESCRIPTION_DIVIDER = ' - ';
7
-
8
- const formatDescription = description => {
9
- const descriptionTypes = mapDescription(description);
10
- const descriptionValue = descriptionTypes.filter(value => (
11
- !value.includes(ENUM_IDENTIFIER) && !value.includes(JSON_IDENTIFIER)
12
- )).join(DESCRIPTION_DIVIDER);
13
- const enumOption = descriptionTypes.find(value => value.includes(ENUM_IDENTIFIER));
14
- const jsonOption = descriptionTypes.find(value => value.includes(JSON_IDENTIFIER));
15
- const res = [descriptionValue];
16
- if (enumOption) {
17
- const [, enumOptions] = enumOption.split('enum:');
18
- const enumValues = enumOptions.split(',');
19
- res.push(enumValues);
20
- } else {
21
- res.push(undefined);
22
- }
23
- if (jsonOption) {
24
- try {
25
- const jsonOptions = JSON.parse(jsonOption.slice(JSON_IDENTIFIER.length));
26
- if (typeof jsonOptions !== 'object') { throw new Error('options must be object'); }
27
- res.push(jsonOptions);
28
- } catch (err) {
29
- errorMessage(`json options are malformed: ${err.message}`);
30
- }
31
- }
32
- return res;
33
- };
34
-
35
- module.exports = formatDescription;
@@ -1,25 +0,0 @@
1
- const errorMessage = require('./errorMessage');
2
-
3
- const DEFAULT_CONTENT_TYPE = 'application/json';
4
-
5
- const formatJSONExamples = type => (exampleList, contentType, status) => {
6
- let cloneExamples = type === 'requestBody' ? { ...exampleList } : undefined;
7
- if (exampleList && contentType === DEFAULT_CONTENT_TYPE) {
8
- cloneExamples = { ...exampleList };
9
- Object.keys(cloneExamples)
10
- .filter(k => typeof cloneExamples[k].value === 'string')
11
- .forEach(k => {
12
- try {
13
- cloneExamples[k].value = JSON.parse(cloneExamples[k].value);
14
- } catch (err) {
15
- const message = type === 'requestBody'
16
- ? 'requestBody example malformed'
17
- : `response example for status ${status} with content-type ${DEFAULT_CONTENT_TYPE} malformed`;
18
- errorMessage(message);
19
- }
20
- });
21
- }
22
- return cloneExamples;
23
- };
24
-
25
- module.exports = formatJSONExamples;
@@ -1,6 +0,0 @@
1
- const generator = (parseParameter, filterKey) => paramValues => {
2
- if (!paramValues || !Array.isArray(paramValues)) return [];
3
- return paramValues.map(parseParameter).filter(param => param[filterKey]);
4
- };
5
-
6
- module.exports = generator;