openapi-ts-request 1.6.6 → 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.
- package/dist/util.js +34 -2
- package/package.json +2 -2
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.
|
|
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.
|
|
73
|
+
"typescript": "5.9.2",
|
|
74
74
|
"vitest": "^2.1.9"
|
|
75
75
|
},
|
|
76
76
|
"keywords": [
|