swagger-typescript-api 13.0.9 → 13.0.10
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/dist/chunk-3S356DIU.cjs +105 -0
- package/dist/chunk-3S356DIU.cjs.map +1 -0
- package/dist/chunk-MTWJNW6B.js +65 -0
- package/dist/chunk-MTWJNW6B.js.map +1 -0
- package/dist/cli.cjs +43 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.js +36 -0
- package/dist/cli.js.map +1 -0
- package/dist/lib.cjs +21 -0
- package/dist/lib.cjs.map +1 -0
- package/dist/lib.js +4 -0
- package/dist/lib.js.map +1 -0
- package/package.json +25 -14
- package/cli/constants.js +0 -6
- package/cli/execute.js +0 -180
- package/cli/index.js +0 -94
- package/cli/operations/display-help.js +0 -177
- package/cli/operations/display-version.js +0 -5
- package/cli/parse-args.js +0 -24
- package/cli/process-option.js +0 -75
- package/index.js +0 -344
- package/src/code-formatter.js +0 -114
- package/src/code-gen-process.js +0 -569
- package/src/commands/generate-templates/configuration.js +0 -31
- package/src/commands/generate-templates/index.js +0 -10
- package/src/commands/generate-templates/templates-gen-process.js +0 -205
- package/src/component-type-name-resolver.js +0 -42
- package/src/configuration.js +0 -445
- package/src/constants.js +0 -77
- package/src/index.js +0 -16
- package/src/schema-components-map.js +0 -76
- package/src/schema-parser/base-schema-parsers/array.js +0 -41
- package/src/schema-parser/base-schema-parsers/complex.js +0 -49
- package/src/schema-parser/base-schema-parsers/discriminator.js +0 -305
- package/src/schema-parser/base-schema-parsers/enum.js +0 -156
- package/src/schema-parser/base-schema-parsers/object.js +0 -103
- package/src/schema-parser/base-schema-parsers/primitive.js +0 -61
- package/src/schema-parser/complex-schema-parsers/all-of.js +0 -26
- package/src/schema-parser/complex-schema-parsers/any-of.js +0 -27
- package/src/schema-parser/complex-schema-parsers/not.js +0 -9
- package/src/schema-parser/complex-schema-parsers/one-of.js +0 -27
- package/src/schema-parser/mono-schema-parser.js +0 -46
- package/src/schema-parser/schema-formatters.js +0 -164
- package/src/schema-parser/schema-parser-fabric.js +0 -130
- package/src/schema-parser/schema-parser.js +0 -295
- package/src/schema-parser/schema-utils.js +0 -319
- package/src/schema-parser/util/enum-key-resolver.js +0 -24
- package/src/schema-routes/schema-routes.js +0 -1208
- package/src/schema-routes/util/specific-arg-name-resolver.js +0 -24
- package/src/schema-walker.js +0 -91
- package/src/swagger-schema-resolver.js +0 -195
- package/src/templates-worker.js +0 -243
- package/src/translators/javascript.js +0 -81
- package/src/translators/translator.js +0 -33
- package/src/type-name-formatter.js +0 -111
- package/src/util/file-system.js +0 -95
- package/src/util/id.js +0 -7
- package/src/util/internal-case.js +0 -7
- package/src/util/logger.js +0 -142
- package/src/util/name-resolver.js +0 -103
- package/src/util/object-assign.js +0 -17
- package/src/util/pascal-case.js +0 -7
- package/src/util/random.js +0 -11
- package/src/util/request.js +0 -63
- package/src/util/sort-by-property.js +0 -15
package/cli/index.js
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
import { reservedOptions, root_command } from "./constants.js";
|
|
3
|
-
import { execute } from "./execute.js";
|
|
4
|
-
import { displayHelp } from "./operations/display-help.js";
|
|
5
|
-
import { displayVersion } from "./operations/display-version.js";
|
|
6
|
-
import { processOption } from "./process-option.js";
|
|
7
|
-
|
|
8
|
-
const cli = (input) => {
|
|
9
|
-
const commands = {};
|
|
10
|
-
|
|
11
|
-
const addCommand = (command, { addVersion = false, addHelp = true } = {}) => {
|
|
12
|
-
commands[command.name] = {
|
|
13
|
-
name: command.name,
|
|
14
|
-
description: `${command.description || ""}`,
|
|
15
|
-
options: _.compact(_.map(command.options, processOption)),
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
if (addVersion) {
|
|
19
|
-
commands[command.name].options.unshift(
|
|
20
|
-
processOption({
|
|
21
|
-
flags: "-v, --version",
|
|
22
|
-
description: "output the current version",
|
|
23
|
-
operation: () => displayVersion(instance),
|
|
24
|
-
}),
|
|
25
|
-
);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (addHelp) {
|
|
29
|
-
commands[command.name].options.push(
|
|
30
|
-
processOption({
|
|
31
|
-
flags: "-h, --help",
|
|
32
|
-
description: "display help for command",
|
|
33
|
-
operation: () =>
|
|
34
|
-
displayHelp(commands, instance, commands[command.name]),
|
|
35
|
-
}),
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return instance;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const instance = {
|
|
43
|
-
commands,
|
|
44
|
-
input,
|
|
45
|
-
addCommand,
|
|
46
|
-
execute: (params) => execute(params, commands, instance),
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
addCommand(
|
|
50
|
-
{
|
|
51
|
-
name: root_command,
|
|
52
|
-
options: [],
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
addVersion: false,
|
|
56
|
-
addHelp: false,
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
_.forEach(input.options, (option) => {
|
|
61
|
-
const processed = processOption(option);
|
|
62
|
-
|
|
63
|
-
if (!processed) return;
|
|
64
|
-
|
|
65
|
-
if (reservedOptions.includes(processed.name)) {
|
|
66
|
-
console.warn("reserved option", processed.name);
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
commands[root_command].options.push(processed);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
commands[root_command].options.unshift(
|
|
74
|
-
processOption({
|
|
75
|
-
flags: "-v, --version",
|
|
76
|
-
description: "output the current version",
|
|
77
|
-
operation: () => displayVersion(instance),
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
commands[root_command].options.push(
|
|
82
|
-
processOption({
|
|
83
|
-
flags: "-h, --help",
|
|
84
|
-
description: "display help for command",
|
|
85
|
-
operation: () => displayHelp(commands, instance, commands[root_command]),
|
|
86
|
-
}),
|
|
87
|
-
);
|
|
88
|
-
|
|
89
|
-
_.forEach(input.commands, addCommand);
|
|
90
|
-
|
|
91
|
-
return instance;
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
export { cli };
|
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
import { root_command } from "../constants.js";
|
|
3
|
-
|
|
4
|
-
const generateOptionsOutput = (options) =>
|
|
5
|
-
options.reduce(
|
|
6
|
-
(acc, option) => {
|
|
7
|
-
const flags = `${option.flags.keys.join(", ")}${
|
|
8
|
-
option.flags.value?.raw ? ` ${option.flags.value?.raw}` : ""
|
|
9
|
-
}`;
|
|
10
|
-
const description = `${option.description || ""}${
|
|
11
|
-
option.default === undefined ||
|
|
12
|
-
(option.flags.isNoFlag && option.default === true)
|
|
13
|
-
? ""
|
|
14
|
-
: ` (default: ${
|
|
15
|
-
typeof option.default === "string"
|
|
16
|
-
? `"${option.default}"`
|
|
17
|
-
: option.default
|
|
18
|
-
})`
|
|
19
|
-
}`;
|
|
20
|
-
|
|
21
|
-
if (flags.length > acc.maxLength) {
|
|
22
|
-
acc.maxLength = flags.length;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
acc.options.push({
|
|
26
|
-
flags,
|
|
27
|
-
description,
|
|
28
|
-
});
|
|
29
|
-
return acc;
|
|
30
|
-
},
|
|
31
|
-
{
|
|
32
|
-
options: [],
|
|
33
|
-
maxLength: 0,
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const generateOptionsTextOutput = (options, maxLength, spaces) =>
|
|
38
|
-
options
|
|
39
|
-
.map((option) => {
|
|
40
|
-
const spacesText = Array(spaces).fill(" ").join("");
|
|
41
|
-
const leftStr = `${spacesText}${option.flags.padEnd(maxLength, " ")} `;
|
|
42
|
-
const leftStrFiller = Array(leftStr.length).fill(" ").join("");
|
|
43
|
-
const descriptionLines = option.description.split("\n");
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
leftStr +
|
|
47
|
-
descriptionLines
|
|
48
|
-
.map((line, i) => {
|
|
49
|
-
if (i === 0) {
|
|
50
|
-
return line;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return `\n${leftStrFiller}${line}`;
|
|
54
|
-
})
|
|
55
|
-
.join("")
|
|
56
|
-
);
|
|
57
|
-
})
|
|
58
|
-
.join("\n");
|
|
59
|
-
|
|
60
|
-
const displayAllHelp = (commands, instance) => {
|
|
61
|
-
const { options, maxLength: maxOptionLength } = generateOptionsOutput(
|
|
62
|
-
commands[root_command].options,
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
const { commands: commandLabels, maxLength: maxCommandLength } = _.filter(
|
|
66
|
-
commands,
|
|
67
|
-
(command) => command.name !== root_command,
|
|
68
|
-
).reduce(
|
|
69
|
-
(acc, command) => {
|
|
70
|
-
const options = generateOptionsOutput(command.options);
|
|
71
|
-
const name = `${command.name}${options.length ? " [options]" : ""}`;
|
|
72
|
-
const description = command.description;
|
|
73
|
-
|
|
74
|
-
const maxLength = Math.max(name.length, options.maxLength);
|
|
75
|
-
if (maxLength > acc.maxLength) {
|
|
76
|
-
acc.maxLength = maxLength;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
acc.commands.push({
|
|
80
|
-
description,
|
|
81
|
-
name,
|
|
82
|
-
options,
|
|
83
|
-
});
|
|
84
|
-
return acc;
|
|
85
|
-
},
|
|
86
|
-
{
|
|
87
|
-
commands: [],
|
|
88
|
-
maxLength: maxOptionLength,
|
|
89
|
-
},
|
|
90
|
-
);
|
|
91
|
-
|
|
92
|
-
const optionsOutput = generateOptionsTextOutput(options, maxOptionLength, 2);
|
|
93
|
-
|
|
94
|
-
const commandsOutput = commandLabels
|
|
95
|
-
.map((commandLabel) => {
|
|
96
|
-
const leftStr = ` ${commandLabel.name.padEnd(
|
|
97
|
-
maxCommandLength,
|
|
98
|
-
" ",
|
|
99
|
-
)} `;
|
|
100
|
-
const leftStrFiller = Array(leftStr.length).fill(" ").join("");
|
|
101
|
-
const descriptionLines = commandLabel.description.split("\n");
|
|
102
|
-
const optionsTextOutput = generateOptionsTextOutput(
|
|
103
|
-
commandLabel.options.options,
|
|
104
|
-
maxCommandLength,
|
|
105
|
-
4,
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
return (
|
|
109
|
-
leftStr +
|
|
110
|
-
descriptionLines
|
|
111
|
-
.map((line, i) => {
|
|
112
|
-
if (i === 0) {
|
|
113
|
-
return line;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return `\n${leftStrFiller}${line}`;
|
|
117
|
-
})
|
|
118
|
-
.join("") +
|
|
119
|
-
(optionsTextOutput.length ? `\n${optionsTextOutput}` : "")
|
|
120
|
-
);
|
|
121
|
-
})
|
|
122
|
-
.join("\n");
|
|
123
|
-
|
|
124
|
-
const outputTest = [
|
|
125
|
-
optionsOutput &&
|
|
126
|
-
`Options:
|
|
127
|
-
${optionsOutput}`,
|
|
128
|
-
commandsOutput &&
|
|
129
|
-
`Commands:
|
|
130
|
-
${commandsOutput}`,
|
|
131
|
-
]
|
|
132
|
-
.filter(Boolean)
|
|
133
|
-
.join("\n\n");
|
|
134
|
-
|
|
135
|
-
console.log(`Usage: ${[instance.input.name, instance.input.alias]
|
|
136
|
-
.filter(Boolean)
|
|
137
|
-
.join("|")}${optionsOutput ? " [options]" : ""}${
|
|
138
|
-
commandsOutput ? " [command]" : ""
|
|
139
|
-
}
|
|
140
|
-
${
|
|
141
|
-
instance.input.description &&
|
|
142
|
-
`
|
|
143
|
-
${instance.input.description}`
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
${outputTest}`);
|
|
147
|
-
};
|
|
148
|
-
|
|
149
|
-
const displayHelp = (commands, instance, command) => {
|
|
150
|
-
if (command.name === root_command) return displayAllHelp(commands, instance);
|
|
151
|
-
|
|
152
|
-
const { options, maxLength: maxOptionLength } = generateOptionsOutput(
|
|
153
|
-
command.options,
|
|
154
|
-
);
|
|
155
|
-
const optionsOutput = generateOptionsTextOutput(options, maxOptionLength, 2);
|
|
156
|
-
|
|
157
|
-
const outputTest = [
|
|
158
|
-
optionsOutput &&
|
|
159
|
-
`Options:
|
|
160
|
-
${optionsOutput}`,
|
|
161
|
-
]
|
|
162
|
-
.filter(Boolean)
|
|
163
|
-
.join("\n\n");
|
|
164
|
-
|
|
165
|
-
console.log(`Usage: ${instance.input.name} ${command.name}${
|
|
166
|
-
optionsOutput ? " [options]" : ""
|
|
167
|
-
}
|
|
168
|
-
${
|
|
169
|
-
command.description &&
|
|
170
|
-
`
|
|
171
|
-
${command.description}`
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
${outputTest}`);
|
|
175
|
-
};
|
|
176
|
-
|
|
177
|
-
export { displayHelp };
|
package/cli/parse-args.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const parseArgs = (args, type) => {
|
|
2
|
-
if (args == null || !Array.isArray(args)) {
|
|
3
|
-
throw "args should be array";
|
|
4
|
-
}
|
|
5
|
-
const argsCopy = args.slice();
|
|
6
|
-
|
|
7
|
-
switch (type) {
|
|
8
|
-
case "electron": {
|
|
9
|
-
if (process.defaultApp) {
|
|
10
|
-
return argsCopy.slice(2);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return argsCopy.slice(1);
|
|
14
|
-
}
|
|
15
|
-
case "user": {
|
|
16
|
-
return argsCopy;
|
|
17
|
-
}
|
|
18
|
-
default: {
|
|
19
|
-
return argsCopy.slice(2);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { parseArgs };
|
package/cli/process-option.js
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import _ from "lodash";
|
|
2
|
-
|
|
3
|
-
const optionFormatters = {
|
|
4
|
-
number: (str) => +str,
|
|
5
|
-
numeric: (str) => +str,
|
|
6
|
-
str: (str) => `${str}`,
|
|
7
|
-
string: (str) => `${str}`,
|
|
8
|
-
bool: (str) => !!str,
|
|
9
|
-
boolean: (str) => !!str,
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const processFlags = (flags) => {
|
|
13
|
-
let name = null;
|
|
14
|
-
const keys = [];
|
|
15
|
-
let value = null;
|
|
16
|
-
const isNoFlag = flags.includes("--no-");
|
|
17
|
-
|
|
18
|
-
_.compact(_.split(flags, " ").map((str) => str.replace(/,/g, ""))).forEach(
|
|
19
|
-
(str) => {
|
|
20
|
-
if (str.startsWith("-")) {
|
|
21
|
-
keys.push(str);
|
|
22
|
-
} else if (value === null) {
|
|
23
|
-
if (str.startsWith("{") || str.startsWith("[") || str.startsWith("<")) {
|
|
24
|
-
const rawValue = str.replace(/[{[<>}\].]/g, "");
|
|
25
|
-
const variadic = str.includes("...");
|
|
26
|
-
value = {
|
|
27
|
-
raw: str,
|
|
28
|
-
variadic,
|
|
29
|
-
name: rawValue,
|
|
30
|
-
formatter: optionFormatters[rawValue] || optionFormatters.string,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const longestKey = keys.slice().sort((a, b) => b.length - a.length)[0];
|
|
38
|
-
|
|
39
|
-
if (!_.isEmpty(longestKey)) {
|
|
40
|
-
name = _.camelCase(
|
|
41
|
-
(isNoFlag ? longestKey.replace("--no-", "") : longestKey).replace(
|
|
42
|
-
/(--?)/,
|
|
43
|
-
"",
|
|
44
|
-
),
|
|
45
|
-
);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
isNoFlag,
|
|
50
|
-
raw: flags,
|
|
51
|
-
name,
|
|
52
|
-
keys,
|
|
53
|
-
value,
|
|
54
|
-
};
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const processOption = (option) => {
|
|
58
|
-
const processedFlags = processFlags(option.flags);
|
|
59
|
-
|
|
60
|
-
if (!processedFlags.name) {
|
|
61
|
-
console.warn("invalid option", option);
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
required: !!option.required,
|
|
67
|
-
description: `${option.description || ""}`,
|
|
68
|
-
default: option.default,
|
|
69
|
-
flags: processedFlags,
|
|
70
|
-
operation: option.operation,
|
|
71
|
-
internal: option.internal,
|
|
72
|
-
};
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
export { processOption };
|