swagger-typescript-api 13.0.2 → 13.0.4

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 (58) hide show
  1. package/README.md +310 -369
  2. package/cli/constants.js +3 -3
  3. package/cli/execute.js +12 -12
  4. package/cli/index.js +16 -16
  5. package/cli/operations/display-help.js +25 -25
  6. package/cli/parse-args.js +3 -3
  7. package/cli/process-option.js +11 -11
  8. package/index.d.ts +140 -45
  9. package/index.js +110 -111
  10. package/package.json +93 -108
  11. package/src/code-formatter.js +6 -6
  12. package/src/code-gen-process.js +45 -45
  13. package/src/commands/generate-templates/configuration.js +2 -2
  14. package/src/commands/generate-templates/index.js +1 -1
  15. package/src/commands/generate-templates/templates-gen-process.js +21 -21
  16. package/src/component-type-name-resolver.js +4 -4
  17. package/src/configuration.js +107 -107
  18. package/src/constants.js +26 -26
  19. package/src/index.js +3 -3
  20. package/src/schema-components-map.js +3 -3
  21. package/src/schema-parser/base-schema-parsers/array.js +3 -3
  22. package/src/schema-parser/base-schema-parsers/complex.js +5 -5
  23. package/src/schema-parser/base-schema-parsers/discriminator.js +16 -13
  24. package/src/schema-parser/base-schema-parsers/enum.js +12 -12
  25. package/src/schema-parser/base-schema-parsers/object.js +8 -8
  26. package/src/schema-parser/base-schema-parsers/primitive.js +3 -3
  27. package/src/schema-parser/complex-schema-parsers/all-of.js +2 -2
  28. package/src/schema-parser/complex-schema-parsers/any-of.js +2 -2
  29. package/src/schema-parser/complex-schema-parsers/not.js +1 -1
  30. package/src/schema-parser/complex-schema-parsers/one-of.js +2 -2
  31. package/src/schema-parser/mono-schema-parser.js +1 -1
  32. package/src/schema-parser/schema-formatters.js +14 -14
  33. package/src/schema-parser/schema-parser-fabric.js +5 -5
  34. package/src/schema-parser/schema-parser.js +24 -24
  35. package/src/schema-parser/schema-utils.js +21 -21
  36. package/src/schema-parser/util/enum-key-resolver.js +2 -2
  37. package/src/schema-routes/schema-routes.js +68 -68
  38. package/src/schema-routes/util/specific-arg-name-resolver.js +2 -2
  39. package/src/schema-walker.js +7 -7
  40. package/src/swagger-schema-resolver.js +16 -16
  41. package/src/templates-worker.js +21 -18
  42. package/src/translators/javascript.js +7 -7
  43. package/src/translators/translator.js +1 -1
  44. package/src/type-name-formatter.js +16 -16
  45. package/src/util/file-system.js +13 -14
  46. package/src/util/id.js +2 -2
  47. package/src/util/internal-case.js +1 -1
  48. package/src/util/logger.js +27 -27
  49. package/src/util/name-resolver.js +5 -5
  50. package/src/util/object-assign.js +2 -2
  51. package/src/util/pascal-case.js +1 -1
  52. package/src/util/request.js +15 -10
  53. package/templates/README.md +15 -14
  54. package/templates/base/README.md +4 -5
  55. package/templates/base/http-clients/fetch-http-client.ejs +1 -1
  56. package/templates/base/route-name.ejs +4 -4
  57. package/templates/default/README.md +4 -4
  58. package/templates/modular/README.md +4 -4
package/cli/constants.js CHANGED
@@ -1,7 +1,7 @@
1
- const root_command = Symbol('root');
2
- const skip_command = Symbol('skip');
1
+ const root_command = Symbol("root");
2
+ const skip_command = Symbol("skip");
3
3
 
4
- const reservedOptions = ['version', 'help'];
4
+ const reservedOptions = ["version", "help"];
5
5
 
6
6
  module.exports = {
7
7
  root_command,
package/cli/execute.js CHANGED
@@ -1,7 +1,7 @@
1
- const _ = require('lodash');
2
- const { root_command, skip_command } = require('./constants');
3
- const { parseArgs } = require('./parse-args');
4
- const didYouMean = require('didyoumean');
1
+ const _ = require("lodash");
2
+ const { root_command, skip_command } = require("./constants");
3
+ const { parseArgs } = require("./parse-args");
4
+ const didYouMean = require("didyoumean");
5
5
 
6
6
  didYouMean.threshold = 0.5;
7
7
 
@@ -19,7 +19,7 @@ const execute = (params, commands, instance) => {
19
19
 
20
20
  if (!usageOptions.length && command.name === root_command) {
21
21
  usageOptions.push(
22
- command.options.find((option) => option.flags.name === 'help'),
22
+ command.options.find((option) => option.flags.name === "help"),
23
23
  );
24
24
  }
25
25
 
@@ -32,7 +32,7 @@ const execute = (params, commands, instance) => {
32
32
  });
33
33
  return;
34
34
  } else {
35
- let error = '';
35
+ let error = "";
36
36
 
37
37
  const processUserOptionData = (userOption, option) => {
38
38
  if (userOption) {
@@ -43,7 +43,7 @@ const execute = (params, commands, instance) => {
43
43
  if (option.flags.value) {
44
44
  if (option.flags.value.variadic) {
45
45
  return data.reduce((acc, d) => {
46
- acc.push(...d.split(',').map(option.flags.value.formatter));
46
+ acc.push(...d.split(",").map(option.flags.value.formatter));
47
47
  return acc;
48
48
  }, []);
49
49
  } else {
@@ -94,7 +94,7 @@ const processArgs = (commands, args) => {
94
94
  let command = null;
95
95
  let usageOptions = [];
96
96
  let walkingOption = null;
97
- let error = '';
97
+ let error = "";
98
98
 
99
99
  let allFlagKeys = [];
100
100
 
@@ -104,10 +104,10 @@ const processArgs = (commands, args) => {
104
104
  if (i === 0) {
105
105
  command = commands[arg];
106
106
 
107
- if (!command && !arg.startsWith('-')) {
107
+ if (!command && !arg.startsWith("-")) {
108
108
  const tip = didYouMean(arg, _.keys(commands));
109
109
  error = `unknown command ${arg}${
110
- tip ? `\n(Did you mean ${tip} ?)` : ''
110
+ tip ? `\n(Did you mean ${tip} ?)` : ""
111
111
  }`;
112
112
  } else if (!command) {
113
113
  command = commands[root_command];
@@ -123,7 +123,7 @@ const processArgs = (commands, args) => {
123
123
 
124
124
  if (error) return;
125
125
 
126
- if (arg.startsWith('-')) {
126
+ if (arg.startsWith("-")) {
127
127
  const option = command.options.find((option) =>
128
128
  option.flags.keys.includes(arg),
129
129
  );
@@ -131,7 +131,7 @@ const processArgs = (commands, args) => {
131
131
  if (!option) {
132
132
  const tip = didYouMean(arg, allFlagKeys);
133
133
  error = `unknown option ${arg}${
134
- tip ? `\n(Did you mean ${tip} ?)` : ''
134
+ tip ? `\n(Did you mean ${tip} ?)` : ""
135
135
  }`;
136
136
  }
137
137
 
package/cli/index.js CHANGED
@@ -1,9 +1,9 @@
1
- const _ = require('lodash');
2
- const { reservedOptions, root_command } = require('./constants');
3
- const { processOption } = require('./process-option');
4
- const { execute } = require('./execute');
5
- const { displayHelp } = require('./operations/display-help');
6
- const { displayVersion } = require('./operations/display-version');
1
+ const _ = require("lodash");
2
+ const { reservedOptions, root_command } = require("./constants");
3
+ const { processOption } = require("./process-option");
4
+ const { execute } = require("./execute");
5
+ const { displayHelp } = require("./operations/display-help");
6
+ const { displayVersion } = require("./operations/display-version");
7
7
 
8
8
  const cli = (input) => {
9
9
  const commands = {};
@@ -11,15 +11,15 @@ const cli = (input) => {
11
11
  const addCommand = (command, { addVersion = false, addHelp = true } = {}) => {
12
12
  commands[command.name] = {
13
13
  name: command.name,
14
- description: `${command.description || ''}`,
14
+ description: `${command.description || ""}`,
15
15
  options: _.compact(_.map(command.options, processOption)),
16
16
  };
17
17
 
18
18
  if (addVersion) {
19
19
  commands[command.name].options.unshift(
20
20
  processOption({
21
- flags: '-v, --version',
22
- description: 'output the current version',
21
+ flags: "-v, --version",
22
+ description: "output the current version",
23
23
  operation: () => displayVersion(instance),
24
24
  }),
25
25
  );
@@ -28,8 +28,8 @@ const cli = (input) => {
28
28
  if (addHelp) {
29
29
  commands[command.name].options.push(
30
30
  processOption({
31
- flags: '-h, --help',
32
- description: 'display help for command',
31
+ flags: "-h, --help",
32
+ description: "display help for command",
33
33
  operation: () =>
34
34
  displayHelp(commands, instance, commands[command.name]),
35
35
  }),
@@ -63,7 +63,7 @@ const cli = (input) => {
63
63
  if (!processed) return;
64
64
 
65
65
  if (reservedOptions.includes(processed.name)) {
66
- console.warn('reserved option', processed.name);
66
+ console.warn("reserved option", processed.name);
67
67
  return;
68
68
  }
69
69
 
@@ -72,16 +72,16 @@ const cli = (input) => {
72
72
 
73
73
  commands[root_command].options.unshift(
74
74
  processOption({
75
- flags: '-v, --version',
76
- description: 'output the current version',
75
+ flags: "-v, --version",
76
+ description: "output the current version",
77
77
  operation: () => displayVersion(instance),
78
78
  }),
79
79
  );
80
80
 
81
81
  commands[root_command].options.push(
82
82
  processOption({
83
- flags: '-h, --help',
84
- description: 'display help for command',
83
+ flags: "-h, --help",
84
+ description: "display help for command",
85
85
  operation: () => displayHelp(commands, instance, commands[root_command]),
86
86
  }),
87
87
  );
@@ -1,18 +1,18 @@
1
- const _ = require('lodash');
2
- const { root_command } = require('../constants');
1
+ const _ = require("lodash");
2
+ const { root_command } = require("../constants");
3
3
 
4
4
  const generateOptionsOutput = (options) =>
5
5
  options.reduce(
6
6
  (acc, option) => {
7
- const flags = `${option.flags.keys.join(', ')}${
8
- option.flags.value?.raw ? ` ${option.flags.value?.raw}` : ''
7
+ const flags = `${option.flags.keys.join(", ")}${
8
+ option.flags.value?.raw ? ` ${option.flags.value?.raw}` : ""
9
9
  }`;
10
- const description = `${option.description || ''}${
10
+ const description = `${option.description || ""}${
11
11
  option.default === undefined ||
12
12
  (option.flags.isNoFlag && option.default === true)
13
- ? ''
13
+ ? ""
14
14
  : ` (default: ${
15
- typeof option.default === 'string'
15
+ typeof option.default === "string"
16
16
  ? `"${option.default}"`
17
17
  : option.default
18
18
  })`
@@ -37,10 +37,10 @@ const generateOptionsOutput = (options) =>
37
37
  const generateOptionsTextOutput = (options, maxLength, spaces) =>
38
38
  options
39
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');
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
44
 
45
45
  return (
46
46
  leftStr +
@@ -52,10 +52,10 @@ const generateOptionsTextOutput = (options, maxLength, spaces) =>
52
52
 
53
53
  return `\n${leftStrFiller}${line}`;
54
54
  })
55
- .join('')
55
+ .join("")
56
56
  );
57
57
  })
58
- .join('\n');
58
+ .join("\n");
59
59
 
60
60
  const displayAllHelp = (commands, instance) => {
61
61
  const { options, maxLength: maxOptionLength } = generateOptionsOutput(
@@ -68,7 +68,7 @@ const displayAllHelp = (commands, instance) => {
68
68
  ).reduce(
69
69
  (acc, command) => {
70
70
  const options = generateOptionsOutput(command.options);
71
- const name = `${command.name}${options.length ? ' [options]' : ''}`;
71
+ const name = `${command.name}${options.length ? " [options]" : ""}`;
72
72
  const description = command.description;
73
73
 
74
74
  const maxLength = Math.max(name.length, options.maxLength);
@@ -95,10 +95,10 @@ const displayAllHelp = (commands, instance) => {
95
95
  .map((commandLabel) => {
96
96
  const leftStr = ` ${commandLabel.name.padEnd(
97
97
  maxCommandLength,
98
- ' ',
98
+ " ",
99
99
  )} `;
100
- const leftStrFiller = Array(leftStr.length).fill(' ').join('');
101
- const descriptionLines = commandLabel.description.split('\n');
100
+ const leftStrFiller = Array(leftStr.length).fill(" ").join("");
101
+ const descriptionLines = commandLabel.description.split("\n");
102
102
  const optionsTextOutput = generateOptionsTextOutput(
103
103
  commandLabel.options.options,
104
104
  maxCommandLength,
@@ -115,11 +115,11 @@ const displayAllHelp = (commands, instance) => {
115
115
 
116
116
  return `\n${leftStrFiller}${line}`;
117
117
  })
118
- .join('') +
119
- (optionsTextOutput.length ? `\n${optionsTextOutput}` : '')
118
+ .join("") +
119
+ (optionsTextOutput.length ? `\n${optionsTextOutput}` : "")
120
120
  );
121
121
  })
122
- .join('\n');
122
+ .join("\n");
123
123
 
124
124
  const outputTest = [
125
125
  optionsOutput &&
@@ -130,12 +130,12 @@ ${optionsOutput}`,
130
130
  ${commandsOutput}`,
131
131
  ]
132
132
  .filter(Boolean)
133
- .join('\n\n');
133
+ .join("\n\n");
134
134
 
135
135
  console.log(`Usage: ${[instance.input.name, instance.input.alias]
136
136
  .filter(Boolean)
137
- .join('|')}${optionsOutput ? ' [options]' : ''}${
138
- commandsOutput ? ' [command]' : ''
137
+ .join("|")}${optionsOutput ? " [options]" : ""}${
138
+ commandsOutput ? " [command]" : ""
139
139
  }
140
140
  ${
141
141
  instance.input.description &&
@@ -160,10 +160,10 @@ const displayHelp = (commands, instance, command) => {
160
160
  ${optionsOutput}`,
161
161
  ]
162
162
  .filter(Boolean)
163
- .join('\n\n');
163
+ .join("\n\n");
164
164
 
165
165
  console.log(`Usage: ${instance.input.name} ${command.name}${
166
- optionsOutput ? ' [options]' : ''
166
+ optionsOutput ? " [options]" : ""
167
167
  }
168
168
  ${
169
169
  command.description &&
package/cli/parse-args.js CHANGED
@@ -1,18 +1,18 @@
1
1
  const parseArgs = (args, type) => {
2
2
  if (args == null || !Array.isArray(args)) {
3
- throw 'args should be array';
3
+ throw "args should be array";
4
4
  }
5
5
  const argsCopy = args.slice();
6
6
 
7
7
  switch (type) {
8
- case 'electron': {
8
+ case "electron": {
9
9
  if (process.defaultApp) {
10
10
  return argsCopy.slice(2);
11
11
  }
12
12
 
13
13
  return argsCopy.slice(1);
14
14
  }
15
- case 'user': {
15
+ case "user": {
16
16
  return argsCopy;
17
17
  }
18
18
  default: {
@@ -1,4 +1,4 @@
1
- const _ = require('lodash');
1
+ const _ = require("lodash");
2
2
 
3
3
  const optionFormatters = {
4
4
  number: (str) => +str,
@@ -13,16 +13,16 @@ const processFlags = (flags) => {
13
13
  let name = null;
14
14
  const keys = [];
15
15
  let value = null;
16
- const isNoFlag = flags.includes('--no-');
16
+ const isNoFlag = flags.includes("--no-");
17
17
 
18
- _.compact(_.split(flags, ' ').map((str) => str.replace(/,/g, ''))).forEach(
18
+ _.compact(_.split(flags, " ").map((str) => str.replace(/,/g, ""))).forEach(
19
19
  (str) => {
20
- if (str.startsWith('-')) {
20
+ if (str.startsWith("-")) {
21
21
  keys.push(str);
22
22
  } else if (value === null) {
23
- if (str.startsWith('{') || str.startsWith('[') || str.startsWith('<')) {
24
- const rawValue = str.replace(/[{[<>}\].]/g, '');
25
- const variadic = str.includes('...');
23
+ if (str.startsWith("{") || str.startsWith("[") || str.startsWith("<")) {
24
+ const rawValue = str.replace(/[{[<>}\].]/g, "");
25
+ const variadic = str.includes("...");
26
26
  value = {
27
27
  raw: str,
28
28
  variadic,
@@ -38,9 +38,9 @@ const processFlags = (flags) => {
38
38
 
39
39
  if (!_.isEmpty(longestKey)) {
40
40
  name = _.camelCase(
41
- (isNoFlag ? longestKey.replace('--no-', '') : longestKey).replace(
41
+ (isNoFlag ? longestKey.replace("--no-", "") : longestKey).replace(
42
42
  /(--?)/,
43
- '',
43
+ "",
44
44
  ),
45
45
  );
46
46
  }
@@ -58,13 +58,13 @@ const processOption = (option) => {
58
58
  const processedFlags = processFlags(option.flags);
59
59
 
60
60
  if (!processedFlags.name) {
61
- console.warn('invalid option', option);
61
+ console.warn("invalid option", option);
62
62
  return null;
63
63
  }
64
64
 
65
65
  return {
66
66
  required: !!option.required,
67
- description: `${option.description || ''}`,
67
+ description: `${option.description || ""}`,
68
68
  default: option.default,
69
69
  flags: processedFlags,
70
70
  operation: option.operation,