yapi-to-typescript2 1.0.0 → 1.0.2
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/Generator.d.ts +49 -0
- package/lib/cjs/Generator.js +729 -1121
- package/lib/cjs/SwaggerToYApiServer.d.ts +20 -0
- package/lib/cjs/SwaggerToYApiServer.js +222 -330
- package/lib/cjs/cli.d.ts +4 -0
- package/lib/cjs/cli.js +247 -278
- package/lib/cjs/helpers.d.ts +49 -0
- package/lib/cjs/helpers.js +179 -203
- package/lib/cjs/index.d.ts +2 -0
- package/lib/cjs/index.js +17 -18
- package/lib/cjs/swaggerJsonToYApiData.d.ts +6 -0
- package/lib/cjs/swaggerJsonToYApiData.js +408 -465
- package/lib/cjs/types.d.ts +693 -0
- package/lib/cjs/types.js +75 -82
- package/lib/cjs/utils.d.ts +92 -0
- package/lib/cjs/utils.js +499 -654
- package/lib/esm/Generator.d.ts +49 -0
- package/lib/esm/Generator.js +696 -1093
- package/lib/esm/SwaggerToYApiServer.d.ts +20 -0
- package/lib/esm/SwaggerToYApiServer.js +212 -307
- package/lib/esm/cli.d.ts +4 -0
- package/lib/esm/cli.js +209 -242
- package/lib/esm/helpers.d.ts +49 -0
- package/lib/esm/helpers.js +174 -190
- package/lib/esm/index.d.ts +2 -845
- package/lib/esm/index.js +1 -1
- package/lib/esm/swaggerJsonToYApiData.d.ts +6 -0
- package/lib/esm/swaggerJsonToYApiData.js +399 -450
- package/lib/esm/types.d.ts +693 -0
- package/lib/esm/types.js +66 -55
- package/lib/esm/utils.d.ts +92 -0
- package/lib/esm/utils.js +462 -584
- package/package.json +9 -4
package/lib/cjs/types.js
CHANGED
|
@@ -1,100 +1,93 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
exports.
|
|
4
|
-
exports.ResponseBodyType = exports.Required = exports.RequestQueryType = exports.RequestParamType = exports.RequestFormItemType = exports.RequestBodyType = exports.QueryStringArrayFormat = exports.Method = void 0;
|
|
5
|
-
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.QueryStringArrayFormat = exports.ResponseBodyType = exports.RequestFormItemType = exports.RequestQueryType = exports.RequestParamType = exports.RequestBodyType = exports.Required = exports.Method = void 0;
|
|
6
4
|
/** 请求方式 */
|
|
7
5
|
var Method;
|
|
8
|
-
/** 是否必需 */
|
|
9
|
-
|
|
10
|
-
exports.Method = Method;
|
|
11
|
-
|
|
12
6
|
(function (Method) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
})(Method
|
|
21
|
-
|
|
7
|
+
Method["GET"] = "GET";
|
|
8
|
+
Method["POST"] = "POST";
|
|
9
|
+
Method["PUT"] = "PUT";
|
|
10
|
+
Method["DELETE"] = "DELETE";
|
|
11
|
+
Method["HEAD"] = "HEAD";
|
|
12
|
+
Method["OPTIONS"] = "OPTIONS";
|
|
13
|
+
Method["PATCH"] = "PATCH";
|
|
14
|
+
})(Method = exports.Method || (exports.Method = {}));
|
|
15
|
+
/** 是否必需 */
|
|
22
16
|
var Required;
|
|
23
|
-
/** 请求数据类型 */
|
|
24
|
-
|
|
25
|
-
exports.Required = Required;
|
|
26
|
-
|
|
27
17
|
(function (Required) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
/** 不必需 */
|
|
19
|
+
Required["false"] = "0";
|
|
20
|
+
/** 必需 */
|
|
21
|
+
Required["true"] = "1";
|
|
22
|
+
})(Required = exports.Required || (exports.Required = {}));
|
|
23
|
+
/** 请求数据类型 */
|
|
32
24
|
var RequestBodyType;
|
|
33
|
-
/** 请求路径参数类型 */
|
|
34
|
-
|
|
35
|
-
exports.RequestBodyType = RequestBodyType;
|
|
36
|
-
|
|
37
25
|
(function (RequestBodyType) {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
26
|
+
/** 查询字符串 */
|
|
27
|
+
RequestBodyType["query"] = "query";
|
|
28
|
+
/** 表单 */
|
|
29
|
+
RequestBodyType["form"] = "form";
|
|
30
|
+
/** JSON */
|
|
31
|
+
RequestBodyType["json"] = "json";
|
|
32
|
+
/** 纯文本 */
|
|
33
|
+
RequestBodyType["text"] = "text";
|
|
34
|
+
/** 文件 */
|
|
35
|
+
RequestBodyType["file"] = "file";
|
|
36
|
+
/** 原始数据 */
|
|
37
|
+
RequestBodyType["raw"] = "raw";
|
|
38
|
+
/** 无请求数据 */
|
|
39
|
+
RequestBodyType["none"] = "none";
|
|
40
|
+
})(RequestBodyType = exports.RequestBodyType || (exports.RequestBodyType = {}));
|
|
41
|
+
/** 请求路径参数类型 */
|
|
47
42
|
var RequestParamType;
|
|
48
|
-
/** 请求查询参数类型 */
|
|
49
|
-
|
|
50
|
-
exports.RequestParamType = RequestParamType;
|
|
51
|
-
|
|
52
43
|
(function (RequestParamType) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
44
|
+
/** 字符串 */
|
|
45
|
+
RequestParamType["string"] = "string";
|
|
46
|
+
/** 数字 */
|
|
47
|
+
RequestParamType["number"] = "number";
|
|
48
|
+
})(RequestParamType = exports.RequestParamType || (exports.RequestParamType = {}));
|
|
49
|
+
/** 请求查询参数类型 */
|
|
57
50
|
var RequestQueryType;
|
|
58
|
-
/** 请求表单条目类型 */
|
|
59
|
-
|
|
60
|
-
exports.RequestQueryType = RequestQueryType;
|
|
61
|
-
|
|
62
51
|
(function (RequestQueryType) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
52
|
+
/** 字符串 */
|
|
53
|
+
RequestQueryType["string"] = "string";
|
|
54
|
+
/** 数字 */
|
|
55
|
+
RequestQueryType["number"] = "number";
|
|
56
|
+
})(RequestQueryType = exports.RequestQueryType || (exports.RequestQueryType = {}));
|
|
57
|
+
/** 请求表单条目类型 */
|
|
67
58
|
var RequestFormItemType;
|
|
68
|
-
/** 返回数据类型 */
|
|
69
|
-
|
|
70
|
-
exports.RequestFormItemType = RequestFormItemType;
|
|
71
|
-
|
|
72
59
|
(function (RequestFormItemType) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
60
|
+
/** 纯文本 */
|
|
61
|
+
RequestFormItemType["text"] = "text";
|
|
62
|
+
/** 文件 */
|
|
63
|
+
RequestFormItemType["file"] = "file";
|
|
64
|
+
})(RequestFormItemType = exports.RequestFormItemType || (exports.RequestFormItemType = {}));
|
|
65
|
+
/** 返回数据类型 */
|
|
77
66
|
var ResponseBodyType;
|
|
78
|
-
/** 查询字符串数组格式化方式 */
|
|
79
|
-
|
|
80
|
-
exports.ResponseBodyType = ResponseBodyType;
|
|
81
|
-
|
|
82
67
|
(function (ResponseBodyType) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
68
|
+
/** JSON */
|
|
69
|
+
ResponseBodyType["json"] = "json";
|
|
70
|
+
/** 纯文本 */
|
|
71
|
+
ResponseBodyType["text"] = "text";
|
|
72
|
+
/** XML */
|
|
73
|
+
ResponseBodyType["xml"] = "xml";
|
|
74
|
+
/** 原始数据 */
|
|
75
|
+
ResponseBodyType["raw"] = "raw";
|
|
76
|
+
// yapi 实际上返回的是 json,有另外的字段指示其是否是 json schema
|
|
77
|
+
/** JSON Schema */
|
|
78
|
+
// jsonSchema = 'json-schema',
|
|
79
|
+
})(ResponseBodyType = exports.ResponseBodyType || (exports.ResponseBodyType = {}));
|
|
80
|
+
/** 查询字符串数组格式化方式 */
|
|
89
81
|
var QueryStringArrayFormat;
|
|
90
|
-
/** 接口定义 */
|
|
91
|
-
|
|
92
|
-
exports.QueryStringArrayFormat = QueryStringArrayFormat;
|
|
93
|
-
|
|
94
82
|
(function (QueryStringArrayFormat) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
83
|
+
/** 示例: `a[]=b&a[]=c` */
|
|
84
|
+
QueryStringArrayFormat["brackets"] = "brackets";
|
|
85
|
+
/** 示例: `a[0]=b&a[1]=c` */
|
|
86
|
+
QueryStringArrayFormat["indices"] = "indices";
|
|
87
|
+
/** 示例: `a=b&a=c` */
|
|
88
|
+
QueryStringArrayFormat["repeat"] = "repeat";
|
|
89
|
+
/** 示例: `a=b,c` */
|
|
90
|
+
QueryStringArrayFormat["comma"] = "comma";
|
|
91
|
+
/** 示例: `a=["b","c"]` */
|
|
92
|
+
QueryStringArrayFormat["json"] = "json";
|
|
93
|
+
})(QueryStringArrayFormat = exports.QueryStringArrayFormat || (exports.QueryStringArrayFormat = {}));
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/// <reference types="lodash" />
|
|
2
|
+
import prettier from 'prettier';
|
|
3
|
+
import { OneOrMore } from 'vtils/types';
|
|
4
|
+
import { Interface, Method, PropDefinitions } from './types';
|
|
5
|
+
import { JSONSchema4, JSONSchema4TypeName } from 'json-schema';
|
|
6
|
+
/**
|
|
7
|
+
* 抛出错误。
|
|
8
|
+
*
|
|
9
|
+
* @param msg 错误信息
|
|
10
|
+
*/
|
|
11
|
+
export declare function throwError(...msg: string[]): never;
|
|
12
|
+
/**
|
|
13
|
+
* 将路径统一为 unix 风格的路径。
|
|
14
|
+
*
|
|
15
|
+
* @param path 路径
|
|
16
|
+
* @returns unix 风格的路径
|
|
17
|
+
*/
|
|
18
|
+
export declare function toUnixPath(path: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* 获得规范化的相对路径。
|
|
21
|
+
*
|
|
22
|
+
* @param from 来源路径
|
|
23
|
+
* @param to 去向路径
|
|
24
|
+
* @returns 相对路径
|
|
25
|
+
*/
|
|
26
|
+
export declare function getNormalizedRelativePath(from: string, to: string): string;
|
|
27
|
+
/**
|
|
28
|
+
* 原地遍历 JSONSchema。
|
|
29
|
+
*/
|
|
30
|
+
export declare function traverseJsonSchema(jsonSchema: JSONSchema4, cb: (jsonSchema: JSONSchema4, currentPath: Array<string | number>) => JSONSchema4, currentPath?: Array<string | number>): JSONSchema4;
|
|
31
|
+
/**
|
|
32
|
+
* 原地处理 JSONSchema。
|
|
33
|
+
*
|
|
34
|
+
* @param jsonSchema 待处理的 JSONSchema
|
|
35
|
+
* @returns 处理后的 JSONSchema
|
|
36
|
+
*/
|
|
37
|
+
export declare function processJsonSchema(jsonSchema: JSONSchema4, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
38
|
+
/**
|
|
39
|
+
* 获取适用于 JSTT 的 JSONSchema。
|
|
40
|
+
*
|
|
41
|
+
* @param jsonSchema 待处理的 JSONSchema
|
|
42
|
+
* @returns 适用于 JSTT 的 JSONSchema
|
|
43
|
+
*/
|
|
44
|
+
export declare function jsonSchemaToJSTTJsonSchema(jsonSchema: JSONSchema4, typeName: string): JSONSchema4;
|
|
45
|
+
/**
|
|
46
|
+
* 将 JSONSchema 字符串转为 JSONSchema 对象。
|
|
47
|
+
*
|
|
48
|
+
* @param str 要转换的 JSONSchema 字符串
|
|
49
|
+
* @returns 转换后的 JSONSchema 对象
|
|
50
|
+
*/
|
|
51
|
+
export declare function jsonSchemaStringToJsonSchema(str: string, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
52
|
+
/**
|
|
53
|
+
* 获得 JSON 数据的 JSONSchema 对象。
|
|
54
|
+
*
|
|
55
|
+
* @param json JSON 数据
|
|
56
|
+
* @returns JSONSchema 对象
|
|
57
|
+
*/
|
|
58
|
+
export declare function jsonToJsonSchema(json: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
59
|
+
/**
|
|
60
|
+
* 获得 mockjs 模板的 JSONSchema 对象。
|
|
61
|
+
*
|
|
62
|
+
* @param template mockjs 模板
|
|
63
|
+
* @returns JSONSchema 对象
|
|
64
|
+
*/
|
|
65
|
+
export declare function mockjsTemplateToJsonSchema(template: object, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
66
|
+
/**
|
|
67
|
+
* 获得属性定义列表的 JSONSchema 对象。
|
|
68
|
+
*
|
|
69
|
+
* @param propDefinitions 属性定义列表
|
|
70
|
+
* @returns JSONSchema 对象
|
|
71
|
+
*/
|
|
72
|
+
export declare function propDefinitionsToJsonSchema(propDefinitions: PropDefinitions, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
73
|
+
/**
|
|
74
|
+
* 根据 JSONSchema 对象生产 TypeScript 类型定义。
|
|
75
|
+
*
|
|
76
|
+
* @param jsonSchema JSONSchema 对象
|
|
77
|
+
* @param typeName 类型名称
|
|
78
|
+
* @returns TypeScript 类型定义
|
|
79
|
+
*/
|
|
80
|
+
export declare function jsonSchemaToType(jsonSchema: JSONSchema4, typeName: string): Promise<string>;
|
|
81
|
+
export declare function getRequestDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>): JSONSchema4;
|
|
82
|
+
export declare function getResponseDataJsonSchema(interfaceInfo: Interface, customTypeMapping: Record<string, JSONSchema4TypeName>, dataKey?: OneOrMore<string>): JSONSchema4;
|
|
83
|
+
export declare function reachJsonSchema(jsonSchema: JSONSchema4, path: OneOrMore<string>): JSONSchema4;
|
|
84
|
+
export declare function sortByWeights<T extends {
|
|
85
|
+
weights: number[];
|
|
86
|
+
}>(list: T[]): T[];
|
|
87
|
+
export declare function isGetLikeMethod(method: Method): boolean;
|
|
88
|
+
export declare function isPostLikeMethod(method: Method): boolean;
|
|
89
|
+
export declare function getPrettier(cwd: string): Promise<typeof prettier>;
|
|
90
|
+
export declare function getPrettierOptions(): Promise<prettier.Options>;
|
|
91
|
+
export declare const getCachedPrettierOptions: typeof getPrettierOptions & import("lodash").MemoizedFunction;
|
|
92
|
+
export declare function httpGet<T>(url: string, query?: Record<string, any>): Promise<T>;
|