yapi-apifox-to-typescript 4.2.3 → 5.0.0
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/lib/cjs/ApifoxToYApiData.js +312 -588
- package/lib/cjs/Generator.js +513 -1171
- package/lib/cjs/SwaggerToYApiServer.js +125 -336
- package/lib/cjs/_virtual/_rolldown/runtime.js +23 -0
- package/lib/cjs/cli.js +171 -280
- package/lib/cjs/helpers.js +125 -209
- package/lib/cjs/index.js +15 -19
- package/lib/cjs/mini-ut.js +220 -0
- package/lib/cjs/swaggerJsonToYApiData.js +268 -482
- package/lib/cjs/types.js +93 -93
- package/lib/cjs/utils.js +364 -769
- package/lib/esm/ApifoxToYApiData.d.ts +49 -0
- package/lib/esm/ApifoxToYApiData.js +310 -572
- package/lib/esm/Generator.d.ts +53 -0
- package/lib/esm/Generator.js +509 -1146
- package/lib/esm/SwaggerToYApiServer.d.ts +23 -0
- package/lib/esm/SwaggerToYApiServer.js +119 -317
- package/lib/esm/_virtual/_rolldown/runtime.js +7 -0
- package/lib/esm/cli.d.ts +4 -0
- package/lib/esm/cli.js +162 -251
- package/lib/esm/helpers.d.ts +49 -0
- package/lib/esm/helpers.js +125 -198
- package/lib/esm/index.d.ts +2 -897
- package/lib/esm/index.js +3 -2
- package/lib/esm/mini-ut.d.ts +105 -0
- package/lib/esm/mini-ut.js +198 -0
- package/lib/esm/swaggerJsonToYApiData.d.ts +6 -0
- package/lib/esm/swaggerJsonToYApiData.js +265 -469
- package/lib/esm/types.d.ts +695 -0
- package/lib/esm/types.js +87 -73
- package/lib/esm/utils.d.ts +95 -0
- package/lib/esm/utils.js +350 -720
- package/package.json +49 -59
package/lib/esm/types.js
CHANGED
|
@@ -1,81 +1,95 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
1
2
|
/** 请求方式 */
|
|
2
|
-
|
|
3
|
+
var Method = /* @__PURE__ */ function(Method) {
|
|
4
|
+
Method["GET"] = "GET";
|
|
5
|
+
Method["POST"] = "POST";
|
|
6
|
+
Method["PUT"] = "PUT";
|
|
7
|
+
Method["DELETE"] = "DELETE";
|
|
8
|
+
Method["HEAD"] = "HEAD";
|
|
9
|
+
Method["OPTIONS"] = "OPTIONS";
|
|
10
|
+
Method["PATCH"] = "PATCH";
|
|
11
|
+
return Method;
|
|
12
|
+
}({});
|
|
3
13
|
/** 是否必需 */
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
Method["OPTIONS"] = "OPTIONS";
|
|
12
|
-
Method["PATCH"] = "PATCH";
|
|
13
|
-
})(Method || (Method = {}));
|
|
14
|
-
|
|
15
|
-
export var Required;
|
|
14
|
+
var Required = /* @__PURE__ */ function(Required) {
|
|
15
|
+
/** 不必需 */
|
|
16
|
+
Required["false"] = "0";
|
|
17
|
+
/** 必需 */
|
|
18
|
+
Required["true"] = "1";
|
|
19
|
+
return Required;
|
|
20
|
+
}({});
|
|
16
21
|
/** 请求数据类型 */
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
var RequestBodyType = /* @__PURE__ */ function(RequestBodyType) {
|
|
23
|
+
/** 查询字符串 */
|
|
24
|
+
RequestBodyType["query"] = "query";
|
|
25
|
+
/** 表单 */
|
|
26
|
+
RequestBodyType["form"] = "form";
|
|
27
|
+
/** JSON */
|
|
28
|
+
RequestBodyType["json"] = "json";
|
|
29
|
+
/** 纯文本 */
|
|
30
|
+
RequestBodyType["text"] = "text";
|
|
31
|
+
/** 文件 */
|
|
32
|
+
RequestBodyType["file"] = "file";
|
|
33
|
+
/** 原始数据 */
|
|
34
|
+
RequestBodyType["raw"] = "raw";
|
|
35
|
+
/** 无请求数据 */
|
|
36
|
+
RequestBodyType["none"] = "none";
|
|
37
|
+
return RequestBodyType;
|
|
38
|
+
}({});
|
|
24
39
|
/** 请求路径参数类型 */
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
})(RequestBodyType || (RequestBodyType = {}));
|
|
35
|
-
|
|
36
|
-
export var RequestParamType;
|
|
40
|
+
var RequestParamType = /* @__PURE__ */ function(RequestParamType) {
|
|
41
|
+
/** 字符串 */
|
|
42
|
+
RequestParamType["string"] = "string";
|
|
43
|
+
/** 数字 */
|
|
44
|
+
RequestParamType["number"] = "number";
|
|
45
|
+
/** 布尔值 */
|
|
46
|
+
RequestParamType["boolean"] = "boolean";
|
|
47
|
+
return RequestParamType;
|
|
48
|
+
}({});
|
|
37
49
|
/** 请求查询参数类型 */
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
50
|
+
var RequestQueryType = /* @__PURE__ */ function(RequestQueryType) {
|
|
51
|
+
/** 字符串 */
|
|
52
|
+
RequestQueryType["string"] = "string";
|
|
53
|
+
/** 数字 */
|
|
54
|
+
RequestQueryType["number"] = "number";
|
|
55
|
+
/** 布尔值 */
|
|
56
|
+
RequestQueryType["boolean"] = "boolean";
|
|
57
|
+
return RequestQueryType;
|
|
58
|
+
}({});
|
|
46
59
|
/** 请求表单条目类型 */
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
export var RequestFormItemType;
|
|
60
|
+
var RequestFormItemType = /* @__PURE__ */ function(RequestFormItemType) {
|
|
61
|
+
/** 纯文本 */
|
|
62
|
+
RequestFormItemType["text"] = "text";
|
|
63
|
+
/** 文件 */
|
|
64
|
+
RequestFormItemType["file"] = "file";
|
|
65
|
+
return RequestFormItemType;
|
|
66
|
+
}({});
|
|
55
67
|
/** 返回数据类型 */
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
68
|
+
var ResponseBodyType = /* @__PURE__ */ function(ResponseBodyType) {
|
|
69
|
+
/** JSON */
|
|
70
|
+
ResponseBodyType["json"] = "json";
|
|
71
|
+
/** 纯文本 */
|
|
72
|
+
ResponseBodyType["text"] = "text";
|
|
73
|
+
/** XML */
|
|
74
|
+
ResponseBodyType["xml"] = "xml";
|
|
75
|
+
/** 原始数据 */
|
|
76
|
+
ResponseBodyType["raw"] = "raw";
|
|
77
|
+
return ResponseBodyType;
|
|
78
|
+
/** JSON Schema */
|
|
79
|
+
}({});
|
|
63
80
|
/** 查询字符串数组格式化方式 */
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
QueryStringArrayFormat["comma"] = "comma";
|
|
80
|
-
QueryStringArrayFormat["json"] = "json";
|
|
81
|
-
})(QueryStringArrayFormat || (QueryStringArrayFormat = {}));
|
|
81
|
+
var QueryStringArrayFormat = /* @__PURE__ */ function(QueryStringArrayFormat) {
|
|
82
|
+
/** 示例: `a[]=b&a[]=c` */
|
|
83
|
+
QueryStringArrayFormat["brackets"] = "brackets";
|
|
84
|
+
/** 示例: `a[0]=b&a[1]=c` */
|
|
85
|
+
QueryStringArrayFormat["indices"] = "indices";
|
|
86
|
+
/** 示例: `a=b&a=c` */
|
|
87
|
+
QueryStringArrayFormat["repeat"] = "repeat";
|
|
88
|
+
/** 示例: `a=b,c` */
|
|
89
|
+
QueryStringArrayFormat["comma"] = "comma";
|
|
90
|
+
/** 示例: `a=["b","c"]` */
|
|
91
|
+
QueryStringArrayFormat["json"] = "json";
|
|
92
|
+
return QueryStringArrayFormat;
|
|
93
|
+
}({});
|
|
94
|
+
//#endregion
|
|
95
|
+
export { Method, QueryStringArrayFormat, RequestBodyType, RequestFormItemType, RequestParamType, RequestQueryType, Required, ResponseBodyType };
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { default as prettier } from 'prettier';
|
|
2
|
+
import { Category, CategoryConfig, Interface, Method, PropDefinitions } from './types';
|
|
3
|
+
import { OneOrMore } from './mini-ut';
|
|
4
|
+
import { JSONSchema4, JSONSchema4TypeName } from 'json-schema';
|
|
5
|
+
/**
|
|
6
|
+
* 抛出错误。
|
|
7
|
+
*
|
|
8
|
+
* @param msg 错误信息
|
|
9
|
+
*/
|
|
10
|
+
export declare function throwError(...msg: string[]): never;
|
|
11
|
+
/**
|
|
12
|
+
* 将路径统一为 unix 风格的路径。
|
|
13
|
+
*
|
|
14
|
+
* @param path 路径
|
|
15
|
+
* @returns unix 风格的路径
|
|
16
|
+
*/
|
|
17
|
+
export declare function toUnixPath(path: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* 获得规范化的相对路径。
|
|
20
|
+
*
|
|
21
|
+
* @param from 来源路径
|
|
22
|
+
* @param to 去向路径
|
|
23
|
+
* @returns 相对路径
|
|
24
|
+
*/
|
|
25
|
+
export declare function getNormalizedRelativePath(from: string, to: string): string;
|
|
26
|
+
/**
|
|
27
|
+
* 原地遍历 JSONSchema。
|
|
28
|
+
*/
|
|
29
|
+
export declare function traverseJsonSchema(jsonSchema: JSONSchema4, cb: (jsonSchema: JSONSchema4, currentPath: Array<string | number>) => JSONSchema4, currentPath?: Array<string | number>): JSONSchema4;
|
|
30
|
+
/**
|
|
31
|
+
* 原地处理 JSONSchema。
|
|
32
|
+
*
|
|
33
|
+
* @param jsonSchema 待处理的 JSONSchema
|
|
34
|
+
* @returns 处理后的 JSONSchema
|
|
35
|
+
*/
|
|
36
|
+
export declare function processJsonSchema(jsonSchema: JSONSchema4, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
37
|
+
/**
|
|
38
|
+
* 获取适用于 JSTT 的 JSONSchema。
|
|
39
|
+
*
|
|
40
|
+
* @param jsonSchema 待处理的 JSONSchema
|
|
41
|
+
* @returns 适用于 JSTT 的 JSONSchema
|
|
42
|
+
*/
|
|
43
|
+
export declare function jsonSchemaToJSTTJsonSchema(jsonSchema: JSONSchema4, typeName: string): JSONSchema4;
|
|
44
|
+
/**
|
|
45
|
+
* 将 JSONSchema 字符串转为 JSONSchema 对象。
|
|
46
|
+
*
|
|
47
|
+
* @param str 要转换的 JSONSchema 字符串
|
|
48
|
+
* @returns 转换后的 JSONSchema 对象
|
|
49
|
+
*/
|
|
50
|
+
export declare function jsonSchemaStringToJsonSchema(str: string, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
51
|
+
/**
|
|
52
|
+
* 获得 JSON 数据的 JSONSchema 对象。
|
|
53
|
+
*
|
|
54
|
+
* @param json JSON 数据
|
|
55
|
+
* @returns JSONSchema 对象
|
|
56
|
+
*/
|
|
57
|
+
export declare function jsonToJsonSchema(json: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
58
|
+
/**
|
|
59
|
+
* 获得 mockjs 模板的 JSONSchema 对象。
|
|
60
|
+
*
|
|
61
|
+
* @param template mockjs 模板
|
|
62
|
+
* @returns JSONSchema 对象
|
|
63
|
+
*/
|
|
64
|
+
export declare function mockjsTemplateToJsonSchema(template: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
65
|
+
/**
|
|
66
|
+
* 获得属性定义列表的 JSONSchema 对象。
|
|
67
|
+
*
|
|
68
|
+
* @param propDefinitions 属性定义列表
|
|
69
|
+
* @returns JSONSchema 对象
|
|
70
|
+
*/
|
|
71
|
+
export declare function propDefinitionsToJsonSchema(propDefinitions: PropDefinitions, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
72
|
+
/**
|
|
73
|
+
* 根据 JSONSchema 对象生产 TypeScript 类型定义。
|
|
74
|
+
*
|
|
75
|
+
* @param jsonSchema JSONSchema 对象
|
|
76
|
+
* @param typeName 类型名称
|
|
77
|
+
* @returns TypeScript 类型定义
|
|
78
|
+
*/
|
|
79
|
+
export declare function jsonSchemaToType(jsonSchema: JSONSchema4, typeName: string): Promise<string>;
|
|
80
|
+
export declare function getRequestDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
81
|
+
export declare function getResponseDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>, dataKey?: OneOrMore<string>): JSONSchema4;
|
|
82
|
+
export declare function reachJsonSchema(jsonSchema: JSONSchema4, path: OneOrMore<string>): JSONSchema4;
|
|
83
|
+
export declare function sortByWeights<T extends {
|
|
84
|
+
weights: number[];
|
|
85
|
+
}>(list: T[]): T[];
|
|
86
|
+
export declare function isGetLikeMethod(method: Method): boolean;
|
|
87
|
+
export declare function isPostLikeMethod(method: Method): boolean;
|
|
88
|
+
export declare function getPrettier(cwd: string): Promise<typeof prettier>;
|
|
89
|
+
export declare function getPrettierOptions(): Promise<prettier.Options>;
|
|
90
|
+
export declare const getCachedPrettierOptions: typeof getPrettierOptions;
|
|
91
|
+
export declare function httpGet<T>(url: string, query?: Record<string, any>): Promise<T>;
|
|
92
|
+
/**
|
|
93
|
+
* 获取过滤后的菜单
|
|
94
|
+
*/
|
|
95
|
+
export declare const getFilteredCat: (cat: CategoryConfig, cats: Category[], isApifox?: boolean) => number[];
|