@dazhicheng/openapi 1.1.4 → 1.1.6

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.
@@ -1,44 +1,53 @@
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
- params
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.params.path and api.params.path.length -%}
23
- & {{namespace}}.{{api.typeName}}
24
- {%- endif -%}
25
- {%- endif -%}
26
- {%- elif api.params and api.hasParams -%}
27
- params
28
- {%- if genType === "ts" -%}
29
- : {{namespace}}.{{api.typeName}}
30
- {%- endif -%}
31
- {%- endif -%}
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 %}
36
- return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
37
- url: {{ "`" if api.path and "${" in api.path else "'" }}{{ api.path }}{{ "`" if api.path and "${" in api.path else "'" }},
38
- {%- if api.body or (api.params and api.hasParams) %}
39
- {{ "data" if api.method | lower == "delete" else "params" }}: params,
40
- {%- endif %}
41
- });
42
- }
43
-
44
- {% 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
+ params
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.params.path and api.params.path.length -%}
23
+ & {{namespace}}.{{api.typeName}}
24
+ {%- endif -%}
25
+ {%- endif -%}
26
+ {%- elif api.params and api.hasParams -%}
27
+ params
28
+ {%- if genType === "ts" -%}
29
+ : {{namespace}}.{{api.typeName}}
30
+ {%- endif -%}
31
+ {%- endif -%}
32
+ {%- if api.body or (api.params and api.hasParams) -%}
33
+ ,
34
+ {%- endif -%}
35
+ {%- if genType === "ts" -%}
36
+ options?: { [key: string]: any }
37
+ {%- else -%}
38
+ options
39
+ {%- endif -%}
40
+ ) {
41
+ {%- if api.params and api.params.path and api.params.path.length %}
42
+ const { {% for p in api.params.path %}{{ p.name }}{{ ", " if not loop.last }}{% endfor %} } = params;
43
+ {%- endif %}
44
+ return request.{{ "del" if api.method | lower == "delete" else api.method | lower }}{{ ("<" + api.response.type + ">") | safe if genType === "ts" }}({
45
+ url: {{ "`" if api.path and "${" in api.path else "'" }}{{ api.path }}{{ "`" if api.path and "${" in api.path else "'" }},
46
+ {%- if api.body or (api.params and api.hasParams) %}
47
+ {{ "data" if api.method | lower == "delete" else "params" }}: params,
48
+ {%- endif %}
49
+ ...(options ?? {}),
50
+ });
51
+ }
52
+
53
+ {% endfor -%}
package/src/index.d.ts DELETED
@@ -1,141 +0,0 @@
1
- import type { OpenAPIObject, OperationObject, SchemaObject } from "openapi3-ts";
2
- import type { APIDataType } from "./serviceGenerator";
3
- export type GenerateServiceProps = {
4
- requestLibPath?: string;
5
- requestOptionsType?: string;
6
- requestImportStatement?: string;
7
- declareType?: "type" | "interface";
8
- /**
9
- * api 的前缀
10
- */
11
- apiPrefix?: string | ((params: {
12
- path: string;
13
- method: string;
14
- namespace: string;
15
- functionName: string;
16
- autoExclude?: boolean;
17
- }) => string);
18
- /**
19
- * 生成的文件夹的路径
20
- */
21
- serversPath?: string;
22
- /**
23
- * Swagger 2.0 或 OpenAPI 3.0 的地址
24
- */
25
- schemaPath?: string;
26
- /**
27
- * 项目名称
28
- */
29
- projectName?: string;
30
- /**
31
- * 文档登录凭证
32
- */
33
- authorization?: string;
34
- hook?: {
35
- /** change open api data after constructor */
36
- afterOpenApiDataInited?: (openAPIData: OpenAPIObject) => OpenAPIObject;
37
- /** 自定义函数名称 */
38
- customFunctionName?: (data: APIDataType) => string;
39
- /** 自定义类型名称 */
40
- customTypeName?: (data: APIDataType) => string;
41
- /** 自定义 options 默认值 */
42
- customOptionsDefaultValue?: (data: OperationObject) => Record<string, any> | undefined;
43
- /** 自定义类名 */
44
- customClassName?: (tagName: string) => string;
45
- /**
46
- * 自定义获取type hook
47
- * 返回非字符串将使用默认方法获取type
48
- * @example set number to string
49
- * function customType(schemaObject,namespace){
50
- * if(schemaObject.type==='number' && !schemaObject.format){
51
- * return 'BigDecimalString';
52
- * }
53
- * }
54
- */
55
- customType?: (schemaObject: SchemaObject | undefined, namespace: string, originGetType: (schemaObject: SchemaObject | undefined, namespace: string) => string) => string;
56
- /**
57
- * 自定义生成文件名,可返回多个,表示生成多个文件
58
- * 返回为空,则使用默认的获取方法获取
59
- * @example 使用operationId生成文件名
60
- * function customFileNames(operationObject,apiPath){
61
- * const operationId=operationObject.operationId;
62
- * if (!operationId) {
63
- * console.warn('[Warning] no operationId', apiPath);
64
- * return;
65
- * }
66
- * const res = operationId.split('_');
67
- * if (res.length > 1) {
68
- * res.shift();
69
- * if (res.length > 2) {
70
- * console.warn('[Warning] operationId has more than 2 part', apiPath);
71
- * }
72
- * return [res.join('_')];
73
- * } else {
74
- * const controllerName = (res || [])[0];
75
- * if (controllerName) {
76
- * return [controllerName];
77
- * }
78
- * return;
79
- * }
80
- * }
81
- */
82
- customFileNames?: (operationObject: OperationObject, apiPath: string, _apiMethod: string) => string[];
83
- };
84
- namespace?: string;
85
- /**
86
- * 默认为false,true时使用null代替可选
87
- */
88
- nullable?: boolean;
89
- mockFolder?: string;
90
- /**
91
- * 模板文件的文件路径
92
- */
93
- templatesFolder?: string;
94
- /**
95
- * 枚举样式
96
- */
97
- enumStyle?: "string-literal" | "enum";
98
- /**
99
- * response中数据字段
100
- * example: ['result', 'res']
101
- */
102
- dataFields?: string[];
103
- /**
104
- * 模板文件、请求函数采用小驼峰命名
105
- */
106
- isCamelCase?: boolean;
107
- /**
108
- * 指定生成的接口路径列表
109
- * 传入则只生成这些接口,不传则全量生成
110
- * @example specifiedPaths: ["/user/list", "/user/detail"]
111
- */
112
- specifiedPaths?: string[];
113
- /**
114
- * mock配置
115
- */
116
- mockConfig?: {
117
- /**
118
- * msw类型mock文件格式. 直接返回对象
119
- * 举例:
120
- * // @ts-ignore
121
-
122
- export default {
123
- 'DELETE /mydata/delete': { message: { message: 'Mydata successfully deleted' } },
124
- };
125
-
126
-
127
- 原文件:
128
- // @ts-ignore
129
- import { Request, Response } from 'express';
130
-
131
- export default {
132
- 'DELETE /mydata/delete': (req: Request, res: Response) => {
133
- res.status(200).send({ message: { message: 'Mydata successfully deleted' } });
134
- },
135
- };
136
- */
137
- msw?: boolean;
138
- };
139
- };
140
- export declare const getSchema: (schemaPath: string, authorization?: string) => Promise<any>;
141
- export declare const ttOpenAPI: (configs: GenerateServiceProps[] | GenerateServiceProps) => Promise<void>;
package/src/log.d.ts DELETED
@@ -1,2 +0,0 @@
1
- declare const Log: (...rest: any[]) => void;
2
- export default Log;
@@ -1,8 +0,0 @@
1
- import { GenerateServiceProps } from "./index";
2
- export type genMockDataServerConfig = {
3
- openAPI: any;
4
- mockFolder: string;
5
- mockConfig: GenerateServiceProps["mockConfig"];
6
- };
7
- declare const mockGenerator: ({ openAPI, mockFolder, mockConfig }: genMockDataServerConfig) => Promise<void>;
8
- export { mockGenerator };
@@ -1,7 +0,0 @@
1
- declare class OpenAPIGeneratorMockJs {
2
- protected openAPI: any;
3
- constructor(openAPI: any);
4
- sampleFromSchema: (schema: any, propsName?: string[], schemaSet?: Set<string>) => any;
5
- parser: () => any;
6
- }
7
- export default OpenAPIGeneratorMockJs;
@@ -1,31 +0,0 @@
1
- declare const _default: {
2
- string: string;
3
- string_email: string;
4
- string_phone: string;
5
- string_username: string;
6
- string_url: string;
7
- string_uuid: string;
8
- string_id: string;
9
- string_status: string;
10
- string_authority: string;
11
- string_label: string;
12
- string_group: string;
13
- string_csentence: string;
14
- string_cname: string;
15
- string_name: string;
16
- string_errorCode: string;
17
- string_country: string;
18
- string_county: string;
19
- string_province: string;
20
- string_city: string;
21
- string_avatar: string;
22
- string_href: string;
23
- "string_string(16)": string;
24
- "string_date-time": string;
25
- string_date: string;
26
- number: string;
27
- number_float: string;
28
- integer: string;
29
- boolean: string;
30
- };
31
- export default _default;
@@ -1,8 +0,0 @@
1
- declare function isObject(obj: any): boolean;
2
- declare function objectify(thing: any): any;
3
- declare function get(entity: any, path: (string | number)[]): any;
4
- declare function normalizeArray(arr: any): any[];
5
- declare function isFunc(thing: any): boolean;
6
- declare function inferSchema(thing: any): any;
7
- declare function getRandomInt(min: any, max: any): number;
8
- export { isObject, get, objectify, isFunc, inferSchema, normalizeArray, getRandomInt };