openapi-ts-request 1.6.5 → 1.6.7

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.
@@ -121,9 +121,10 @@ class ServiceGenerator {
121
121
  return;
122
122
  }
123
123
  }
124
+ const tagTypeName = (0, util_2.resolveTypeName)(tag);
124
125
  const tagKey = this.config.isCamelCase
125
- ? (0, util_1.camelCase)((0, util_2.resolveTypeName)(tag))
126
- : (0, util_2.resolveTypeName)(tag);
126
+ ? (0, util_1.camelCase)(tagTypeName)
127
+ : (0, lodash_1.lowerFirst)(tagTypeName);
127
128
  if (!this.apiData[tagKey]) {
128
129
  this.apiData[tagKey] = [];
129
130
  }
@@ -366,7 +367,7 @@ class ServiceGenerator {
366
367
  }
367
368
  if (this.config.isGenJsonSchemas) {
368
369
  this.schemaList.push({
369
- typeName: `$${(0, util_2.resolveTypeName)(schemaKey)}`,
370
+ typeName: `$${(0, lodash_1.lowerFirst)((0, util_2.resolveTypeName)(schemaKey))}`,
370
371
  type: JSON.stringify((0, patchSchema_1.patchSchema)(schema, (_a = this.openAPIData.components) === null || _a === void 0 ? void 0 : _a.schemas)),
371
372
  });
372
373
  }
@@ -584,7 +585,7 @@ class ServiceGenerator {
584
585
  var _a, _b, _c;
585
586
  const namespace = this.config.namespace ? `${this.config.namespace}.` : '';
586
587
  const typeName = ((_c = (_b = (_a = this.config) === null || _a === void 0 ? void 0 : _a.hook) === null || _b === void 0 ? void 0 : _b.customTypeName) === null || _c === void 0 ? void 0 : _c.call(_b, data)) || this.getFunctionName(data);
587
- return (0, util_2.resolveTypeName)(`${namespace}${typeName !== null && typeName !== void 0 ? typeName : data.operationId}Params`);
588
+ return (0, lodash_1.upperFirst)((0, util_2.resolveTypeName)(`${namespace}${typeName !== null && typeName !== void 0 ? typeName : data.operationId}Params`));
588
589
  }
589
590
  getBodyTP(requestBody, namespace) {
590
591
  var _a;
@@ -72,10 +72,10 @@ function resolveTypeName(typeName) {
72
72
  return `Pinyin_${name}`;
73
73
  }
74
74
  if (!/[\u3220-\uFA29]/.test(name) && !/^\d$/.test(name)) {
75
- return name;
75
+ return (0, lodash_1.upperFirst)(name);
76
76
  }
77
77
  const noBlankName = name.replace(/ +/g, '');
78
- return tiny_pinyin_1.default.convertToPinyin(noBlankName, '', true);
78
+ return (0, lodash_1.upperFirst)(tiny_pinyin_1.default.convertToPinyin(noBlankName, '', true));
79
79
  }
80
80
  function getRefName(refObject) {
81
81
  if (!isReferenceObject(refObject)) {
package/dist/util.js CHANGED
@@ -11,6 +11,7 @@ const https_1 = tslib_1.__importDefault(require("https"));
11
11
  const yaml = tslib_1.__importStar(require("js-yaml"));
12
12
  const lodash_1 = require("lodash");
13
13
  const node_fs_1 = require("node:fs");
14
+ const promises_1 = require("node:fs/promises");
14
15
  const swagger2openapi_1 = tslib_1.__importDefault(require("swagger2openapi"));
15
16
  const log_1 = tslib_1.__importStar(require("./log"));
16
17
  const getImportStatement = (requestLibPath) => {
@@ -201,10 +202,40 @@ function isJSONString(str) {
201
202
  return false;
202
203
  }
203
204
  }
205
+ function readFileSafelySync(filePath) {
206
+ if (!(0, node_fs_1.existsSync)(filePath)) {
207
+ (0, log_1.logError)(`文件 ${filePath} 不存在`);
208
+ return null;
209
+ }
210
+ try {
211
+ return (0, node_fs_1.readFileSync)(filePath, 'utf-8');
212
+ }
213
+ catch (error) {
214
+ (0, log_1.logError)(`读取文件 ${filePath} 时出错:`, error);
215
+ return null;
216
+ }
217
+ }
218
+ function writeFileAsync(filePath, content) {
219
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
220
+ try {
221
+ yield (0, promises_1.writeFile)(filePath, content, 'utf8');
222
+ }
223
+ catch (error) {
224
+ (0, log_1.logError)(`文件 ${filePath} 写入失败`);
225
+ }
226
+ });
227
+ }
204
228
  function translateChineseModuleNodeToEnglish(openAPI) {
205
229
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
230
+ const content = readFileSafelySync(process.cwd() + '/openapi-ts-request.cache.json');
231
+ let i18n = {};
232
+ if (content !== null) {
233
+ if (isJSONString(content)) {
234
+ i18n = JSON.parse(content);
235
+ }
236
+ }
206
237
  return new Promise((resolve, reject) => {
207
- const translateMap = {};
238
+ const translateMap = i18n;
208
239
  const operations = [];
209
240
  let tags = [];
210
241
  (0, lodash_1.forEach)((0, lodash_1.keys)(openAPI.paths), (path) => {
@@ -219,7 +250,7 @@ function translateChineseModuleNodeToEnglish(openAPI) {
219
250
  });
220
251
  void Promise.all((0, lodash_1.map)((0, lodash_1.uniq)(tags), (tagName) => {
221
252
  return new Promise((resolve) => {
222
- if (tagName && /[\u3220-\uFA29]/.test(tagName)) {
253
+ if (tagName && /[\u3220-\uFA29]/.test(tagName) && !i18n[tagName]) {
223
254
  void (0, bing_translate_api_1.translate)(tagName, null, 'en')
224
255
  .then((translateRes) => {
225
256
  const text = (0, exports.camelCase)(translateRes === null || translateRes === void 0 ? void 0 : translateRes.translation);
@@ -246,6 +277,7 @@ function translateChineseModuleNodeToEnglish(openAPI) {
246
277
  });
247
278
  });
248
279
  resolve(translateMap);
280
+ void writeFileAsync(process.cwd() + '/openapi-ts-request.cache.json', JSON.stringify(translateMap, null, 2));
249
281
  })
250
282
  .catch(() => {
251
283
  reject(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openapi-ts-request",
3
- "version": "1.6.5",
3
+ "version": "1.6.7",
4
4
  "description": "Swagger2/OpenAPI3/Apifox to TypeScript/JavaScript, request client(support any client), request mock service, enum and enum translation, react-query/vue-query, type field label, JSON Schemas",
5
5
  "engines": {
6
6
  "node": ">=18.0.0",
@@ -70,7 +70,7 @@
70
70
  "openapi-types": "^12.1.3",
71
71
  "sanitize-filename": "^1.6.3",
72
72
  "ts-node": "^10.9.2",
73
- "typescript": "5.8.3",
73
+ "typescript": "5.9.2",
74
74
  "vitest": "^2.1.9"
75
75
  },
76
76
  "keywords": [