swagger2api-v3 1.1.6 → 1.1.8
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/README.md +15 -1
- package/dist/.swagger2api.schema.json +120 -0
- package/dist/cli/index.js +119 -47
- package/dist/config/validator.d.ts +7 -0
- package/dist/config/validator.js +218 -0
- package/dist/core/generator.d.ts +7 -1
- package/dist/core/generator.js +26 -44
- package/dist/core/parser.d.ts +13 -1
- package/dist/core/parser.js +54 -40
- package/dist/index.d.ts +6 -0
- package/dist/index.js +21 -13
- package/dist/types/index.d.ts +75 -38
- package/dist/utils/comment.d.ts +8 -0
- package/dist/utils/comment.js +47 -0
- package/dist/utils/file.d.ts +23 -0
- package/dist/utils/file.js +98 -0
- package/dist/utils/index.d.ts +4 -99
- package/dist/utils/index.js +6 -572
- package/dist/utils/naming.d.ts +51 -0
- package/dist/utils/naming.js +124 -0
- package/dist/utils/type.d.ts +39 -0
- package/dist/utils/type.js +331 -0
- package/package.json +3 -2
package/dist/core/generator.js
CHANGED
|
@@ -95,13 +95,12 @@ class CodeGenerator {
|
|
|
95
95
|
* @returns 类型文件内容
|
|
96
96
|
*/
|
|
97
97
|
generateTypesContent(types) {
|
|
98
|
-
const header = [
|
|
98
|
+
const header = this.generateHeader([
|
|
99
99
|
'/**',
|
|
100
100
|
' * API 类型定义',
|
|
101
101
|
' * 此文件由 swagger2api-v3 自动生成,请勿手动修改',
|
|
102
|
-
' */'
|
|
103
|
-
|
|
104
|
-
].join('\n');
|
|
102
|
+
' */'
|
|
103
|
+
]);
|
|
105
104
|
const typeDefinitions = types
|
|
106
105
|
.map((type) => {
|
|
107
106
|
const comment = type.description
|
|
@@ -118,7 +117,7 @@ class CodeGenerator {
|
|
|
118
117
|
return `${comment}${definition}`;
|
|
119
118
|
})
|
|
120
119
|
.join('\n\n');
|
|
121
|
-
return `${header}${typeDefinitions}\n`;
|
|
120
|
+
return `${header}\n\n${typeDefinitions}\n`;
|
|
122
121
|
}
|
|
123
122
|
/**
|
|
124
123
|
* 按标签生成API文件
|
|
@@ -158,11 +157,12 @@ class CodeGenerator {
|
|
|
158
157
|
generateApiFileContent(apis, types, tag) {
|
|
159
158
|
const importTemplate = this.config.importTemplate || "import { request } from '@/utils'";
|
|
160
159
|
const header = [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
160
|
+
this.generateHeader([
|
|
161
|
+
'/**',
|
|
162
|
+
` * ${tag ? `${tag} ` : ''}API 接口`,
|
|
163
|
+
' * 此文件由 swagger2api-v3 自动生成,请勿手动修改',
|
|
164
|
+
' */'
|
|
165
|
+
]),
|
|
166
166
|
importTemplate + ';'
|
|
167
167
|
];
|
|
168
168
|
// 收集当前文件实际使用的类型
|
|
@@ -233,7 +233,7 @@ class CodeGenerator {
|
|
|
233
233
|
}
|
|
234
234
|
/**
|
|
235
235
|
* 生成直接参数形式
|
|
236
|
-
* @param parameters
|
|
236
|
+
* @param parameters OpenAPI 参数数组
|
|
237
237
|
* @returns 函数参数字符串
|
|
238
238
|
*/
|
|
239
239
|
generateDirectParameters(parameters, isJavaScript = false) {
|
|
@@ -241,7 +241,6 @@ class CodeGenerator {
|
|
|
241
241
|
const queryParams = parameters.filter((p) => p.in === 'query');
|
|
242
242
|
const pathParams = parameters.filter((p) => p.in === 'path');
|
|
243
243
|
const bodyParams = parameters.filter((p) => p.in === 'body');
|
|
244
|
-
const formParams = parameters.filter((p) => p.in === 'formData');
|
|
245
244
|
// 合并路径参数和查询参数为一个params对象
|
|
246
245
|
const allParams = [...pathParams, ...queryParams];
|
|
247
246
|
if (allParams.length > 0) {
|
|
@@ -274,21 +273,6 @@ class CodeGenerator {
|
|
|
274
273
|
params.push(`data: ${bodyType}`);
|
|
275
274
|
}
|
|
276
275
|
}
|
|
277
|
-
// 表单参数
|
|
278
|
-
if (formParams.length > 0) {
|
|
279
|
-
if (isJavaScript) {
|
|
280
|
-
params.push('data');
|
|
281
|
-
}
|
|
282
|
-
else {
|
|
283
|
-
const formType = formParams
|
|
284
|
-
.map((p) => {
|
|
285
|
-
const optional = p.required ? '' : '?';
|
|
286
|
-
return `${p.name}${optional}: ${p.type}`;
|
|
287
|
-
})
|
|
288
|
-
.join(', ');
|
|
289
|
-
params.push(`data: { ${formType} }`);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
276
|
// 添加可选的config参数
|
|
293
277
|
params.push(isJavaScript ? 'config' : 'config?: any');
|
|
294
278
|
return params.join(', ');
|
|
@@ -299,9 +283,6 @@ class CodeGenerator {
|
|
|
299
283
|
* @returns 类型字符串
|
|
300
284
|
*/
|
|
301
285
|
getTypeFromSchema(schema) {
|
|
302
|
-
if (schema.$ref) {
|
|
303
|
-
return schema.$ref.split('/').pop() || 'any';
|
|
304
|
-
}
|
|
305
286
|
return (0, utils_1.swaggerTypeToTsType)(schema);
|
|
306
287
|
}
|
|
307
288
|
/**
|
|
@@ -395,7 +376,7 @@ class CodeGenerator {
|
|
|
395
376
|
// 检查是否包含 data 字段且类型为 Record<string, any>
|
|
396
377
|
const hasDataField = definition.includes('data: Record<string, any>;');
|
|
397
378
|
// 检查是否包含其他常见的响应容器字段
|
|
398
|
-
const hasCommonFields = ['code', 'message', 'success', 'status'].some((field) =>
|
|
379
|
+
const hasCommonFields = ['code', 'message', 'success', 'status'].some((field) => new RegExp(`\\b${field}\\??:`).test(definition));
|
|
399
380
|
return hasDataField && hasCommonFields;
|
|
400
381
|
}
|
|
401
382
|
/**
|
|
@@ -430,13 +411,9 @@ class CodeGenerator {
|
|
|
430
411
|
}
|
|
431
412
|
// 请求体数据
|
|
432
413
|
const bodyParams = api.parameters.filter((p) => p.in === 'body');
|
|
433
|
-
const formParams = api.parameters.filter((p) => p.in === 'formData');
|
|
434
414
|
if (bodyParams.length > 0) {
|
|
435
415
|
config.push('data');
|
|
436
416
|
}
|
|
437
|
-
else if (formParams.length > 0) {
|
|
438
|
-
config.push('data');
|
|
439
|
-
}
|
|
440
417
|
// 在通用请求风格下添加 method 字段
|
|
441
418
|
if (includeMethod) {
|
|
442
419
|
config.push(`method: '${api.method}'`);
|
|
@@ -467,15 +444,7 @@ class CodeGenerator {
|
|
|
467
444
|
// 导出单个API文件
|
|
468
445
|
exports.push("export * from './api';");
|
|
469
446
|
}
|
|
470
|
-
const content = [
|
|
471
|
-
'/**',
|
|
472
|
-
' * API 入口文件',
|
|
473
|
-
' * 此文件由 swagger2api-v3 自动生成,请勿手动修改',
|
|
474
|
-
' */',
|
|
475
|
-
'',
|
|
476
|
-
...exports,
|
|
477
|
-
''
|
|
478
|
-
].join('\n');
|
|
447
|
+
const content = [this.generateHeader(), '', ...exports, ''].join('\n');
|
|
479
448
|
const ext = this.config.generator === 'javascript' ? 'js' : 'ts';
|
|
480
449
|
const filePath = path.join(this.config.output, `index.${ext}`);
|
|
481
450
|
(0, utils_1.writeFile)(filePath, content);
|
|
@@ -498,6 +467,19 @@ class CodeGenerator {
|
|
|
498
467
|
return (0, utils_1.toCamelCase)(cleanTag);
|
|
499
468
|
}
|
|
500
469
|
}
|
|
470
|
+
/**
|
|
471
|
+
* 生成文件头部注释
|
|
472
|
+
* @param defaultHeader 默认头部注释
|
|
473
|
+
* @returns 文件头部注释内容
|
|
474
|
+
*/
|
|
475
|
+
generateHeader(defaultHeader = [
|
|
476
|
+
'/**',
|
|
477
|
+
' * API 入口文件',
|
|
478
|
+
' * 此文件由 swagger2api-v3 自动生成,请勿手动修改',
|
|
479
|
+
' */'
|
|
480
|
+
]) {
|
|
481
|
+
return this.config.headerComment?.trim() || defaultHeader.join('\n');
|
|
482
|
+
}
|
|
501
483
|
/**
|
|
502
484
|
* 在所有文件生成完成后运行lint命令
|
|
503
485
|
*/
|
package/dist/core/parser.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ export declare class SwaggerParser {
|
|
|
7
7
|
private config;
|
|
8
8
|
constructor(document: SwaggerDocument, config: SwaggerConfig);
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* 获取 OpenAPI components.schemas
|
|
11
11
|
* @returns schemas 对象
|
|
12
12
|
*/
|
|
13
13
|
private getAllSchemas;
|
|
@@ -37,6 +37,12 @@ export declare class SwaggerParser {
|
|
|
37
37
|
* @returns 类型信息
|
|
38
38
|
*/
|
|
39
39
|
private parseTypeDefinition;
|
|
40
|
+
/**
|
|
41
|
+
* 解析本地 $ref 引用对象
|
|
42
|
+
* @param value 可能带有 $ref 的对象
|
|
43
|
+
* @returns 引用解析后的对象
|
|
44
|
+
*/
|
|
45
|
+
private resolveReference;
|
|
40
46
|
/**
|
|
41
47
|
* 按标签分组API
|
|
42
48
|
* @param apis API接口数组
|
|
@@ -53,6 +59,12 @@ export declare class SwaggerParser {
|
|
|
53
59
|
* @returns 基础URL字符串
|
|
54
60
|
*/
|
|
55
61
|
getBaseUrl(): string;
|
|
62
|
+
/**
|
|
63
|
+
* 解析 OpenAPI server 地址
|
|
64
|
+
* @param server OpenAPI server 对象
|
|
65
|
+
* @returns 替换默认变量后的 server URL
|
|
66
|
+
*/
|
|
67
|
+
private resolveServerUrl;
|
|
56
68
|
/**
|
|
57
69
|
* 获取API文档信息
|
|
58
70
|
* @returns API文档基本信息
|
package/dist/core/parser.js
CHANGED
|
@@ -11,14 +11,11 @@ class SwaggerParser {
|
|
|
11
11
|
this.config = config;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* 获取 OpenAPI components.schemas
|
|
15
15
|
* @returns schemas 对象
|
|
16
16
|
*/
|
|
17
17
|
getAllSchemas() {
|
|
18
|
-
return {
|
|
19
|
-
...(this.document.definitions || {}),
|
|
20
|
-
...(this.document.components?.schemas || {})
|
|
21
|
-
};
|
|
18
|
+
return this.document.components?.schemas || {};
|
|
22
19
|
}
|
|
23
20
|
/**
|
|
24
21
|
* 解析所有API接口
|
|
@@ -60,22 +57,20 @@ class SwaggerParser {
|
|
|
60
57
|
const allParameters = [
|
|
61
58
|
...(globalParameters || []),
|
|
62
59
|
...(operation.parameters || [])
|
|
63
|
-
];
|
|
60
|
+
].map((parameter) => this.resolveReference(parameter));
|
|
64
61
|
// 处理 OpenAPI 3.0 requestBody
|
|
65
62
|
if (operation.requestBody) {
|
|
66
|
-
const requestBody = operation.requestBody;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
allParameters.push(bodyParam);
|
|
78
|
-
}
|
|
63
|
+
const requestBody = this.resolveReference(operation.requestBody);
|
|
64
|
+
const schema = (0, utils_1.getSchemaFromContent)(requestBody.content);
|
|
65
|
+
if (schema) {
|
|
66
|
+
const bodyParam = {
|
|
67
|
+
name: 'body',
|
|
68
|
+
in: 'body',
|
|
69
|
+
required: requestBody.required || false,
|
|
70
|
+
schema,
|
|
71
|
+
type: 'object'
|
|
72
|
+
};
|
|
73
|
+
allParameters.push(bodyParam);
|
|
79
74
|
}
|
|
80
75
|
}
|
|
81
76
|
// 生成函数名
|
|
@@ -99,7 +94,7 @@ class SwaggerParser {
|
|
|
99
94
|
// 应用前缀忽略规则
|
|
100
95
|
functionName = (0, utils_1.stripMethodNamePrefixes)(functionName, this.config.methodNameIgnorePrefix);
|
|
101
96
|
// 获取响应类型
|
|
102
|
-
const responseType = (0, utils_1.getResponseType)(operation.responses);
|
|
97
|
+
const responseType = (0, utils_1.getResponseType)(operation.responses, this.getAllSchemas());
|
|
103
98
|
// 获取请求体类型
|
|
104
99
|
const bodyParam = allParameters.find((p) => p.in === 'body');
|
|
105
100
|
const requestBodyType = bodyParam
|
|
@@ -107,16 +102,14 @@ class SwaggerParser {
|
|
|
107
102
|
: undefined;
|
|
108
103
|
// 解析参数信息
|
|
109
104
|
const parameters = allParameters.map((param) => {
|
|
110
|
-
const type = param.
|
|
111
|
-
? (0, utils_1.swaggerTypeToTsType)(param.schema)
|
|
112
|
-
: (0, utils_1.swaggerTypeToTsType)({ type: param.type || 'string' });
|
|
105
|
+
const type = (0, utils_1.swaggerTypeToTsType)((0, utils_1.swaggerParameterToSchema)(param), this.getAllSchemas());
|
|
113
106
|
return {
|
|
114
107
|
name: param.name,
|
|
115
108
|
type,
|
|
116
109
|
in: param.in,
|
|
117
110
|
required: param.required || false,
|
|
118
111
|
description: param.description,
|
|
119
|
-
schema: param
|
|
112
|
+
schema: (0, utils_1.swaggerParameterToSchema)(param)
|
|
120
113
|
};
|
|
121
114
|
});
|
|
122
115
|
return {
|
|
@@ -138,7 +131,6 @@ class SwaggerParser {
|
|
|
138
131
|
const types = [];
|
|
139
132
|
// Debug log
|
|
140
133
|
console.log('解析类型定义...');
|
|
141
|
-
console.log('Has definitions:', !!this.document.definitions);
|
|
142
134
|
console.log('Has components:', !!this.document.components);
|
|
143
135
|
if (this.document.components) {
|
|
144
136
|
console.log('Has schemas:', !!this.document.components.schemas);
|
|
@@ -146,15 +138,7 @@ class SwaggerParser {
|
|
|
146
138
|
console.log('Schema keys:', Object.keys(this.document.components.schemas));
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
|
-
// 解析
|
|
150
|
-
if (this.document.definitions) {
|
|
151
|
-
for (const [name, schema] of Object.entries(this.document.definitions)) {
|
|
152
|
-
const sanitizedName = (0, utils_1.sanitizeTypeName)(name); // Use it
|
|
153
|
-
const typeInfo = this.parseTypeDefinition(sanitizedName, schema);
|
|
154
|
-
types.push(typeInfo);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
// 解析 OpenAPI 3.0 components.schemas
|
|
141
|
+
// 解析 OpenAPI 3.x components.schemas
|
|
158
142
|
if (this.document.components?.schemas) {
|
|
159
143
|
for (const [name, schema] of Object.entries(this.document.components.schemas)) {
|
|
160
144
|
const sanitizedName = (0, utils_1.sanitizeTypeName)(name); // Use it
|
|
@@ -232,6 +216,25 @@ class SwaggerParser {
|
|
|
232
216
|
description: schema.description
|
|
233
217
|
};
|
|
234
218
|
}
|
|
219
|
+
/**
|
|
220
|
+
* 解析本地 $ref 引用对象
|
|
221
|
+
* @param value 可能带有 $ref 的对象
|
|
222
|
+
* @returns 引用解析后的对象
|
|
223
|
+
*/
|
|
224
|
+
resolveReference(value) {
|
|
225
|
+
if (!value || !value.$ref) {
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
const refPath = value.$ref.replace(/^#\//, '').split('/');
|
|
229
|
+
let current = this.document;
|
|
230
|
+
for (const segment of refPath) {
|
|
231
|
+
current = current?.[segment];
|
|
232
|
+
if (!current) {
|
|
233
|
+
return value;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return current;
|
|
237
|
+
}
|
|
235
238
|
/**
|
|
236
239
|
* 按标签分组API
|
|
237
240
|
* @param apis API接口数组
|
|
@@ -285,12 +288,23 @@ class SwaggerParser {
|
|
|
285
288
|
* @returns 基础URL字符串
|
|
286
289
|
*/
|
|
287
290
|
getBaseUrl() {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
const server = this.document.servers?.[0];
|
|
292
|
+
if (!server)
|
|
293
|
+
return '';
|
|
294
|
+
return this.resolveServerUrl(server);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* 解析 OpenAPI server 地址
|
|
298
|
+
* @param server OpenAPI server 对象
|
|
299
|
+
* @returns 替换默认变量后的 server URL
|
|
300
|
+
*/
|
|
301
|
+
resolveServerUrl(server) {
|
|
302
|
+
if (!server.variables)
|
|
303
|
+
return server.url;
|
|
304
|
+
return server.url.replace(/\{([^}]+)\}/g, (match, name) => {
|
|
305
|
+
const variable = server.variables?.[name];
|
|
306
|
+
return variable?.default ?? match;
|
|
307
|
+
});
|
|
294
308
|
}
|
|
295
309
|
/**
|
|
296
310
|
* 获取API文档信息
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -44,6 +44,7 @@ const fs = __importStar(require("fs"));
|
|
|
44
44
|
const parser_1 = require("./core/parser");
|
|
45
45
|
const generator_1 = require("./core/generator");
|
|
46
46
|
const utils_1 = require("./utils");
|
|
47
|
+
const validator_1 = require("./config/validator");
|
|
47
48
|
/**
|
|
48
49
|
* Swagger2API 主类
|
|
49
50
|
*/
|
|
@@ -69,7 +70,7 @@ class Swagger2API {
|
|
|
69
70
|
// 2. 解析文档
|
|
70
71
|
console.log('🔍 解析API接口...');
|
|
71
72
|
const parser = new parser_1.SwaggerParser(document, this.config);
|
|
72
|
-
const apis = parser.parseApis();
|
|
73
|
+
const apis = this.filterApis(parser.parseApis());
|
|
73
74
|
const types = parser.parseTypes();
|
|
74
75
|
const groupedApis = parser.groupApisByTags(apis);
|
|
75
76
|
console.log(`✅ 解析完成: ${apis.length} 个接口, ${types.length} 个类型`);
|
|
@@ -94,18 +95,7 @@ class Swagger2API {
|
|
|
94
95
|
* 验证配置
|
|
95
96
|
*/
|
|
96
97
|
validateConfig() {
|
|
97
|
-
const errors =
|
|
98
|
-
if (!this.config.input) {
|
|
99
|
-
errors.push('input 配置项不能为空');
|
|
100
|
-
}
|
|
101
|
-
if (!this.config.output) {
|
|
102
|
-
errors.push('output 配置项不能为空');
|
|
103
|
-
}
|
|
104
|
-
// 支持 typescript 与 javascript 两种生成器
|
|
105
|
-
if (this.config.generator !== 'typescript' &&
|
|
106
|
-
this.config.generator !== 'javascript') {
|
|
107
|
-
errors.push('目前只支持 typescript 或 javascript 生成器');
|
|
108
|
-
}
|
|
98
|
+
const errors = (0, validator_1.validateSwaggerConfig)(this.config);
|
|
109
99
|
if (errors.length > 0) {
|
|
110
100
|
console.error('❌ 配置验证失败:');
|
|
111
101
|
errors.forEach((error) => console.error(` - ${error}`));
|
|
@@ -113,6 +103,24 @@ class Swagger2API {
|
|
|
113
103
|
}
|
|
114
104
|
return true;
|
|
115
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* 根据配置过滤 API
|
|
108
|
+
* @param apis API接口数组
|
|
109
|
+
* @returns 过滤后的 API接口数组
|
|
110
|
+
*/
|
|
111
|
+
filterApis(apis) {
|
|
112
|
+
const includeTags = this.config.filter?.include?.tags;
|
|
113
|
+
const excludeTags = this.config.filter?.exclude?.tags;
|
|
114
|
+
if (!includeTags?.length && !excludeTags?.length) {
|
|
115
|
+
return apis;
|
|
116
|
+
}
|
|
117
|
+
return apis.filter((api) => {
|
|
118
|
+
const tags = api.tags || [];
|
|
119
|
+
const included = !includeTags?.length || tags.some((tag) => includeTags.includes(tag));
|
|
120
|
+
const excluded = !!excludeTags?.length && tags.some((tag) => excludeTags.includes(tag));
|
|
121
|
+
return included && !excluded;
|
|
122
|
+
});
|
|
123
|
+
}
|
|
116
124
|
}
|
|
117
125
|
exports.Swagger2API = Swagger2API;
|
|
118
126
|
/**
|
package/dist/types/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* Swagger配置接口
|
|
6
6
|
*/
|
|
7
7
|
export interface SwaggerConfig {
|
|
8
|
+
/** 本地 JSON Schema 路径,用于编辑器提示 */
|
|
9
|
+
$schema?: string;
|
|
8
10
|
/** Swagger JSON 文件路径或 URL */
|
|
9
11
|
input: string;
|
|
10
12
|
/** 输出目录 */
|
|
@@ -33,65 +35,96 @@ export interface SwaggerConfig {
|
|
|
33
35
|
methodNameIgnorePrefix?: string[];
|
|
34
36
|
/** 是否在生成的方法名中添加 HTTP method 后缀,默认为 true。true: userListPost, false: userList */
|
|
35
37
|
addMethodSuffix?: boolean;
|
|
38
|
+
/** 接口过滤配置 */
|
|
39
|
+
filter?: FilterConfig;
|
|
40
|
+
/** 自定义生成文件头部注释 */
|
|
41
|
+
headerComment?: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 接口过滤配置
|
|
45
|
+
*/
|
|
46
|
+
export interface FilterConfig {
|
|
47
|
+
/** 包含规则 */
|
|
48
|
+
include?: TagFilterConfig;
|
|
49
|
+
/** 排除规则 */
|
|
50
|
+
exclude?: TagFilterConfig;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* 标签过滤配置
|
|
54
|
+
*/
|
|
55
|
+
export interface TagFilterConfig {
|
|
56
|
+
/** 需要匹配的标签名称 */
|
|
57
|
+
tags?: string[];
|
|
36
58
|
}
|
|
37
59
|
/**
|
|
38
60
|
* 标签分组配置
|
|
39
61
|
*/
|
|
40
62
|
export interface TagGroupingConfig {
|
|
41
63
|
/** 启用标签分组 */
|
|
42
|
-
enabled
|
|
64
|
+
enabled?: boolean;
|
|
43
65
|
/** 为每个标签创建子目录 */
|
|
44
|
-
createSubDirectories
|
|
66
|
+
createSubDirectories?: boolean;
|
|
45
67
|
/** 文件命名方式 */
|
|
46
|
-
fileNaming
|
|
68
|
+
fileNaming?: 'tag' | 'kebab-case' | 'camelCase';
|
|
47
69
|
}
|
|
48
70
|
/**
|
|
49
71
|
* 生成选项
|
|
50
72
|
*/
|
|
51
73
|
export interface GenerationOptions {
|
|
52
74
|
/** 是否生成数据模型 */
|
|
53
|
-
generateModels
|
|
75
|
+
generateModels?: boolean;
|
|
54
76
|
/** 是否生成 API 接口 */
|
|
55
|
-
generateApis
|
|
77
|
+
generateApis?: boolean;
|
|
56
78
|
/** 是否生成入口文件 */
|
|
57
|
-
generateIndex
|
|
79
|
+
generateIndex?: boolean;
|
|
58
80
|
/** 是否使用 Axios */
|
|
59
|
-
useAxios
|
|
81
|
+
useAxios?: boolean;
|
|
60
82
|
/** 是否添加详细注释 */
|
|
61
|
-
addComments
|
|
83
|
+
addComments?: boolean;
|
|
62
84
|
/** 是否格式化代码 */
|
|
63
|
-
prettify
|
|
85
|
+
prettify?: boolean;
|
|
64
86
|
}
|
|
65
87
|
/**
|
|
66
88
|
* 注释配置
|
|
67
89
|
*/
|
|
68
90
|
export interface CommentConfig {
|
|
69
91
|
/** 包含接口描述 */
|
|
70
|
-
includeDescription
|
|
92
|
+
includeDescription?: boolean;
|
|
71
93
|
/** 包含参数信息 */
|
|
72
|
-
includeParameters
|
|
94
|
+
includeParameters?: boolean;
|
|
73
95
|
/** 包含返回值信息 */
|
|
74
|
-
includeResponses
|
|
96
|
+
includeResponses?: boolean;
|
|
75
97
|
/** 包含示例 */
|
|
76
|
-
includeExamples
|
|
98
|
+
includeExamples?: boolean;
|
|
77
99
|
}
|
|
78
100
|
/**
|
|
79
|
-
*
|
|
101
|
+
* OpenAPI 文档结构
|
|
80
102
|
*/
|
|
81
103
|
export interface SwaggerDocument {
|
|
82
|
-
|
|
83
|
-
openapi?: string;
|
|
104
|
+
openapi: string;
|
|
84
105
|
info: SwaggerInfo;
|
|
85
|
-
|
|
86
|
-
basePath?: string;
|
|
87
|
-
schemes?: string[];
|
|
88
|
-
consumes?: string[];
|
|
89
|
-
produces?: string[];
|
|
106
|
+
servers?: OpenAPIServer[];
|
|
90
107
|
paths: SwaggerPaths;
|
|
91
|
-
definitions?: SwaggerDefinitions;
|
|
92
108
|
components?: SwaggerComponents;
|
|
93
109
|
tags?: SwaggerTag[];
|
|
94
110
|
}
|
|
111
|
+
/**
|
|
112
|
+
* OpenAPI Server 对象
|
|
113
|
+
*/
|
|
114
|
+
export interface OpenAPIServer {
|
|
115
|
+
/** Server URL */
|
|
116
|
+
url: string;
|
|
117
|
+
/** Server 描述 */
|
|
118
|
+
description?: string;
|
|
119
|
+
/** Server URL 变量 */
|
|
120
|
+
variables?: {
|
|
121
|
+
[name: string]: {
|
|
122
|
+
default: string;
|
|
123
|
+
enum?: string[];
|
|
124
|
+
description?: string;
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
}
|
|
95
128
|
/**
|
|
96
129
|
* Swagger信息
|
|
97
130
|
*/
|
|
@@ -145,8 +178,6 @@ export interface SwaggerOperation {
|
|
|
145
178
|
summary?: string;
|
|
146
179
|
description?: string;
|
|
147
180
|
operationId?: string;
|
|
148
|
-
consumes?: string[];
|
|
149
|
-
produces?: string[];
|
|
150
181
|
parameters?: SwaggerParameter[];
|
|
151
182
|
requestBody?: SwaggerRequestBody;
|
|
152
183
|
responses: SwaggerResponses;
|
|
@@ -156,6 +187,8 @@ export interface SwaggerOperation {
|
|
|
156
187
|
* Swagger请求体 (OpenAPI 3.0)
|
|
157
188
|
*/
|
|
158
189
|
export interface SwaggerRequestBody {
|
|
190
|
+
/** 本地引用路径 */
|
|
191
|
+
$ref?: string;
|
|
159
192
|
description?: string;
|
|
160
193
|
content: {
|
|
161
194
|
[mediaType: string]: {
|
|
@@ -169,11 +202,13 @@ export interface SwaggerRequestBody {
|
|
|
169
202
|
required?: boolean;
|
|
170
203
|
}
|
|
171
204
|
/**
|
|
172
|
-
*
|
|
205
|
+
* OpenAPI 参数
|
|
173
206
|
*/
|
|
174
207
|
export interface SwaggerParameter {
|
|
208
|
+
/** 本地引用路径 */
|
|
209
|
+
$ref?: string;
|
|
175
210
|
name: string;
|
|
176
|
-
in: 'query' | 'header' | 'path' | '
|
|
211
|
+
in: 'query' | 'header' | 'path' | 'body' | 'cookie';
|
|
177
212
|
description?: string;
|
|
178
213
|
required?: boolean;
|
|
179
214
|
type?: string;
|
|
@@ -184,17 +219,25 @@ export interface SwaggerParameter {
|
|
|
184
219
|
default?: any;
|
|
185
220
|
}
|
|
186
221
|
/**
|
|
187
|
-
*
|
|
222
|
+
* OpenAPI 响应
|
|
188
223
|
*/
|
|
189
224
|
export interface SwaggerResponses {
|
|
190
225
|
[statusCode: string]: SwaggerResponse;
|
|
191
226
|
}
|
|
192
227
|
/**
|
|
193
|
-
*
|
|
228
|
+
* OpenAPI 响应项
|
|
194
229
|
*/
|
|
195
230
|
export interface SwaggerResponse {
|
|
196
231
|
description: string;
|
|
197
|
-
|
|
232
|
+
content?: {
|
|
233
|
+
[mediaType: string]: {
|
|
234
|
+
schema?: SwaggerSchema;
|
|
235
|
+
example?: any;
|
|
236
|
+
examples?: {
|
|
237
|
+
[name: string]: any;
|
|
238
|
+
};
|
|
239
|
+
};
|
|
240
|
+
};
|
|
198
241
|
headers?: {
|
|
199
242
|
[name: string]: SwaggerHeader;
|
|
200
243
|
};
|
|
@@ -214,10 +257,10 @@ export interface SwaggerHeader {
|
|
|
214
257
|
default?: any;
|
|
215
258
|
}
|
|
216
259
|
/**
|
|
217
|
-
*
|
|
260
|
+
* OpenAPI Schema
|
|
218
261
|
*/
|
|
219
262
|
export interface SwaggerSchema {
|
|
220
|
-
type?: string;
|
|
263
|
+
type?: string | string[];
|
|
221
264
|
format?: string;
|
|
222
265
|
title?: string;
|
|
223
266
|
description?: string;
|
|
@@ -255,12 +298,6 @@ export interface SwaggerItems {
|
|
|
255
298
|
default?: any;
|
|
256
299
|
$ref?: string;
|
|
257
300
|
}
|
|
258
|
-
/**
|
|
259
|
-
* Swagger定义
|
|
260
|
-
*/
|
|
261
|
-
export interface SwaggerDefinitions {
|
|
262
|
-
[name: string]: SwaggerSchema;
|
|
263
|
-
}
|
|
264
301
|
/**
|
|
265
302
|
* Swagger组件 (OpenAPI 3.0)
|
|
266
303
|
*/
|
|
@@ -348,7 +385,7 @@ export interface ParameterInfo {
|
|
|
348
385
|
/** 参数类型 */
|
|
349
386
|
type: string;
|
|
350
387
|
/** 参数位置 */
|
|
351
|
-
in: 'query' | 'header' | 'path' | '
|
|
388
|
+
in: 'query' | 'header' | 'path' | 'body' | 'cookie';
|
|
352
389
|
/** 是否必需 */
|
|
353
390
|
required: boolean;
|
|
354
391
|
/** 参数描述 */
|