swagger-typescript-api 10.0.3 → 11.0.0--alpha
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/README.md +218 -0
- package/index.d.ts +93 -0
- package/index.js +230 -103
- package/package.json +121 -119
- package/src/code-formatter.js +101 -0
- package/src/code-gen-process.js +456 -0
- package/src/configuration.js +425 -0
- package/src/constants.js +14 -31
- package/src/index.js +6 -257
- package/src/schema-components-map.js +60 -0
- package/src/schema-parser/schema-formatters.js +145 -0
- package/src/schema-parser/schema-parser.js +497 -0
- package/src/schema-parser/schema-routes.js +902 -0
- package/src/swagger-schema-resolver.js +187 -0
- package/src/templates.js +141 -122
- package/src/translators/JavaScript.js +49 -49
- package/src/type-name.js +79 -0
- package/src/util/file-system.js +76 -0
- package/src/{utils → util}/id.js +0 -0
- package/src/util/internal-case.js +5 -0
- package/src/util/logger.js +100 -0
- package/src/{utils/resolveName.js → util/name-resolver.js} +1 -1
- package/src/util/object-assign.js +11 -0
- package/src/util/pascal-case.js +5 -0
- package/src/{utils → util}/random.js +1 -1
- package/templates/base/data-contract-jsdoc.ejs +29 -24
- package/templates/base/data-contracts.ejs +3 -3
- package/templates/base/interface-data-contract.ejs +1 -0
- package/templates/base/route-docs.ejs +2 -2
- package/templates/base/route-type.ejs +2 -2
- package/templates/default/route-types.ejs +2 -2
- package/templates/modular/api.ejs +2 -2
- package/templates/modular/route-types.ejs +2 -2
- package/src/apiConfig.js +0 -30
- package/src/common.js +0 -28
- package/src/components.js +0 -91
- package/src/config.js +0 -108
- package/src/filePrefix.js +0 -14
- package/src/files.js +0 -56
- package/src/formatFileContent.js +0 -81
- package/src/logger.js +0 -68
- package/src/modelNames.js +0 -74
- package/src/modelTypes.js +0 -31
- package/src/output.js +0 -165
- package/src/prettierOptions.js +0 -23
- package/src/render/utils/fmtToJSDocLine.js +0 -10
- package/src/render/utils/index.js +0 -31
- package/src/render/utils/templateRequire.js +0 -17
- package/src/routeNames.js +0 -46
- package/src/routes.js +0 -809
- package/src/schema.js +0 -474
- package/src/swagger.js +0 -152
- package/src/typeFormatters.js +0 -121
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const fs = require("fs");
|
|
2
|
+
const makeDir = require("make-dir");
|
|
3
|
+
const { resolve } = require("path");
|
|
4
|
+
const _ = require("lodash");
|
|
5
|
+
|
|
6
|
+
const FILE_PREFIX = `/* eslint-disable */
|
|
7
|
+
/* tslint:disable */
|
|
8
|
+
/*
|
|
9
|
+
* ---------------------------------------------------------------
|
|
10
|
+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
11
|
+
* ## ##
|
|
12
|
+
* ## AUTHOR: acacode ##
|
|
13
|
+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
14
|
+
* ---------------------------------------------------------------
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
class FileSystem {
|
|
20
|
+
constructor() {}
|
|
21
|
+
|
|
22
|
+
getFileContent = (path) => {
|
|
23
|
+
return fs.readFileSync(path, { encoding: "UTF-8" });
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
pathIsDir = (path) => {
|
|
27
|
+
if (!path) return false;
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const stat = fs.statSync(path);
|
|
31
|
+
return stat.isDirectory();
|
|
32
|
+
} catch (e) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
cropExtension = (fileName) => {
|
|
38
|
+
const fileNameParts = _.split(fileName, ".");
|
|
39
|
+
|
|
40
|
+
if (fileNameParts.length > 1) {
|
|
41
|
+
fileNameParts.pop();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return fileNameParts.join(".");
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
removeDir = (path) => {
|
|
48
|
+
try {
|
|
49
|
+
if (typeof fs.rmSync === "function") {
|
|
50
|
+
fs.rmSync(path, { recursive: true });
|
|
51
|
+
} else {
|
|
52
|
+
fs.rmdirSync(path, { recursive: true });
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
createDir = (path) => {
|
|
58
|
+
try {
|
|
59
|
+
makeDir.sync(path);
|
|
60
|
+
} catch (e) {}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
cleanDir = (path) => {
|
|
64
|
+
removeDir(path);
|
|
65
|
+
createDir(path);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
pathIsExist = (path) => path && fs.existsSync(path);
|
|
69
|
+
|
|
70
|
+
createFile = ({ path, fileName, content, withPrefix }) =>
|
|
71
|
+
fs.writeFileSync(resolve(__dirname, path, `./${fileName}`), `${withPrefix ? FILE_PREFIX : ""}${content}`, _.noop);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
module.exports = {
|
|
75
|
+
FileSystem,
|
|
76
|
+
};
|
package/src/{utils → util}/id.js
RENAMED
|
File without changes
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
const { emojify } = require("node-emoji");
|
|
2
|
+
const _ = require("lodash");
|
|
3
|
+
|
|
4
|
+
class Logger {
|
|
5
|
+
firstLog = true;
|
|
6
|
+
/**
|
|
7
|
+
* @type {Configuration}
|
|
8
|
+
*/
|
|
9
|
+
config;
|
|
10
|
+
|
|
11
|
+
constructor(config) {
|
|
12
|
+
this.config = config;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
createLogMessage = ({ type, emojiName, messages }) => {
|
|
16
|
+
if (this.config.silent) return;
|
|
17
|
+
|
|
18
|
+
const emoji = emojify(emojiName);
|
|
19
|
+
|
|
20
|
+
if (this.firstLog) {
|
|
21
|
+
this.firstLog = false;
|
|
22
|
+
this.log(
|
|
23
|
+
`swagger-typescript-api(${this.config.version}),${
|
|
24
|
+
process.env.npm_config_user_agent || `nodejs(${process.version})`
|
|
25
|
+
}`,
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
console[type](
|
|
30
|
+
emoji,
|
|
31
|
+
" ",
|
|
32
|
+
..._.map(messages, (message) =>
|
|
33
|
+
_.startsWith(message, "\n") ? `\n${emoji} ${message.replace(/\n/, "")}` : message,
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
*
|
|
40
|
+
* @param messages {any[]}
|
|
41
|
+
*/
|
|
42
|
+
log = (...messages) =>
|
|
43
|
+
this.createLogMessage({
|
|
44
|
+
type: "log",
|
|
45
|
+
emojiName: ":sparkles:",
|
|
46
|
+
messages,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
*
|
|
51
|
+
* @param messages {any[]}
|
|
52
|
+
* @return {void}
|
|
53
|
+
*/
|
|
54
|
+
event = (...messages) =>
|
|
55
|
+
this.createLogMessage({
|
|
56
|
+
type: "log",
|
|
57
|
+
emojiName: ":comet: ",
|
|
58
|
+
messages,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
*
|
|
63
|
+
* @param messages {any[]}
|
|
64
|
+
* @return {void}
|
|
65
|
+
*/
|
|
66
|
+
success = (...messages) =>
|
|
67
|
+
this.createLogMessage({
|
|
68
|
+
type: "log",
|
|
69
|
+
emojiName: ":white_check_mark:",
|
|
70
|
+
messages,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
*
|
|
75
|
+
* @param messages {any[]}
|
|
76
|
+
* @return {void}
|
|
77
|
+
*/
|
|
78
|
+
warn = (...messages) =>
|
|
79
|
+
this.createLogMessage({
|
|
80
|
+
type: "warn",
|
|
81
|
+
emojiName: ":warning: ",
|
|
82
|
+
messages,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
*
|
|
87
|
+
* @param messages {any[]}
|
|
88
|
+
* @return {void}
|
|
89
|
+
*/
|
|
90
|
+
error = (...messages) =>
|
|
91
|
+
this.createLogMessage({
|
|
92
|
+
type: "error",
|
|
93
|
+
emojiName: ":exclamation:",
|
|
94
|
+
messages,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
Logger,
|
|
100
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const _ = require("lodash");
|
|
2
|
+
|
|
3
|
+
const objectAssign = (target, updaterFn) => {
|
|
4
|
+
if (!updaterFn) return;
|
|
5
|
+
const updated = typeof updaterFn === "function" ? updaterFn(target) : updaterFn;
|
|
6
|
+
Object.assign(target, _.merge(target, updated));
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
module.exports = {
|
|
10
|
+
objectAssign,
|
|
11
|
+
};
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
<%
|
|
2
|
-
const {
|
|
2
|
+
const { data, utils } = it;
|
|
3
3
|
const { formatDescription, require, _ } = utils;
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const stringify = (value) => _.isObject(value) ? JSON.stringify(value) : _.isString(value) ? `"${value}"` : value
|
|
6
6
|
|
|
7
|
-
jsDocLines.
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
7
|
+
const jsDocLines = _.compact([
|
|
8
|
+
data.title,
|
|
9
|
+
data.description && formatDescription(data.description),
|
|
10
|
+
data.deprecated === true && '@deprecated',
|
|
11
|
+
!_.isUndefined(data.format) && `@format ${data.format}`,
|
|
12
|
+
!_.isUndefined(data.minimum) && `@min ${data.minimum}`,
|
|
13
|
+
!_.isUndefined(data.multipleOf) && `@multipleOf ${data.multipleOf}`,
|
|
14
|
+
!_.isUndefined(data.exclusiveMinimum) && `@exclusiveMin ${data.exclusiveMinimum}`,
|
|
15
|
+
!_.isUndefined(data.maximum) && `@max ${data.maximum}`,
|
|
16
|
+
!_.isUndefined(data.minLength) && `@minLength ${data.minLength}`,
|
|
17
|
+
!_.isUndefined(data.maxLength) && `@maxLength ${data.maxLength}`,
|
|
18
|
+
!_.isUndefined(data.exclusiveMaximum) && `@exclusiveMax ${data.exclusiveMaximum}`,
|
|
19
|
+
!_.isUndefined(data.maxItems) && `@maxItems ${data.maxItems}`,
|
|
20
|
+
!_.isUndefined(data.minItems) && `@minItems ${data.minItems}`,
|
|
21
|
+
!_.isUndefined(data.uniqueItems) && `@uniqueItems ${data.uniqueItems}`,
|
|
22
|
+
!_.isUndefined(data.default) && `@default ${stringify(data.default)}`,
|
|
23
|
+
!_.isUndefined(data.pattern) && `@pattern ${data.pattern}`,
|
|
24
|
+
!_.isUndefined(data.example) && `@example ${stringify(data.example)}`
|
|
25
|
+
]).join('\n').split('\n');
|
|
26
26
|
%>
|
|
27
|
-
<% if (jsDocLines.
|
|
27
|
+
<% if (jsDocLines.every(_.isEmpty)) { %>
|
|
28
|
+
<% } else if (jsDocLines.length === 1) { %>
|
|
29
|
+
/** <%~ jsDocLines[0] %> */
|
|
30
|
+
<% } else if (jsDocLines.length) { %>
|
|
28
31
|
/**
|
|
29
|
-
|
|
32
|
+
<% for (jsDocLine of jsDocLines) { %>
|
|
33
|
+
* <%~ jsDocLine %>
|
|
30
34
|
|
|
31
|
-
*/
|
|
32
35
|
<% } %>
|
|
36
|
+
*/
|
|
37
|
+
<% } %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { modelTypes, utils, config } = it;
|
|
3
|
-
const { formatDescription, require, _ } = utils;
|
|
3
|
+
const { formatDescription, require, _, Ts } = utils;
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const dataContractTemplates = {
|
|
@@ -17,11 +17,11 @@ const dataContractTemplates = {
|
|
|
17
17
|
%>
|
|
18
18
|
|
|
19
19
|
<% if (config.internalTemplateOptions.addUtilRequiredKeysType) { %>
|
|
20
|
-
type UtilRequiredKeys
|
|
20
|
+
type <%~ config.Ts.CodeGenKeyword.UtilRequiredKeys %><T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>
|
|
21
21
|
<% } %>
|
|
22
22
|
|
|
23
23
|
<% modelTypes.forEach((contract) => { %>
|
|
24
|
-
<%~ includeFile('@base/data-contract-jsdoc.ejs', { ...it, contract }) %>
|
|
24
|
+
<%~ includeFile('@base/data-contract-jsdoc.ejs', { ...it, data: { ...contract, ...contract.typeData } }) %>
|
|
25
25
|
export <%~ (dataContractTemplates[contract.typeIdentifier] || dataContractTemplates.type)(contract) %>
|
|
26
26
|
|
|
27
27
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { config, route, utils } = it;
|
|
3
|
-
const { _, formatDescription, fmtToJSDocLine,
|
|
3
|
+
const { _, formatDescription, fmtToJSDocLine, pascalCase, require } = utils;
|
|
4
4
|
const { raw, request, routeName } = route;
|
|
5
5
|
|
|
6
6
|
const jsDocDescription = raw.description ?
|
|
@@ -8,7 +8,7 @@ const jsDocDescription = raw.description ?
|
|
|
8
8
|
fmtToJSDocLine('No description', { eol: false });
|
|
9
9
|
const jsDocLines = _.compact([
|
|
10
10
|
_.size(raw.tags) && ` * @tags ${raw.tags.join(", ")}`,
|
|
11
|
-
` * @name ${
|
|
11
|
+
` * @name ${pascalCase(routeName.usage)}`,
|
|
12
12
|
raw.summary && ` * @summary ${raw.summary}`,
|
|
13
13
|
` * @request ${_.upperCase(request.method)}:${raw.route}`,
|
|
14
14
|
raw.deprecated && ` * @deprecated`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { route, utils, config } = it;
|
|
3
|
-
const { _,
|
|
3
|
+
const { _, pascalCase, require } = utils;
|
|
4
4
|
const { query, payload, pathParams, headers } = route.request;
|
|
5
5
|
|
|
6
6
|
const routeDocs = includeFile("@base/route-docs", { config, route, utils });
|
|
7
|
-
const routeNamespace =
|
|
7
|
+
const routeNamespace = pascalCase(route.routeName.usage);
|
|
8
8
|
|
|
9
9
|
%>
|
|
10
10
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { utils, config, routes, modelTypes } = it;
|
|
3
|
-
const { _,
|
|
3
|
+
const { _, pascalCase } = utils;
|
|
4
4
|
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
5
5
|
%>
|
|
6
6
|
|
|
@@ -19,7 +19,7 @@ import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataCont
|
|
|
19
19
|
<% }) %>
|
|
20
20
|
|
|
21
21
|
<% routes.combined && routes.combined.forEach(({ routes = [], moduleName }) => { %>
|
|
22
|
-
export namespace <%~
|
|
22
|
+
export namespace <%~ pascalCase(moduleName) %> {
|
|
23
23
|
<% routes.forEach((route) => { %>
|
|
24
24
|
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
|
25
25
|
<% }) %>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { utils, route, config, modelTypes } = it;
|
|
3
|
-
const { _,
|
|
4
|
-
const apiClassName =
|
|
3
|
+
const { _, pascalCase, require } = utils;
|
|
4
|
+
const apiClassName = pascalCase(route.moduleName);
|
|
5
5
|
const routes = route.routes;
|
|
6
6
|
const dataContracts = _.map(modelTypes, "name");
|
|
7
7
|
%>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<%
|
|
2
2
|
const { utils, config, route, modelTypes } = it;
|
|
3
|
-
const { _,
|
|
3
|
+
const { _, pascalCase } = utils;
|
|
4
4
|
const { routes, moduleName } = route;
|
|
5
5
|
const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ const dataContracts = config.modular ? _.map(modelTypes, "name") : [];
|
|
|
9
9
|
import { <%~ dataContracts.join(", ") %> } from "./<%~ config.fileNames.dataContracts %>"
|
|
10
10
|
<% } %>
|
|
11
11
|
|
|
12
|
-
export namespace <%~
|
|
12
|
+
export namespace <%~ pascalCase(moduleName) %> {
|
|
13
13
|
<% _.forEach(routes, (route) => { %>
|
|
14
14
|
|
|
15
15
|
<%~ includeFile('@base/route-type.ejs', { ...it, route }) %>
|
package/src/apiConfig.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
|
|
3
|
-
const createApiConfig = (swaggerSchema) => {
|
|
4
|
-
const { info, servers, host, basePath, externalDocs, tags } = swaggerSchema;
|
|
5
|
-
const server = (servers && servers[0]) || { url: "" };
|
|
6
|
-
const { title = "No title", version, description: schemaDescription = "" } = info || {};
|
|
7
|
-
const { url: serverUrl } = server;
|
|
8
|
-
|
|
9
|
-
return {
|
|
10
|
-
info: info || {},
|
|
11
|
-
servers: servers || [],
|
|
12
|
-
basePath,
|
|
13
|
-
host,
|
|
14
|
-
externalDocs: _.merge(
|
|
15
|
-
{
|
|
16
|
-
url: "",
|
|
17
|
-
description: "",
|
|
18
|
-
},
|
|
19
|
-
externalDocs,
|
|
20
|
-
),
|
|
21
|
-
tags: _.compact(tags),
|
|
22
|
-
baseUrl: serverUrl,
|
|
23
|
-
title,
|
|
24
|
-
version,
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
module.exports = {
|
|
29
|
-
createApiConfig,
|
|
30
|
-
};
|
package/src/common.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
|
|
3
|
-
module.exports = {
|
|
4
|
-
formatDescription: (description, inline) => {
|
|
5
|
-
if (!description) return "";
|
|
6
|
-
|
|
7
|
-
let prettified = description;
|
|
8
|
-
|
|
9
|
-
prettified = _.replace(prettified, /\*\//g, "*/");
|
|
10
|
-
|
|
11
|
-
const hasMultipleLines = _.includes(prettified, "\n");
|
|
12
|
-
|
|
13
|
-
if (!hasMultipleLines) return prettified;
|
|
14
|
-
|
|
15
|
-
if (inline) {
|
|
16
|
-
return _(prettified)
|
|
17
|
-
.split(/\n/g)
|
|
18
|
-
.map((part) => _.trim(part))
|
|
19
|
-
.compact()
|
|
20
|
-
.join(" ")
|
|
21
|
-
.valueOf();
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return _.replace(prettified, /\n$/g, "");
|
|
25
|
-
},
|
|
26
|
-
internalCase: (value) => _.camelCase(_.lowerCase(value)),
|
|
27
|
-
classNameCase: (value) => _.upperFirst(_.camelCase(value)),
|
|
28
|
-
};
|
package/src/components.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
const _ = require("lodash");
|
|
2
|
-
const { parseSchema } = require("./schema");
|
|
3
|
-
const { config } = require("./config");
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {"schemas" | "examples" | "headers" | "parameters" | "requestBodies" | "responses" | "securitySchemes"} ComponentName
|
|
7
|
-
* @typedef {object} RawTypeData
|
|
8
|
-
* @typedef {{ type, typeIdentifier, name, description, content }} TypeData
|
|
9
|
-
*
|
|
10
|
-
* @typedef {{
|
|
11
|
-
* typeName: string;
|
|
12
|
-
* componentName: ComponentName;
|
|
13
|
-
* rawTypeData: RawTypeData;
|
|
14
|
-
* typeData: TypeData | null;
|
|
15
|
-
* }} TypeInfo
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
*
|
|
20
|
-
* @param {ComponentName} componentName
|
|
21
|
-
* @param {string} typeName
|
|
22
|
-
* @param {RawTypeData} rawTypeData
|
|
23
|
-
* @returns {TypeInfo}
|
|
24
|
-
*/
|
|
25
|
-
const createComponent = (componentName, typeName, rawTypeData) => {
|
|
26
|
-
const $ref = `#/components/${componentName}/${typeName}`;
|
|
27
|
-
|
|
28
|
-
const componentSchema = {
|
|
29
|
-
$ref,
|
|
30
|
-
typeName,
|
|
31
|
-
rawTypeData,
|
|
32
|
-
componentName,
|
|
33
|
-
typeData: null,
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const usageComponent = config.hooks.onCreateComponent(componentSchema) || componentSchema;
|
|
37
|
-
|
|
38
|
-
config.componentsMap[$ref] = usageComponent;
|
|
39
|
-
|
|
40
|
-
return usageComponent;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @returns {{ [key: string]: TypeInfo }}
|
|
45
|
-
*/
|
|
46
|
-
const createComponentsMap = (components) => {
|
|
47
|
-
config.componentsMap = {};
|
|
48
|
-
|
|
49
|
-
_.each(components, (component, componentName) =>
|
|
50
|
-
_.each(component, (rawTypeData, typeName) => createComponent(componentName, typeName, rawTypeData)),
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
return config.componentsMap;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @param {{ [key: string]: TypeInfo }} componentsMap
|
|
59
|
-
* @param {ComponentName} componentName
|
|
60
|
-
* @returns {TypeInfo[]}
|
|
61
|
-
*/
|
|
62
|
-
const filterComponentsMap = (componentsMap, componentName) =>
|
|
63
|
-
_.filter(componentsMap, (v, ref) => _.startsWith(ref, `#/components/${componentName}`));
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
*
|
|
67
|
-
* @param {TypeInfo} typeInfo
|
|
68
|
-
* @returns {TypeData}
|
|
69
|
-
*/
|
|
70
|
-
const getTypeData = (typeInfo) => {
|
|
71
|
-
if (!typeInfo.typeData) {
|
|
72
|
-
typeInfo.typeData = parseSchema(typeInfo.rawTypeData, typeInfo.typeName);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return typeInfo.typeData;
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
*
|
|
80
|
-
* @param {string} ref
|
|
81
|
-
* @returns {TypeInfo | null}
|
|
82
|
-
*/
|
|
83
|
-
const getComponentByRef = (ref) => config.componentsMap[ref] || null;
|
|
84
|
-
|
|
85
|
-
module.exports = {
|
|
86
|
-
getTypeData,
|
|
87
|
-
createComponent,
|
|
88
|
-
createComponentsMap,
|
|
89
|
-
filterComponentsMap,
|
|
90
|
-
getComponentByRef,
|
|
91
|
-
};
|
package/src/config.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const { HTTP_CLIENT, TS_KEYWORDS, PRETTIER_OPTIONS } = require("./constants");
|
|
2
|
-
const { NameResolver } = require("./utils/resolveName");
|
|
3
|
-
const packageJson = require("../package.json");
|
|
4
|
-
|
|
5
|
-
const config = {
|
|
6
|
-
version: packageJson.version,
|
|
7
|
-
/** CLI flag */
|
|
8
|
-
templates: "../templates/default",
|
|
9
|
-
/** CLI flag */
|
|
10
|
-
generateResponses: false,
|
|
11
|
-
/** CLI flag */
|
|
12
|
-
defaultResponseAsSuccess: false,
|
|
13
|
-
/** CLI flag */
|
|
14
|
-
generateRouteTypes: false,
|
|
15
|
-
/** CLI flag */
|
|
16
|
-
generateClient: true,
|
|
17
|
-
/** CLI flag */
|
|
18
|
-
generateUnionEnums: false,
|
|
19
|
-
/** CLI flag */
|
|
20
|
-
addReadonly: false,
|
|
21
|
-
enumNamesAsValues: false,
|
|
22
|
-
/** parsed swagger schema from getSwaggerObject() */
|
|
23
|
-
|
|
24
|
-
/** parsed swagger schema ref */
|
|
25
|
-
swaggerSchema: null,
|
|
26
|
-
/** original (converted to json) swagger schema ref */
|
|
27
|
-
originalSchema: null,
|
|
28
|
-
|
|
29
|
-
/** { "#/components/schemas/Foo": @TypeInfo, ... } */
|
|
30
|
-
componentsMap: {},
|
|
31
|
-
/** flag for catching convertion from swagger 2.0 */
|
|
32
|
-
convertedFromSwagger2: false,
|
|
33
|
-
|
|
34
|
-
/** url index from paths used for merging into modules */
|
|
35
|
-
moduleNameIndex: 0,
|
|
36
|
-
|
|
37
|
-
/** use the first tag for the module name */
|
|
38
|
-
moduleNameFirstTag: false,
|
|
39
|
-
disableStrictSSL: false,
|
|
40
|
-
disableProxy: false,
|
|
41
|
-
extractRequestParams: false,
|
|
42
|
-
extractRequestBody: false,
|
|
43
|
-
extractResponseBody: false,
|
|
44
|
-
extractResponseError: false,
|
|
45
|
-
fileNames: {
|
|
46
|
-
dataContracts: "data-contracts",
|
|
47
|
-
routeTypes: "route-types",
|
|
48
|
-
httpClient: "http-client",
|
|
49
|
-
outOfModuleApi: "Common",
|
|
50
|
-
},
|
|
51
|
-
routeNameDuplicatesMap: new Map(),
|
|
52
|
-
prettierOptions: PRETTIER_OPTIONS,
|
|
53
|
-
hooks: {
|
|
54
|
-
onCreateComponent: (schema) => schema,
|
|
55
|
-
onParseSchema: (originalSchema, parsedSchema) => parsedSchema,
|
|
56
|
-
onCreateRoute: (routeData) => routeData,
|
|
57
|
-
onInit: (config) => config,
|
|
58
|
-
onPrepareConfig: (apiConfig) => apiConfig,
|
|
59
|
-
onCreateRequestParams: (rawType) => {},
|
|
60
|
-
onCreateRouteName: () => {},
|
|
61
|
-
onFormatTypeName: (typeName, rawTypeName) => {},
|
|
62
|
-
onFormatRouteName: (routeInfo, templateRouteName) => {},
|
|
63
|
-
},
|
|
64
|
-
defaultResponseType: TS_KEYWORDS.VOID,
|
|
65
|
-
singleHttpClient: false,
|
|
66
|
-
httpClientType: HTTP_CLIENT.FETCH,
|
|
67
|
-
unwrapResponseData: false,
|
|
68
|
-
disableThrowOnError: false,
|
|
69
|
-
sortTypes: false,
|
|
70
|
-
templatePaths: {
|
|
71
|
-
/** `templates/base` */
|
|
72
|
-
base: "",
|
|
73
|
-
/** `templates/default` */
|
|
74
|
-
default: "",
|
|
75
|
-
/** `templates/modular` */
|
|
76
|
-
modular: "",
|
|
77
|
-
/** usage path if `--templates` option is not set */
|
|
78
|
-
original: "",
|
|
79
|
-
/** custom path to templates (`--templates`) */
|
|
80
|
-
custom: "",
|
|
81
|
-
},
|
|
82
|
-
/** Record<templateName, templateContent> */
|
|
83
|
-
templatesToRender: {
|
|
84
|
-
api: "",
|
|
85
|
-
dataContracts: "",
|
|
86
|
-
httpClient: "",
|
|
87
|
-
routeTypes: "",
|
|
88
|
-
routeName: "",
|
|
89
|
-
},
|
|
90
|
-
toJS: false,
|
|
91
|
-
silent: false,
|
|
92
|
-
typePrefix: "",
|
|
93
|
-
typeSuffix: "",
|
|
94
|
-
patch: false,
|
|
95
|
-
componentTypeNameResolver: new NameResolver([]),
|
|
96
|
-
/** name of the main exported class */
|
|
97
|
-
apiClassName: "Api",
|
|
98
|
-
debug: false,
|
|
99
|
-
internalTemplateOptions: {
|
|
100
|
-
addUtilRequiredKeysType: false,
|
|
101
|
-
},
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/** needs to use data everywhere in project */
|
|
105
|
-
module.exports = {
|
|
106
|
-
addToConfig: (configParts) => Object.assign(config, configParts),
|
|
107
|
-
config,
|
|
108
|
-
};
|
package/src/filePrefix.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
filePrefix: `/* eslint-disable */
|
|
3
|
-
/* tslint:disable */
|
|
4
|
-
/*
|
|
5
|
-
* ---------------------------------------------------------------
|
|
6
|
-
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
7
|
-
* ## ##
|
|
8
|
-
* ## AUTHOR: acacode ##
|
|
9
|
-
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
|
|
10
|
-
* ---------------------------------------------------------------
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
`,
|
|
14
|
-
};
|