swagger-typescript-api 13.0.9 → 13.0.11

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 (69) hide show
  1. package/README.md +3 -3
  2. package/dist/chunk-3OGOYA5P.cjs +104 -0
  3. package/dist/chunk-3OGOYA5P.cjs.map +1 -0
  4. package/dist/chunk-R4CYI34W.js +65 -0
  5. package/dist/chunk-R4CYI34W.js.map +1 -0
  6. package/dist/cli.cjs +43 -0
  7. package/dist/cli.cjs.map +1 -0
  8. package/dist/cli.js +36 -0
  9. package/dist/cli.js.map +1 -0
  10. package/dist/lib.cjs +21 -0
  11. package/dist/lib.cjs.map +1 -0
  12. package/dist/lib.js +4 -0
  13. package/dist/lib.js.map +1 -0
  14. package/index.d.ts +1 -1
  15. package/package.json +25 -14
  16. package/templates/base/http-clients/axios-http-client.ejs +3 -0
  17. package/templates/base/http-clients/fetch-http-client.ejs +3 -3
  18. package/cli/constants.js +0 -6
  19. package/cli/execute.js +0 -180
  20. package/cli/index.js +0 -94
  21. package/cli/operations/display-help.js +0 -177
  22. package/cli/operations/display-version.js +0 -5
  23. package/cli/parse-args.js +0 -24
  24. package/cli/process-option.js +0 -75
  25. package/index.js +0 -344
  26. package/src/code-formatter.js +0 -114
  27. package/src/code-gen-process.js +0 -569
  28. package/src/commands/generate-templates/configuration.js +0 -31
  29. package/src/commands/generate-templates/index.js +0 -10
  30. package/src/commands/generate-templates/templates-gen-process.js +0 -205
  31. package/src/component-type-name-resolver.js +0 -42
  32. package/src/configuration.js +0 -445
  33. package/src/constants.js +0 -77
  34. package/src/index.js +0 -16
  35. package/src/schema-components-map.js +0 -76
  36. package/src/schema-parser/base-schema-parsers/array.js +0 -41
  37. package/src/schema-parser/base-schema-parsers/complex.js +0 -49
  38. package/src/schema-parser/base-schema-parsers/discriminator.js +0 -305
  39. package/src/schema-parser/base-schema-parsers/enum.js +0 -156
  40. package/src/schema-parser/base-schema-parsers/object.js +0 -103
  41. package/src/schema-parser/base-schema-parsers/primitive.js +0 -61
  42. package/src/schema-parser/complex-schema-parsers/all-of.js +0 -26
  43. package/src/schema-parser/complex-schema-parsers/any-of.js +0 -27
  44. package/src/schema-parser/complex-schema-parsers/not.js +0 -9
  45. package/src/schema-parser/complex-schema-parsers/one-of.js +0 -27
  46. package/src/schema-parser/mono-schema-parser.js +0 -46
  47. package/src/schema-parser/schema-formatters.js +0 -164
  48. package/src/schema-parser/schema-parser-fabric.js +0 -130
  49. package/src/schema-parser/schema-parser.js +0 -295
  50. package/src/schema-parser/schema-utils.js +0 -319
  51. package/src/schema-parser/util/enum-key-resolver.js +0 -24
  52. package/src/schema-routes/schema-routes.js +0 -1208
  53. package/src/schema-routes/util/specific-arg-name-resolver.js +0 -24
  54. package/src/schema-walker.js +0 -91
  55. package/src/swagger-schema-resolver.js +0 -195
  56. package/src/templates-worker.js +0 -243
  57. package/src/translators/javascript.js +0 -81
  58. package/src/translators/translator.js +0 -33
  59. package/src/type-name-formatter.js +0 -111
  60. package/src/util/file-system.js +0 -95
  61. package/src/util/id.js +0 -7
  62. package/src/util/internal-case.js +0 -7
  63. package/src/util/logger.js +0 -142
  64. package/src/util/name-resolver.js +0 -103
  65. package/src/util/object-assign.js +0 -17
  66. package/src/util/pascal-case.js +0 -7
  67. package/src/util/random.js +0 -11
  68. package/src/util/request.js +0 -63
  69. package/src/util/sort-by-property.js +0 -15
package/cli/execute.js DELETED
@@ -1,180 +0,0 @@
1
- import didYouMean from "didyoumean";
2
- import _ from "lodash";
3
- import { root_command, skip_command } from "./constants.js";
4
- import { parseArgs } from "./parse-args.js";
5
-
6
- didYouMean.threshold = 0.5;
7
-
8
- // eslint-disable-next-line no-unused-vars
9
- const execute = (params, commands, instance) => {
10
- const args = parseArgs(params.args, params.from);
11
-
12
- return new Promise((resolve, reject) => {
13
- const { command, usageOptions, error } = processArgs(commands, args);
14
-
15
- if (error) {
16
- reject(new Error(error));
17
- return;
18
- }
19
-
20
- if (!usageOptions.length && command.name === root_command) {
21
- usageOptions.push(
22
- command.options.find((option) => option.flags.name === "help"),
23
- );
24
- }
25
-
26
- const operationOptions = usageOptions.filter((option) => option.operation);
27
- if (operationOptions.length) {
28
- operationOptions[0].operation();
29
- resolve({
30
- command: skip_command,
31
- options: {},
32
- });
33
- return;
34
- } else {
35
- let error = "";
36
-
37
- const processUserOptionData = (userOption, option) => {
38
- if (userOption) {
39
- const data = userOption.$data;
40
- if (!data.length && !option.flags.value) {
41
- return !option.flags.isNoFlag;
42
- }
43
- if (option.flags.value) {
44
- if (option.flags.value.variadic) {
45
- return data.reduce((acc, d) => {
46
- acc.push(...d.split(",").map(option.flags.value.formatter));
47
- return acc;
48
- }, []);
49
- } else {
50
- return option.flags.value.formatter(data[0] || option.default);
51
- }
52
- }
53
- }
54
-
55
- return option.default;
56
- };
57
-
58
- const parsedOptionsObject = command.options.reduce((acc, option) => {
59
- if (error) return acc;
60
-
61
- const userOption = usageOptions.find(
62
- (o) => o.flags.name === option.flags.name,
63
- );
64
-
65
- if (!userOption && option.required) {
66
- error = `required option '${option.flags.raw}' not specified`;
67
- return acc;
68
- }
69
-
70
- const flagValue = processUserOptionData(userOption, option);
71
- if (!option.operation) {
72
- const internal = option.internal || {};
73
- acc[internal.name || option.flags.name] = internal.formatter
74
- ? internal.formatter(flagValue)
75
- : flagValue;
76
- }
77
-
78
- return acc;
79
- }, {});
80
-
81
- if (error) {
82
- reject(new Error(error));
83
- } else {
84
- resolve({
85
- command: command.name === root_command ? null : command.name,
86
- options: parsedOptionsObject,
87
- });
88
- }
89
- }
90
- });
91
- };
92
-
93
- const processArgs = (commands, args) => {
94
- let command = null;
95
- let usageOptions = [];
96
- let walkingOption = null;
97
- let error = "";
98
-
99
- let allFlagKeys = [];
100
-
101
- _.forEach(args, (arg, i) => {
102
- if (error) return;
103
-
104
- if (i === 0) {
105
- command = commands[arg];
106
-
107
- if (!command && !arg.startsWith("-")) {
108
- const tip = didYouMean(arg, _.keys(commands));
109
- error = `unknown command ${arg}${
110
- tip ? `\n(Did you mean ${tip} ?)` : ""
111
- }`;
112
- } else if (!command) {
113
- command = commands[root_command];
114
- }
115
-
116
- if (command) {
117
- allFlagKeys = command.options.reduce(
118
- (acc, option) => [...acc, ...option.flags.keys],
119
- [],
120
- );
121
- }
122
- }
123
-
124
- if (error) return;
125
-
126
- if (arg.startsWith("-")) {
127
- const option = command.options.find((option) =>
128
- option.flags.keys.includes(arg),
129
- );
130
-
131
- if (!option) {
132
- const tip = didYouMean(arg, allFlagKeys);
133
- error = `unknown option ${arg}${
134
- tip ? `\n(Did you mean ${tip} ?)` : ""
135
- }`;
136
- }
137
-
138
- if (option) {
139
- if (walkingOption && walkingOption.flags.name === option.flags.name) {
140
- return;
141
- }
142
- const existedOption = usageOptions.find(
143
- (o) => o.flags.name === option.flags.name,
144
- );
145
- if (existedOption) {
146
- walkingOption = existedOption;
147
- } else {
148
- walkingOption = {
149
- ...option,
150
- $data: [],
151
- };
152
- usageOptions.push(walkingOption);
153
- }
154
- }
155
-
156
- return;
157
- }
158
-
159
- if (walkingOption) {
160
- walkingOption.$data.push(arg);
161
- }
162
- });
163
- command = command || commands[root_command];
164
-
165
- if (error) {
166
- return {
167
- command: null,
168
- usageOptions: [],
169
- error,
170
- };
171
- }
172
-
173
- return {
174
- command,
175
- usageOptions,
176
- error,
177
- };
178
- };
179
-
180
- export { execute };
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 };
@@ -1,5 +0,0 @@
1
- const displayVersion = (instance) => {
2
- console.log(instance.input.version);
3
- };
4
-
5
- export { displayVersion };
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 };
@@ -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 };