swagger-typescript-api 11.0.0 → 11.0.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # next release
2
2
 
3
+ # 11.0.1
4
+
5
+ - fix: problems with --http-client option in `generate-templates` command
6
+ - fix: rewrite file content in `generate-templates` command
7
+
3
8
  # 11.0.0
4
9
 
5
10
  ## Breaking changes
package/index.js CHANGED
@@ -290,7 +290,14 @@ const main = async () => {
290
290
  break;
291
291
  }
292
292
  case "generate-templates": {
293
- await generateTemplates(options);
293
+ await generateTemplates({
294
+ cleanOutput: options.cleanOutput,
295
+ output: options.output,
296
+ httpClientType: options.httpClient,
297
+ modular: options.modular,
298
+ silent: options.silent,
299
+ rewrite: options.rewrite,
300
+ });
294
301
  break;
295
302
  }
296
303
  default: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swagger-typescript-api",
3
- "version": "11.0.0",
3
+ "version": "11.0.1",
4
4
  "description": "Generate typescript/javascript api from swagger schema",
5
5
  "scripts": {
6
6
  "cli:json": "node index.js -r -d -p ./swagger-test-cli.json -n swagger-test-cli.ts",
@@ -56,16 +56,36 @@ class TemplatesGenProcess {
56
56
  }
57
57
 
58
58
  templates.forEach((template) => {
59
- const templateExist = this.fileSystem.pathIsExist(path.resolve(outputPath, template.name));
60
- if (!templateExist || this.config.rewrite) {
59
+ const templateName = this.fileSystem.cropExtension(template.name);
60
+ const templateEjsPath = path.resolve(outputPath, `${templateName}.ejs`);
61
+ const templateEtaPath = path.resolve(outputPath, `${templateName}.eta`);
62
+ const templateEjsPathExist = this.fileSystem.pathIsExist(templateEjsPath);
63
+ const templateEtaPathExist = this.fileSystem.pathIsExist(templateEtaPath);
64
+
65
+ if (this.config.rewrite || (!templateEjsPathExist && !templateEtaPathExist)) {
61
66
  this.fileSystem.createFile({
62
67
  path: outputPath,
63
68
  fileName: template.name,
64
69
  content: template.content,
65
70
  withPrefix: false,
66
71
  });
72
+ } else if (templateEjsPathExist) {
73
+ this.fileSystem.createFile({
74
+ path: outputPath,
75
+ fileName: `${templateName}.ejs`,
76
+ content: template.content,
77
+ withPrefix: false,
78
+ });
79
+ } else if (templateEtaPathExist) {
80
+ this.fileSystem.createFile({
81
+ path: outputPath,
82
+ fileName: `${templateName}.eta`,
83
+ content: template.content,
84
+ withPrefix: false,
85
+ });
67
86
  }
68
87
  });
88
+
69
89
  this.logger.success(`source templates has been successfully created in "${outputPath}"`);
70
90
  }
71
91
 
@@ -83,23 +103,26 @@ class TemplatesGenProcess {
83
103
  const apiTemplatesPath = this.config.modular ? this.paths.moduleApiTemplates : this.paths.defaultApiTemplates;
84
104
  const apiTemplates = this.getTemplateNamesFromDir(apiTemplatesPath);
85
105
 
86
- for (const fileName of baseTemplates) {
87
- outputFiles.push({
88
- name: fileName,
89
- content: this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${fileName}`)),
90
- });
91
- }
92
-
93
106
  const usingHttpClientTemplate = httpClientTemplates.find((template) =>
94
107
  template.startsWith(`${this.config.httpClientType}-`),
95
108
  );
96
109
 
110
+ let httpClientTemplateContent = "";
111
+
97
112
  if (usingHttpClientTemplate) {
113
+ httpClientTemplateContent = this.fixTemplateContent(
114
+ this.getTemplateContent(`${this.paths.httpClientTemplates}/${usingHttpClientTemplate}`),
115
+ );
116
+ }
117
+
118
+ for (const fileName of baseTemplates) {
119
+ const templateContent =
120
+ (fileName === "http-client.ejs" && httpClientTemplateContent) ||
121
+ this.fixTemplateContent(this.getTemplateContent(`${this.paths.baseTemplates}/${fileName}`));
122
+
98
123
  outputFiles.push({
99
- name: usingHttpClientTemplate,
100
- content: this.fixTemplateContent(
101
- this.getTemplateContent(`${this.paths.httpClientTemplates}/${usingHttpClientTemplate}`),
102
- ),
124
+ name: fileName,
125
+ content: templateContent,
103
126
  });
104
127
  }
105
128