openapi-ts-request 1.12.5 → 1.12.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.
|
@@ -6,12 +6,12 @@ const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
|
6
6
|
const lodash_1 = require("lodash");
|
|
7
7
|
const mockjs_1 = tslib_1.__importDefault(require("mockjs"));
|
|
8
8
|
const path_1 = require("path");
|
|
9
|
-
const tiny_pinyin_1 = tslib_1.__importDefault(require("tiny-pinyin"));
|
|
10
9
|
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
11
10
|
const index_1 = tslib_1.__importDefault(require("../parser-mock/index"));
|
|
12
11
|
const util_1 = require("../parser-mock/util");
|
|
13
12
|
const config_1 = require("./config");
|
|
14
13
|
const file_1 = require("./file");
|
|
14
|
+
const util_2 = require("./util");
|
|
15
15
|
mockjs_1.default.Random.extend({
|
|
16
16
|
country() {
|
|
17
17
|
const data = [
|
|
@@ -162,7 +162,7 @@ const mockGenerator = ({ openAPI, mockFolder, }) => {
|
|
|
162
162
|
((_a = methodConfig === null || methodConfig === void 0 ? void 0 : methodConfig.tags) === null || _a === void 0 ? void 0 : _a.join('/')) ||
|
|
163
163
|
path.replace('/', '').split('/')[1])) === null || _b === void 0 ? void 0 : _b.replace(/[^\w^\s^\u4e00-\u9fa5]/gi, '');
|
|
164
164
|
if (/[\u3220-\uFA29]/.test(conte)) {
|
|
165
|
-
conte =
|
|
165
|
+
conte = (0, util_2.toPlainPinyin)(conte);
|
|
166
166
|
}
|
|
167
167
|
if (!conte) {
|
|
168
168
|
return;
|
package/dist/generator/util.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import type { ArraySchemaObject, BinaryArraySchemaObject, ComponentsObject, ISchemaObject, NonArraySchemaObject, OpenAPIObject, OperationObject, ReferenceObject, SchemaObject } from '../type';
|
|
2
2
|
import type { ITypeItem } from './type';
|
|
3
|
+
/**
|
|
4
|
+
* 汉字转连续无音调小写拼音(对齐原 tiny-pinyin 的 convertToPinyin(str, '', true))
|
|
5
|
+
*/
|
|
6
|
+
export declare function toPlainPinyin(str: string): string;
|
|
3
7
|
export declare function stripDot(str: string): string;
|
|
4
8
|
export declare function resolveTypeName(typeName: string): string;
|
|
5
9
|
export declare function getRefName(refObject: ReferenceObject | string): string;
|
package/dist/generator/util.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getAxiosResponseType = exports.getBinaryResponseType = exports.isBinaryMediaType = exports.getBinaryMediaTypes = exports.getDefaultBinaryMediaTypes = exports.parseDescriptionEnumByReg = exports.parseDescriptionEnum = void 0;
|
|
4
|
+
exports.toPlainPinyin = toPlainPinyin;
|
|
4
5
|
exports.stripDot = stripDot;
|
|
5
6
|
exports.resolveTypeName = resolveTypeName;
|
|
6
7
|
exports.getRefName = getRefName;
|
|
@@ -27,11 +28,17 @@ exports.capitalizeFirstLetter = capitalizeFirstLetter;
|
|
|
27
28
|
exports.escapeStringForJs = escapeStringForJs;
|
|
28
29
|
const tslib_1 = require("tslib");
|
|
29
30
|
const lodash_1 = require("lodash");
|
|
31
|
+
const pinyin_pro_1 = require("pinyin-pro");
|
|
30
32
|
const reserved_words_1 = tslib_1.__importDefault(require("reserved-words"));
|
|
31
|
-
const tiny_pinyin_1 = tslib_1.__importDefault(require("tiny-pinyin"));
|
|
32
33
|
const config_1 = require("../config");
|
|
33
34
|
const log_1 = tslib_1.__importDefault(require("../log"));
|
|
34
35
|
const config_2 = require("./config");
|
|
36
|
+
/**
|
|
37
|
+
* 汉字转连续无音调小写拼音(对齐原 tiny-pinyin 的 convertToPinyin(str, '', true))
|
|
38
|
+
*/
|
|
39
|
+
function toPlainPinyin(str) {
|
|
40
|
+
return (0, pinyin_pro_1.pinyin)(str, { toneType: 'none', type: 'string', separator: '' });
|
|
41
|
+
}
|
|
35
42
|
function stripDot(str) {
|
|
36
43
|
return str.replace(/[-_ .](\w)/g, (_all, letter) => letter.toUpperCase());
|
|
37
44
|
}
|
|
@@ -77,7 +84,7 @@ function resolveTypeName(typeName) {
|
|
|
77
84
|
return (0, lodash_1.upperFirst)(name);
|
|
78
85
|
}
|
|
79
86
|
const noBlankName = name.replace(/ +/g, '');
|
|
80
|
-
return (0, lodash_1.upperFirst)(
|
|
87
|
+
return (0, lodash_1.upperFirst)(toPlainPinyin(noBlankName));
|
|
81
88
|
}
|
|
82
89
|
function getRefName(refObject) {
|
|
83
90
|
if (!isReferenceObject(refObject)) {
|
package/dist/util.js
CHANGED
|
@@ -254,7 +254,15 @@ function translateChineseModuleNodeToEnglish(openAPI) {
|
|
|
254
254
|
});
|
|
255
255
|
});
|
|
256
256
|
resolve(translateMap);
|
|
257
|
-
|
|
257
|
+
// 在写入前再次读取缓存,合并多个任务的翻译结果
|
|
258
|
+
const existingContent = readFileSafelySync(process.cwd() + '/openapi-ts-request.cache.json');
|
|
259
|
+
let existingCache = {};
|
|
260
|
+
if (existingContent !== null && isJSONString(existingContent)) {
|
|
261
|
+
existingCache = JSON.parse(existingContent);
|
|
262
|
+
}
|
|
263
|
+
// 合并现有缓存和新的翻译结果(新结果优先)
|
|
264
|
+
const mergedCache = Object.assign(Object.assign({}, existingCache), translateMap);
|
|
265
|
+
void writeFileAsync(process.cwd() + '/openapi-ts-request.cache.json', JSON.stringify(mergedCache, null, 2));
|
|
258
266
|
})
|
|
259
267
|
.catch(() => {
|
|
260
268
|
reject(false);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "openapi-ts-request",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.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",
|
|
@@ -40,11 +40,11 @@
|
|
|
40
40
|
"minimatch": "^9.0.5",
|
|
41
41
|
"mockjs": "^1.1.0",
|
|
42
42
|
"nunjucks": "^3.2.4",
|
|
43
|
+
"pinyin-pro": "^3.28.0",
|
|
43
44
|
"prettier": "^3.3.2",
|
|
44
45
|
"reserved-words": "^0.1.2",
|
|
45
46
|
"rimraf": "^5.0.10",
|
|
46
47
|
"swagger2openapi": "^7.0.8",
|
|
47
|
-
"tiny-pinyin": "^1.3.2",
|
|
48
48
|
"ts-morph": "^25.0.1",
|
|
49
49
|
"tslib": "^2.6.3"
|
|
50
50
|
},
|