@dazhicheng/openapi 1.1.12 → 1.1.14
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/CHANGELOG.md +12 -0
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/cli.d.ts +2 -0
- package/src/cli.ts +28 -28
- package/src/index.d.ts +141 -0
- package/src/index.ts +276 -274
- package/src/log.d.ts +2 -0
- package/src/log.ts +0 -1
- package/src/mockGenerator.d.ts +8 -0
- package/src/mockGenerator.ts +239 -239
- package/src/openAPIParserMock/index.d.ts +7 -0
- package/src/openAPIParserMock/index.ts +0 -3
- package/src/openAPIParserMock/primitives.d.ts +31 -0
- package/src/openAPIParserMock/primitives.ts +30 -30
- package/src/openAPIParserMock/utils.d.ts +8 -0
- package/src/openAPIParserMock/utils.ts +54 -54
- package/src/serviceGenerator.d.ts +460 -0
- package/src/serviceGenerator.ts +1095 -1093
- package/src/util.d.ts +35 -0
- package/src/util.ts +0 -4
- package/templates/interface.njk +54 -54
- package/templates/serviceController.njk +76 -76
- package/templates/serviceIndex.njk +14 -14
package/src/util.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export declare const getAbsolutePath: (filePath: string) => string;
|
|
2
|
+
export declare const mkdir: (dir: string) => void;
|
|
3
|
+
export declare const prettierFile: (content: string) => Promise<[string, boolean]>;
|
|
4
|
+
export declare const writeFile: (folderPath: string, fileName: string, content: string) => Promise<boolean>;
|
|
5
|
+
export declare const getTagName: (name: string) => string | undefined;
|
|
6
|
+
/**
|
|
7
|
+
* 根据当前的数据源类型,对请求回来的 apiInfo 进行格式化
|
|
8
|
+
* 如果是 op 数据源,对 tags 以及 path 中的 tags 进行处理
|
|
9
|
+
* - before: 前缀(产品集.产品码) + 操作对象(必填)+ 子操作对象(可选)+ 动作(必填)
|
|
10
|
+
* - after: 操作对象(必填)+ 子操作对象(可选) ==> 驼峰
|
|
11
|
+
*/
|
|
12
|
+
export declare const formatApiInfo: (apiInfo: Record<string, any>) => any;
|
|
13
|
+
type serviceParam = {
|
|
14
|
+
title: string;
|
|
15
|
+
type: string;
|
|
16
|
+
description: string;
|
|
17
|
+
default: string;
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
type serviceParams = Record<string, serviceParam>;
|
|
21
|
+
/**
|
|
22
|
+
* 一方化场景下,由于 onex 会对请求的响应做处理
|
|
23
|
+
* 1. 将 Response & Request 中的参数字段会变更为小驼峰写法
|
|
24
|
+
* onex 相关代码 : http://gitlab.alipay-inc.com/one-console/sdk/blob/master/src/request.ts#L110
|
|
25
|
+
* 2. 另外要注意:
|
|
26
|
+
* op 返回的数据,请求参数的类型格式 需要做额外的处理
|
|
27
|
+
* - (name) key.n, (type) string ==> key: string []
|
|
28
|
+
* - (name) key.m, (type) string ===> key: string []
|
|
29
|
+
* - (name) key.key1 , (type) string ==> key: {key1:string}
|
|
30
|
+
* - (name) key.n.key1 ,(type) string => key:{ key1 :string}[]
|
|
31
|
+
* - (name) key.n.key1.m,(type) string ==> key:{key1: string[]}[]
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatParamsForYFH(params: serviceParams, paramsObject?: serviceParams): serviceParams;
|
|
34
|
+
export declare const stripDot: (str: string) => string;
|
|
35
|
+
export {};
|
package/src/util.ts
CHANGED
package/templates/interface.njk
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
|
-
declare namespace {{ namespace }} {
|
|
2
|
-
{% for type in list -%}
|
|
3
|
-
{%- if type.props.length %}
|
|
4
|
-
{%- if type.isEnum %}
|
|
5
|
-
enum {{ type.typeName | safe }}
|
|
6
|
-
{%- else %}
|
|
7
|
-
{{ declareType }} {{ type.typeName | safe }} {{ equalSymbol }}
|
|
8
|
-
{%- endif %}
|
|
9
|
-
{%- for prop in type.props %}
|
|
10
|
-
{%- if prop.length > 1 %}
|
|
11
|
-
{
|
|
12
|
-
{%- endif %}
|
|
13
|
-
{%- if prop.length == 1 %}
|
|
14
|
-
{%- if not prop[0].$ref or prop[0].name %}
|
|
15
|
-
{
|
|
16
|
-
{%- endif %}
|
|
17
|
-
{%- endif %}
|
|
18
|
-
{%- for p in prop %}
|
|
19
|
-
{%- if p.desc %}
|
|
20
|
-
/** {{ p.desc }} */
|
|
21
|
-
{%- endif %}
|
|
22
|
-
{%- if p["$ref"] and not p.name %}
|
|
23
|
-
// {{ p.$ref }}
|
|
24
|
-
{{ p.type | safe }}
|
|
25
|
-
{%- else %}
|
|
26
|
-
{%- if nullable %}
|
|
27
|
-
'{{ p.name }}': {{ p.type | safe }}{{'' if p.required else '| null'}};
|
|
28
|
-
{%- else %}
|
|
29
|
-
'{{ p.name }}'{{ '' if p.required else '?' }}: {{ p.type | safe }};
|
|
30
|
-
{%- endif %}
|
|
31
|
-
{%- endif %}
|
|
32
|
-
{%- endfor %}
|
|
33
|
-
{%- if prop.length > 1 %}
|
|
34
|
-
}
|
|
35
|
-
{%- endif %}
|
|
36
|
-
{%- if prop.length == 1 %}
|
|
37
|
-
{%- if not prop[0].$ref or prop[0].name %}
|
|
38
|
-
}
|
|
39
|
-
{%- endif %}
|
|
40
|
-
{%- endif %}
|
|
41
|
-
{%- if prop.length == 0 %}
|
|
42
|
-
{}
|
|
43
|
-
{%- endif %}
|
|
44
|
-
{{ '' if loop.last === true else ' & ' }}
|
|
45
|
-
{%- endfor %}
|
|
46
|
-
{%- else %}
|
|
47
|
-
{%- if type.isEnum %}
|
|
48
|
-
enum {{ type.typeName | safe }} {{ type.type }};
|
|
49
|
-
{%- else %}
|
|
50
|
-
type {{ type.typeName | safe }} = {{ type.type }};
|
|
51
|
-
{%- endif %}
|
|
52
|
-
{%- endif %}
|
|
53
|
-
{% endfor %}
|
|
54
|
-
}
|
|
1
|
+
declare namespace {{ namespace }} {
|
|
2
|
+
{% for type in list -%}
|
|
3
|
+
{%- if type.props.length %}
|
|
4
|
+
{%- if type.isEnum %}
|
|
5
|
+
enum {{ type.typeName | safe }}
|
|
6
|
+
{%- else %}
|
|
7
|
+
{{ declareType }} {{ type.typeName | safe }} {{ equalSymbol }}
|
|
8
|
+
{%- endif %}
|
|
9
|
+
{%- for prop in type.props %}
|
|
10
|
+
{%- if prop.length > 1 %}
|
|
11
|
+
{
|
|
12
|
+
{%- endif %}
|
|
13
|
+
{%- if prop.length == 1 %}
|
|
14
|
+
{%- if not prop[0].$ref or prop[0].name %}
|
|
15
|
+
{
|
|
16
|
+
{%- endif %}
|
|
17
|
+
{%- endif %}
|
|
18
|
+
{%- for p in prop %}
|
|
19
|
+
{%- if p.desc %}
|
|
20
|
+
/** {{ p.desc }} */
|
|
21
|
+
{%- endif %}
|
|
22
|
+
{%- if p["$ref"] and not p.name %}
|
|
23
|
+
// {{ p.$ref }}
|
|
24
|
+
{{ p.type | safe }}
|
|
25
|
+
{%- else %}
|
|
26
|
+
{%- if nullable %}
|
|
27
|
+
'{{ p.name }}': {{ p.type | safe }}{{'' if p.required else '| null'}};
|
|
28
|
+
{%- else %}
|
|
29
|
+
'{{ p.name }}'{{ '' if p.required else '?' }}: {{ p.type | safe }};
|
|
30
|
+
{%- endif %}
|
|
31
|
+
{%- endif %}
|
|
32
|
+
{%- endfor %}
|
|
33
|
+
{%- if prop.length > 1 %}
|
|
34
|
+
}
|
|
35
|
+
{%- endif %}
|
|
36
|
+
{%- if prop.length == 1 %}
|
|
37
|
+
{%- if not prop[0].$ref or prop[0].name %}
|
|
38
|
+
}
|
|
39
|
+
{%- endif %}
|
|
40
|
+
{%- endif %}
|
|
41
|
+
{%- if prop.length == 0 %}
|
|
42
|
+
{}
|
|
43
|
+
{%- endif %}
|
|
44
|
+
{{ '' if loop.last === true else ' & ' }}
|
|
45
|
+
{%- endfor %}
|
|
46
|
+
{%- else %}
|
|
47
|
+
{%- if type.isEnum %}
|
|
48
|
+
enum {{ type.typeName | safe }} {{ type.type }};
|
|
49
|
+
{%- else %}
|
|
50
|
+
type {{ type.typeName | safe }} = {{ type.type }};
|
|
51
|
+
{%- endif %}
|
|
52
|
+
{%- endif %}
|
|
53
|
+
{% endfor %}
|
|
54
|
+
}
|
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
{{ requestImportStatement }}
|
|
4
|
-
|
|
5
|
-
{% for api in list -%}
|
|
6
|
-
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
|
|
7
|
-
export async function {{ api.functionName }}(
|
|
8
|
-
{%- if api.body -%}
|
|
9
|
-
body
|
|
10
|
-
{%- if genType === "ts" -%}
|
|
11
|
-
: {% if api.body.propertiesList %}{
|
|
12
|
-
{%- for prop in api.body.propertiesList %}
|
|
13
|
-
{% if prop.schema.description -%}
|
|
14
|
-
/** {{ prop.schema.description }} */
|
|
15
|
-
{% endif -%}
|
|
16
|
-
{{ prop.key }}{{ "?" if not prop.schema.required }}: {{ prop.schema.type }},
|
|
17
|
-
{%- endfor %}
|
|
18
|
-
}
|
|
19
|
-
{%- else -%}
|
|
20
|
-
{{ api.body.type }}
|
|
21
|
-
{%- endif -%}
|
|
22
|
-
{%- if api.params and api.hasParams -%}
|
|
23
|
-
& {{namespace}}.{{api.typeName}}
|
|
24
|
-
{%- endif -%}
|
|
25
|
-
{%- endif -%}
|
|
26
|
-
{%- endif -%}
|
|
27
|
-
{%- if not api.body and api.params and api.hasParams -%}
|
|
28
|
-
params
|
|
29
|
-
{%- if genType === "ts" -%}
|
|
30
|
-
: {{namespace}}.{{api.typeName}}
|
|
31
|
-
{%- endif -%}
|
|
32
|
-
{%- endif -%}
|
|
33
|
-
{%- if api.body or (api.params and api.hasParams) -%}
|
|
34
|
-
,
|
|
35
|
-
{%- endif -%}
|
|
36
|
-
{%- if genType === "ts" -%}
|
|
37
|
-
options?: { [key: string]: any }
|
|
38
|
-
{%- else -%}
|
|
39
|
-
options
|
|
40
|
-
{%- endif -%}
|
|
41
|
-
) {
|
|
42
|
-
{%- if api.body and api.params and api.hasParams and api.params.path and api.params.path.length %}
|
|
43
|
-
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = body;
|
|
44
|
-
{%- endif %}
|
|
45
|
-
{%- if api.params and api.params.path and api.params.path.length %}
|
|
46
|
-
{%- if not api.body %}
|
|
47
|
-
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
48
|
-
{%- endif %}
|
|
49
|
-
{%- endif %}
|
|
50
|
-
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
51
|
-
url: {{ ("`" + api.path | safe + "`") }},
|
|
52
|
-
{%- if api.params and api.hasParams and not api.body %}
|
|
53
|
-
params: {
|
|
54
|
-
{%- for query in api.params.query %}
|
|
55
|
-
{% if query.schema.default -%}
|
|
56
|
-
// {{query.name | safe}} has a default value: {{ query.schema.default | safe }}
|
|
57
|
-
'{{query.name | safe}}': '{{query.schema.default | safe}}',
|
|
58
|
-
{%- endif -%}
|
|
59
|
-
{%- endfor -%}
|
|
60
|
-
...{{ 'params' }},
|
|
61
|
-
{%- for query in api.params.query %}
|
|
62
|
-
{%- if query.isComplexType %}
|
|
63
|
-
'{{query.name | safe}}': undefined,
|
|
64
|
-
...{{ 'params' }}['{{query.name | safe}}'],
|
|
65
|
-
{%- endif %}
|
|
66
|
-
{%- endfor -%}
|
|
67
|
-
},
|
|
68
|
-
{%- endif %}
|
|
69
|
-
{%- if api.body %}
|
|
70
|
-
data: body,
|
|
71
|
-
{%- endif %}
|
|
72
|
-
...(options || {}),
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
{% endfor -%}
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
{{ requestImportStatement }}
|
|
4
|
+
|
|
5
|
+
{% for api in list -%}
|
|
6
|
+
/** {{ api.desc if api.desc else '此处后端没有提供注释' }} {{api.method | upper}} {{ api.pathInComment | safe }} */
|
|
7
|
+
export async function {{ api.functionName }}(
|
|
8
|
+
{%- if api.body -%}
|
|
9
|
+
body
|
|
10
|
+
{%- if genType === "ts" -%}
|
|
11
|
+
: {% if api.body.propertiesList %}{
|
|
12
|
+
{%- for prop in api.body.propertiesList %}
|
|
13
|
+
{% if prop.schema.description -%}
|
|
14
|
+
/** {{ prop.schema.description }} */
|
|
15
|
+
{% endif -%}
|
|
16
|
+
{{ prop.key }}{{ "?" if not prop.schema.required }}: {{ prop.schema.type }},
|
|
17
|
+
{%- endfor %}
|
|
18
|
+
}
|
|
19
|
+
{%- else -%}
|
|
20
|
+
{{ api.body.type }}
|
|
21
|
+
{%- endif -%}
|
|
22
|
+
{%- if api.params and api.hasParams -%}
|
|
23
|
+
& {{namespace}}.{{api.typeName}}
|
|
24
|
+
{%- endif -%}
|
|
25
|
+
{%- endif -%}
|
|
26
|
+
{%- endif -%}
|
|
27
|
+
{%- if not api.body and api.params and api.hasParams -%}
|
|
28
|
+
params
|
|
29
|
+
{%- if genType === "ts" -%}
|
|
30
|
+
: {{namespace}}.{{api.typeName}}
|
|
31
|
+
{%- endif -%}
|
|
32
|
+
{%- endif -%}
|
|
33
|
+
{%- if api.body or (api.params and api.hasParams) -%}
|
|
34
|
+
,
|
|
35
|
+
{%- endif -%}
|
|
36
|
+
{%- if genType === "ts" -%}
|
|
37
|
+
options?: { [key: string]: any }
|
|
38
|
+
{%- else -%}
|
|
39
|
+
options
|
|
40
|
+
{%- endif -%}
|
|
41
|
+
) {
|
|
42
|
+
{%- if api.body and api.params and api.hasParams and api.params.path and api.params.path.length %}
|
|
43
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = body;
|
|
44
|
+
{%- endif %}
|
|
45
|
+
{%- if api.params and api.params.path and api.params.path.length %}
|
|
46
|
+
{%- if not api.body %}
|
|
47
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
48
|
+
{%- endif %}
|
|
49
|
+
{%- endif %}
|
|
50
|
+
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
51
|
+
url: {{ ("`" + api.path | safe + "`") }},
|
|
52
|
+
{%- if api.params and api.hasParams and not api.body %}
|
|
53
|
+
params: {
|
|
54
|
+
{%- for query in api.params.query %}
|
|
55
|
+
{% if query.schema.default -%}
|
|
56
|
+
// {{query.name | safe}} has a default value: {{ query.schema.default | safe }}
|
|
57
|
+
'{{query.name | safe}}': '{{query.schema.default | safe}}',
|
|
58
|
+
{%- endif -%}
|
|
59
|
+
{%- endfor -%}
|
|
60
|
+
...{{ 'params' }},
|
|
61
|
+
{%- for query in api.params.query %}
|
|
62
|
+
{%- if query.isComplexType %}
|
|
63
|
+
'{{query.name | safe}}': undefined,
|
|
64
|
+
...{{ 'params' }}['{{query.name | safe}}'],
|
|
65
|
+
{%- endif %}
|
|
66
|
+
{%- endfor -%}
|
|
67
|
+
},
|
|
68
|
+
{%- endif %}
|
|
69
|
+
{%- if api.body %}
|
|
70
|
+
data: body,
|
|
71
|
+
{%- endif %}
|
|
72
|
+
...(options || {}),
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
{% endfor -%}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
// @ts-ignore
|
|
2
|
-
/* eslint-disable */
|
|
3
|
-
// API 更新时间:{{ apiResourceModifyTime }}
|
|
4
|
-
// API 唯一标识:{{ apiResourceId }}
|
|
5
|
-
{% for api in list -%}
|
|
6
|
-
import * as {{ api.controllerName }} from './{{ api.fileName }}'
|
|
7
|
-
{% endfor -%}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default {
|
|
11
|
-
{% for api in list -%}
|
|
12
|
-
{{ api.controllerName }},
|
|
13
|
-
{% endfor -%}
|
|
14
|
-
}
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
// API 更新时间:{{ apiResourceModifyTime }}
|
|
4
|
+
// API 唯一标识:{{ apiResourceId }}
|
|
5
|
+
{% for api in list -%}
|
|
6
|
+
import * as {{ api.controllerName }} from './{{ api.fileName }}'
|
|
7
|
+
{% endfor -%}
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
export default {
|
|
11
|
+
{% for api in list -%}
|
|
12
|
+
{{ api.controllerName }},
|
|
13
|
+
{% endfor -%}
|
|
14
|
+
}
|