@dazhicheng/openapi 1.1.0 → 1.1.1
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 +6 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/serviceGenerator.d.ts +3 -21
- package/package.json +1 -1
- package/src/cli.ts +28 -28
- package/src/index.d.ts +141 -0
- package/src/index.ts +279 -251
- package/src/log.d.ts +2 -0
- package/src/mockGenerator.d.ts +8 -0
- package/src/openAPIParserMock/index.d.ts +7 -0
- package/src/openAPIParserMock/index.ts +254 -254
- package/src/openAPIParserMock/primitives.d.ts +31 -0
- package/src/openAPIParserMock/utils.d.ts +8 -0
- package/src/serviceGenerator.d.ts +460 -0
- package/src/serviceGenerator.ts +1090 -1065
- package/src/util.d.ts +35 -0
- package/templates/serviceController.njk +7 -1
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 {};
|
|
@@ -19,6 +19,9 @@ export async function {{ api.functionName }}(
|
|
|
19
19
|
{%- else -%}
|
|
20
20
|
{{ api.body.type }}
|
|
21
21
|
{%- endif -%}
|
|
22
|
+
{%- if api.params and api.params.path and api.params.path.length -%}
|
|
23
|
+
& {{namespace}}.{{api.typeName}}
|
|
24
|
+
{%- endif -%}
|
|
22
25
|
{%- endif -%}
|
|
23
26
|
{%- elif api.params and api.hasParams -%}
|
|
24
27
|
params
|
|
@@ -27,8 +30,11 @@ export async function {{ api.functionName }}(
|
|
|
27
30
|
{%- endif -%}
|
|
28
31
|
{%- endif -%}
|
|
29
32
|
) {
|
|
33
|
+
{%- if api.params and api.params.path and api.params.path.length %}
|
|
34
|
+
const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
|
|
35
|
+
{%- endif %}
|
|
30
36
|
return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
|
|
31
|
-
url: '{{ api.path }}',
|
|
37
|
+
url: {{ "`" if api.path and "${" in api.path else "'" }}{{ api.path }}{{ "`" if api.path and "${" in api.path else "'" }},
|
|
32
38
|
{%- if api.body or (api.params and api.hasParams) %}
|
|
33
39
|
{{ "data" if api.method | lower == "delete" else "params" }}: params,
|
|
34
40
|
{%- endif %}
|