swagger-typescript-api 10.0.0 → 10.0.2

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 (56) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +284 -260
  3. package/index.d.ts +7 -1
  4. package/index.js +115 -115
  5. package/package.json +116 -113
  6. package/src/apiConfig.js +30 -30
  7. package/src/common.js +28 -28
  8. package/src/components.js +3 -5
  9. package/src/config.js +4 -0
  10. package/src/constants.js +7 -0
  11. package/src/filePrefix.js +14 -14
  12. package/src/files.js +6 -6
  13. package/src/formatFileContent.js +13 -6
  14. package/src/index.js +271 -270
  15. package/src/logger.js +59 -59
  16. package/src/modelNames.js +78 -78
  17. package/src/modelTypes.js +31 -30
  18. package/src/output.js +165 -166
  19. package/src/prettierOptions.js +23 -23
  20. package/src/render/utils/fmtToJSDocLine.js +10 -10
  21. package/src/render/utils/index.js +31 -23
  22. package/src/render/utils/templateRequire.js +17 -17
  23. package/src/routeNames.js +46 -46
  24. package/src/routes.js +4 -1
  25. package/src/schema.js +87 -64
  26. package/src/swagger.js +4 -1
  27. package/src/templates.js +155 -132
  28. package/src/translators/JavaScript.js +60 -60
  29. package/src/typeFormatters.js +121 -75
  30. package/src/utils/id.js +9 -9
  31. package/src/utils/random.js +14 -14
  32. package/src/utils/resolveName.js +97 -97
  33. package/templates/README.md +17 -13
  34. package/templates/base/README.md +7 -7
  35. package/templates/base/data-contract-jsdoc.ejs +32 -0
  36. package/templates/base/data-contracts.ejs +28 -0
  37. package/templates/base/enum-data-contract.ejs +15 -0
  38. package/templates/base/{http-client.eta → http-client.ejs} +2 -2
  39. package/templates/base/http-clients/{axios-http-client.eta → axios-http-client.ejs} +133 -145
  40. package/templates/base/http-clients/{fetch-http-client.eta → fetch-http-client.ejs} +222 -222
  41. package/templates/base/interface-data-contract.ejs +10 -0
  42. package/templates/base/object-field-jsdoc.ejs +28 -0
  43. package/templates/base/{route-docs.eta → route-docs.ejs} +31 -31
  44. package/templates/base/{route-name.eta → route-name.ejs} +42 -42
  45. package/templates/base/{route-type.eta → route-type.ejs} +21 -21
  46. package/templates/base/type-data-contract.ejs +15 -0
  47. package/templates/default/README.md +6 -6
  48. package/templates/default/{api.eta → api.ejs} +65 -65
  49. package/templates/default/{procedure-call.eta → procedure-call.ejs} +98 -98
  50. package/templates/default/{route-types.eta → route-types.ejs} +28 -28
  51. package/templates/modular/README.md +6 -6
  52. package/templates/modular/{api.eta → api.ejs} +28 -28
  53. package/templates/modular/{procedure-call.eta → procedure-call.ejs} +98 -98
  54. package/templates/modular/{route-types.eta → route-types.ejs} +18 -18
  55. package/CHANGELOG.md +0 -866
  56. package/templates/base/data-contracts.eta +0 -45
package/src/components.js CHANGED
@@ -47,9 +47,7 @@ const createComponentsMap = (components) => {
47
47
  config.componentsMap = {};
48
48
 
49
49
  _.each(components, (component, componentName) =>
50
- _.each(component, (rawTypeData, typeName) =>
51
- createComponent(componentName, typeName, rawTypeData),
52
- ),
50
+ _.each(component, (rawTypeData, typeName) => createComponent(componentName, typeName, rawTypeData)),
53
51
  );
54
52
 
55
53
  return config.componentsMap;
@@ -80,9 +78,9 @@ const getTypeData = (typeInfo) => {
80
78
  /**
81
79
  *
82
80
  * @param {string} ref
83
- * @returns {TypeInfo | undefined}
81
+ * @returns {TypeInfo | null}
84
82
  */
85
- const getComponentByRef = (ref) => config.componentsMap[ref];
83
+ const getComponentByRef = (ref) => config.componentsMap[ref] || null;
86
84
 
87
85
  module.exports = {
88
86
  getTypeData,
package/src/config.js CHANGED
@@ -93,6 +93,10 @@ const config = {
93
93
  componentTypeNameResolver: new NameResolver([]),
94
94
  /** name of the main exported class */
95
95
  apiClassName: "Api",
96
+ debug: false,
97
+ internalTemplateOptions: {
98
+ addUtilRequiredKeysType: false,
99
+ },
96
100
  };
97
101
 
98
102
  /** needs to use data everywhere in project */
package/src/constants.js CHANGED
@@ -13,6 +13,12 @@ const TS_KEYWORDS = {
13
13
  TYPE: "type",
14
14
  ENUM: "enum",
15
15
  INTERFACE: "interface",
16
+ TYPE_AND_OPERATOR: " & ",
17
+ TYPE_OR_OPERATOR: " | ",
18
+ };
19
+
20
+ const TS_EXTERNAL = {
21
+ RECORD: "Record<string, any>",
16
22
  };
17
23
 
18
24
  const JS_PRIMITIVE_TYPES = [TS_KEYWORDS.NUMBER, TS_KEYWORDS.STRING, TS_KEYWORDS.BOOLEAN];
@@ -49,6 +55,7 @@ module.exports = {
49
55
  JS_PRIMITIVE_TYPES,
50
56
  JS_EMPTY_TYPES,
51
57
  TS_KEYWORDS,
58
+ TS_EXTERNAL,
52
59
  SCHEMA_TYPES,
53
60
  HTTP_CLIENT,
54
61
  RESERVED_QUERY_ARG_NAMES,
package/src/filePrefix.js CHANGED
@@ -1,14 +1,14 @@
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
- };
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
+ };
package/src/files.js CHANGED
@@ -21,7 +21,11 @@ const pathIsDir = (path) => {
21
21
 
22
22
  const removeDir = (path) => {
23
23
  try {
24
- fs.rmdirSync(path, { recursive: true });
24
+ if (typeof fs.rmSync === "function") {
25
+ fs.rmSync(path, { recursive: true });
26
+ } else {
27
+ fs.rmdirSync(path, { recursive: true });
28
+ }
25
29
  } catch (e) {}
26
30
  };
27
31
 
@@ -39,11 +43,7 @@ const cleanDir = (path) => {
39
43
  const pathIsExist = (path) => path && fs.existsSync(path);
40
44
 
41
45
  const createFile = ({ path, fileName, content, withPrefix }) =>
42
- fs.writeFileSync(
43
- resolve(__dirname, path, `./${fileName}`),
44
- `${withPrefix ? filePrefix : ""}${content}`,
45
- _.noop,
46
- );
46
+ fs.writeFileSync(resolve(__dirname, path, `./${fileName}`), `${withPrefix ? filePrefix : ""}${content}`, _.noop);
47
47
 
48
48
  module.exports = {
49
49
  createFile,
@@ -11,15 +11,13 @@ class LanguageServiceHost {
11
11
  fileName,
12
12
  content,
13
13
  compilerOptions: tsconfig
14
- ? ts.convertCompilerOptionsFromJson(
15
- ts.readConfigFile(tsconfig, ts.sys.readFile).config.compilerOptions,
16
- ).options
14
+ ? ts.convertCompilerOptionsFromJson(ts.readConfigFile(tsconfig, ts.sys.readFile).config.compilerOptions).options
17
15
  : ts.getDefaultCompilerOptions(),
18
16
  });
19
17
  }
20
18
 
21
19
  getNewLine() {
22
- return "\n";
20
+ return "newLine" in ts.sys ? ts.sys.newLine : "\n";
23
21
  }
24
22
  getScriptFileNames() {
25
23
  return [this.fileName];
@@ -39,6 +37,16 @@ class LanguageServiceHost {
39
37
  getScriptSnapshot() {
40
38
  return ts.ScriptSnapshot.fromString(this.content);
41
39
  }
40
+ readFile(fileName, encoding) {
41
+ if (fileName === this.fileName) {
42
+ return this.content;
43
+ }
44
+
45
+ return ts.sys.readFile(fileName, encoding);
46
+ }
47
+ fileExists(path) {
48
+ return ts.sys.fileExists(path);
49
+ }
42
50
  }
43
51
 
44
52
  const removeUnusedImports = (content) => {
@@ -70,5 +78,4 @@ const prettierFormat = (content) => {
70
78
 
71
79
  const formatters = [removeUnusedImports, prettierFormat];
72
80
 
73
- module.exports = (content) =>
74
- formatters.reduce((fixedContent, formatter) => formatter(fixedContent), content);
81
+ module.exports = (content) => formatters.reduce((fixedContent, formatter) => formatter(fixedContent), content);