create-dp-koa 1.1.1 → 1.1.3
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/package.json +1 -1
- package/template/scripts/sync-template.mjs +21 -0
- package/template/src/app.ts +1 -2
- package/template/src/{framework/plugins → plugins}/registry.ts +2 -2
- package/template/src/plugins/weboffice/http/routes.ts +2 -2
- package/template/src/plugins/weboffice/index.ts +3 -3
- package/template/src/plugins/weboffice/services/webofficeCallback.service.ts +3 -4
- package/template/src/utils/testDataInitializer.ts +1 -1
- package/template/tsconfig.json +6 -0
- package/template/src/annotations/decorators/ConfigManagement.ts +0 -9
- package/template/src/annotations/decorators/DistributedTracing.ts +0 -9
- package/template/src/annotations/decorators/EnterprisePerformance.ts +0 -9
- package/template/src/annotations/decorators/PerformanceMonitor.ts +0 -32
- package/template/src/annotations/decorators/SecurityAudit.ts +0 -9
- package/template/src/annotations/index.ts +0 -50
- package/template/src/annotations/processors/ConfigManagementProcessor.ts +0 -369
- package/template/src/annotations/processors/DistributedTracingProcessor.ts +0 -288
- package/template/src/annotations/processors/EnterprisePerformanceProcessor.ts +0 -189
- package/template/src/annotations/processors/PerformanceMonitorProcessor.ts +0 -101
- package/template/src/annotations/processors/SecurityAuditProcessor.ts +0 -345
- package/template/src/annotations/processors/SwaggerProcessor.ts +0 -612
- package/template/src/annotations/processors/index.ts +0 -10
- package/template/src/examples/InterceptorExampleRunner.ts +0 -284
- package/template/src/examples/ServiceInterceptorExample.ts +0 -214
- package/template/src/examples/cacheExamples.ts +0 -155
- package/template/src/framework/decorator/controller.ts +0 -311
- package/template/src/framework/decorator/processor/AnnotationDecorators.ts +0 -100
- package/template/src/framework/decorator/processor/AnnotationProcessor.ts +0 -160
- package/template/src/framework/decorator/processor/AnnotationProcessorConfig.ts +0 -45
- package/template/src/framework/decorator/processor/AnnotationRegistry.ts +0 -117
- package/template/src/framework/decorator/processor/AnnotationSystemInitializer.ts +0 -95
- package/template/src/framework/decorator/processor/ProcessorManager.ts +0 -76
- package/template/src/framework/decorator/processor/processors/CustomProcessors.ts +0 -126
- package/template/src/framework/decorator/processor/processors/DefaultProcessors.ts +0 -207
- package/template/src/framework/decorator/refactored/DecoratorFactory.ts +0 -99
- package/template/src/framework/decorator/refactored/DecoratorMetadataManager.ts +0 -125
- package/template/src/framework/decorator/refactored/DecoratorValidator.ts +0 -128
- package/template/src/framework/decorator/refactored/TypeSafeDecorators.ts +0 -139
- package/template/src/framework/decorator/refactored/index.ts +0 -98
- package/template/src/framework/decorator/swagger.ts +0 -150
- package/template/src/framework/interceptors/AdvancedServiceCallInterceptor.ts +0 -375
- package/template/src/framework/interceptors/ServiceCallInterceptor.ts +0 -348
- package/template/src/framework/interceptors/index.ts +0 -19
- package/template/src/framework/plugins/types.ts +0 -15
- package/template/src/framework/types/ServiceResult.ts +0 -151
- package/template/src/framework/types/index.ts +0 -16
- package/template/src/framework/utils/CacheManager.ts +0 -430
- package/template/src/framework/utils/CacheService.ts +0 -248
- package/template/src/framework/utils/DtoValidator.ts +0 -164
- package/template/src/framework/utils/MigrationHelper.ts +0 -179
- package/template/src/framework/utils/MigrationManager.ts +0 -256
- package/template/src/framework/utils/NewRouter.ts +0 -207
- package/template/src/framework/utils/TransactionManager.ts +0 -172
- package/template/src/framework/utils/bootstrap.ts +0 -445
- package/template/src/framework/utils/cache.ts +0 -269
- package/template/src/framework/utils/databaseConfig.ts +0 -148
- package/template/src/framework/utils/db.ts +0 -39
- package/template/src/framework/utils/dbMonitor.ts +0 -106
- package/template/src/framework/utils/function.ts +0 -61
- package/template/src/framework/utils/gracefulShutdown.ts +0 -131
- package/template/src/framework/utils/logger.ts +0 -388
- package/template/src/framework/utils/metrics.ts +0 -182
- package/template/src/framework/utils/router.ts +0 -417
- package/template/src/framework/utils/swagger.ts +0 -184
- package/template/src/framework/utils/testDb.ts +0 -19
- package/template/src/framework/utils/token.ts +0 -23
- package/template/src/framework/utils/transform.ts +0 -17
- package/template/src/libs/aokEmailSender.ts +0 -42
- package/template/src/libs/captcha.ts +0 -37
- package/template/src/libs/cos.ts +0 -45
- package/template/src/libs/mCache.ts +0 -7
- package/template/src/libs/serviceValidate.ts +0 -3
- package/template/src/libs/tecentSms.ts +0 -51
- package/template/src/middlewares/a.middleware.ts +0 -6
- package/template/src/middlewares/error.middleware.ts +0 -14
- package/template/src/middlewares/logging.middleware.ts +0 -187
- package/template/src/middlewares/static.middleware.ts +0 -79
- package/template/src/middlewares/swagger.middleware.ts +0 -70
- package/template/src/middlewares/token.middleware.ts +0 -32
- package/template/src/migrations/1700000000000-InitialDatabaseStructure.ts +0 -172
- package/template/src/migrations/index.ts +0 -6
- package/template/src/repository/base/BaseRepository.ts +0 -124
- package/template/src/repository/interfaces/IBaseRepository.ts +0 -67
- package/template/src/service/base.service.ts +0 -116
|
@@ -1,612 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swagger注解处理器
|
|
3
|
-
* 负责处理Swagger相关的注解,包括元数据收集、验证和规范生成
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { logger } from '@src/framework/utils/logger';
|
|
7
|
-
import { getSwaggerMetadata } from '@src/framework/decorator/swagger';
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Swagger注解处理器接口
|
|
11
|
-
*/
|
|
12
|
-
export interface SwaggerProcessor {
|
|
13
|
-
/**
|
|
14
|
-
* 处理控制器的Swagger注解
|
|
15
|
-
*/
|
|
16
|
-
processController(target: any): SwaggerControllerMetadata;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* 处理方法级别的Swagger注解
|
|
20
|
-
*/
|
|
21
|
-
processMethod(target: any, methodName: string): SwaggerMethodMetadata;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* 验证Swagger注解的完整性
|
|
25
|
-
*/
|
|
26
|
-
validateSwaggerAnnotations(target: any): ValidationResult;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 生成OpenAPI规范
|
|
30
|
-
*/
|
|
31
|
-
generateOpenAPISpec(controllers: any[]): OpenAPISpec;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Swagger控制器元数据
|
|
36
|
-
*/
|
|
37
|
-
export interface SwaggerControllerMetadata {
|
|
38
|
-
tags: string[];
|
|
39
|
-
description?: string;
|
|
40
|
-
basePath?: string;
|
|
41
|
-
methods: Map<string, SwaggerMethodMetadata>;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Swagger方法元数据
|
|
46
|
-
*/
|
|
47
|
-
export interface SwaggerMethodMetadata {
|
|
48
|
-
operationId: string;
|
|
49
|
-
summary: string;
|
|
50
|
-
description: string;
|
|
51
|
-
tags: string[];
|
|
52
|
-
parameters: SwaggerParameter[];
|
|
53
|
-
requestBody?: SwaggerRequestBody;
|
|
54
|
-
responses: SwaggerResponse[];
|
|
55
|
-
deprecated?: boolean;
|
|
56
|
-
security?: SwaggerSecurity[];
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Swagger参数定义
|
|
61
|
-
*/
|
|
62
|
-
export interface SwaggerParameter {
|
|
63
|
-
name: string;
|
|
64
|
-
in: 'path' | 'query' | 'header' | 'cookie';
|
|
65
|
-
description?: string;
|
|
66
|
-
required: boolean;
|
|
67
|
-
schema: any;
|
|
68
|
-
example?: any;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Swagger请求体定义
|
|
73
|
-
*/
|
|
74
|
-
export interface SwaggerRequestBody {
|
|
75
|
-
description?: string;
|
|
76
|
-
required: boolean;
|
|
77
|
-
content: {
|
|
78
|
-
[mediaType: string]: {
|
|
79
|
-
schema: any;
|
|
80
|
-
examples?: Record<string, any>;
|
|
81
|
-
};
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Swagger响应定义
|
|
87
|
-
*/
|
|
88
|
-
export interface SwaggerResponse {
|
|
89
|
-
status: number;
|
|
90
|
-
description: string;
|
|
91
|
-
content?: {
|
|
92
|
-
[mediaType: string]: {
|
|
93
|
-
schema: any;
|
|
94
|
-
examples?: Record<string, any>;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Swagger安全定义
|
|
101
|
-
*/
|
|
102
|
-
export interface SwaggerSecurity {
|
|
103
|
-
name: string;
|
|
104
|
-
scopes?: string[];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* 验证结果
|
|
109
|
-
*/
|
|
110
|
-
export interface ValidationResult {
|
|
111
|
-
isValid: boolean;
|
|
112
|
-
errors: string[];
|
|
113
|
-
warnings: string[];
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* OpenAPI规范
|
|
118
|
-
*/
|
|
119
|
-
export interface OpenAPISpec {
|
|
120
|
-
openapi: string;
|
|
121
|
-
info: {
|
|
122
|
-
title: string;
|
|
123
|
-
version: string;
|
|
124
|
-
description?: string;
|
|
125
|
-
};
|
|
126
|
-
servers: Array<{
|
|
127
|
-
url: string;
|
|
128
|
-
description?: string;
|
|
129
|
-
}>;
|
|
130
|
-
paths: Record<string, any>;
|
|
131
|
-
components?: {
|
|
132
|
-
schemas?: Record<string, any>;
|
|
133
|
-
securitySchemes?: Record<string, any>;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Swagger注解处理器实现
|
|
139
|
-
*/
|
|
140
|
-
class SwaggerProcessorImpl implements SwaggerProcessor {
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* 处理控制器的Swagger注解
|
|
144
|
-
*/
|
|
145
|
-
processController(target: any): SwaggerControllerMetadata {
|
|
146
|
-
try {
|
|
147
|
-
const swaggerMetadata = getSwaggerMetadata(target);
|
|
148
|
-
|
|
149
|
-
const controllerMetadata: SwaggerControllerMetadata = {
|
|
150
|
-
tags: swaggerMetadata.tags || [],
|
|
151
|
-
methods: new Map()
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// 处理所有方法的Swagger注解
|
|
155
|
-
const httpMethods = this.getHttpMethods(target);
|
|
156
|
-
httpMethods.forEach(methodName => {
|
|
157
|
-
const methodMetadata = this.processMethod(target, methodName);
|
|
158
|
-
controllerMetadata.methods.set(methodName, methodMetadata);
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
logger.debug(`处理控制器 ${target.name} 的Swagger注解完成`);
|
|
162
|
-
return controllerMetadata;
|
|
163
|
-
|
|
164
|
-
} catch (error) {
|
|
165
|
-
logger.error(`处理控制器 ${target.name} 的Swagger注解失败:`, error as Error);
|
|
166
|
-
throw error;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 处理方法级别的Swagger注解
|
|
172
|
-
*/
|
|
173
|
-
processMethod(target: any, methodName: string): SwaggerMethodMetadata {
|
|
174
|
-
try {
|
|
175
|
-
const swaggerMetadata = getSwaggerMetadata(target);
|
|
176
|
-
|
|
177
|
-
// 获取方法的基本信息
|
|
178
|
-
const methodInfo = swaggerMetadata.methods.get(methodName) || {};
|
|
179
|
-
const params = swaggerMetadata.params.get(methodName) || [];
|
|
180
|
-
const body = swaggerMetadata.bodies.get(methodName);
|
|
181
|
-
const responses = swaggerMetadata.responses.get(methodName) || [];
|
|
182
|
-
|
|
183
|
-
// 自动推断路径参数
|
|
184
|
-
const autoInferredParams = this.autoInferParameters(target, methodName);
|
|
185
|
-
const allParams = [...this.processParameters(params), ...autoInferredParams];
|
|
186
|
-
|
|
187
|
-
const methodMetadata: SwaggerMethodMetadata = {
|
|
188
|
-
operationId: methodInfo.operationId || methodName,
|
|
189
|
-
summary: methodInfo.summary || this.generateDefaultSummary(methodName),
|
|
190
|
-
description: methodInfo.description || this.generateDefaultDescription(methodName),
|
|
191
|
-
tags: methodInfo.tags || [],
|
|
192
|
-
parameters: allParams,
|
|
193
|
-
responses: this.processResponses(responses)
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
// 处理请求体
|
|
197
|
-
if (body) {
|
|
198
|
-
methodMetadata.requestBody = this.processRequestBody(body);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
logger.debug(`处理方法 ${methodName} 的Swagger注解完成`);
|
|
202
|
-
return methodMetadata;
|
|
203
|
-
|
|
204
|
-
} catch (error) {
|
|
205
|
-
logger.error(`处理方法 ${methodName} 的Swagger注解失败:`, error as Error);
|
|
206
|
-
throw error;
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/**
|
|
211
|
-
* 验证Swagger注解的完整性
|
|
212
|
-
*/
|
|
213
|
-
validateSwaggerAnnotations(target: any): ValidationResult {
|
|
214
|
-
const errors: string[] = [];
|
|
215
|
-
const warnings: string[] = [];
|
|
216
|
-
|
|
217
|
-
try {
|
|
218
|
-
const swaggerMetadata = getSwaggerMetadata(target);
|
|
219
|
-
const httpMethods = this.getHttpMethods(target);
|
|
220
|
-
|
|
221
|
-
// 验证每个方法的注解
|
|
222
|
-
httpMethods.forEach(methodName => {
|
|
223
|
-
const methodInfo = swaggerMetadata.methods.get(methodName);
|
|
224
|
-
const responses = swaggerMetadata.responses.get(methodName) || [];
|
|
225
|
-
|
|
226
|
-
// 检查是否有基本的方法信息
|
|
227
|
-
if (!methodInfo) {
|
|
228
|
-
warnings.push(`方法 ${methodName} 缺少 @Api 注解`);
|
|
229
|
-
} else {
|
|
230
|
-
// 检查summary
|
|
231
|
-
if (!methodInfo.summary) {
|
|
232
|
-
warnings.push(`方法 ${methodName} 缺少 summary 描述`);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// 检查description
|
|
236
|
-
if (!methodInfo.description) {
|
|
237
|
-
warnings.push(`方法 ${methodName} 缺少 description 描述`);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// 检查响应定义
|
|
242
|
-
if (responses.length === 0) {
|
|
243
|
-
warnings.push(`方法 ${methodName} 缺少 @ApiResponse 注解`);
|
|
244
|
-
} else {
|
|
245
|
-
// 检查是否有200响应
|
|
246
|
-
const has200Response = responses.some((r: any) => r.status === 200);
|
|
247
|
-
if (!has200Response) {
|
|
248
|
-
warnings.push(`方法 ${methodName} 缺少200状态码的响应定义`);
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
// 检查控制器标签
|
|
254
|
-
if (!swaggerMetadata.tags || swaggerMetadata.tags.length === 0) {
|
|
255
|
-
warnings.push(`控制器 ${target.name} 缺少 @ApiTags 注解`);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
logger.debug(`验证控制器 ${target.name} 的Swagger注解完成`);
|
|
259
|
-
|
|
260
|
-
return {
|
|
261
|
-
isValid: errors.length === 0,
|
|
262
|
-
errors,
|
|
263
|
-
warnings
|
|
264
|
-
};
|
|
265
|
-
|
|
266
|
-
} catch (error) {
|
|
267
|
-
logger.error(`验证控制器 ${target.name} 的Swagger注解失败:`, error as Error);
|
|
268
|
-
return {
|
|
269
|
-
isValid: false,
|
|
270
|
-
errors: [`验证失败: ${(error as Error).message}`],
|
|
271
|
-
warnings: []
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* 生成OpenAPI规范
|
|
278
|
-
*/
|
|
279
|
-
generateOpenAPISpec(controllers: any[]): OpenAPISpec {
|
|
280
|
-
try {
|
|
281
|
-
const spec: OpenAPISpec = {
|
|
282
|
-
openapi: '3.0.0',
|
|
283
|
-
info: {
|
|
284
|
-
title: 'DP Koa Framework API',
|
|
285
|
-
version: '1.0.0',
|
|
286
|
-
description: '基于Koa的企业级框架API文档'
|
|
287
|
-
},
|
|
288
|
-
servers: [
|
|
289
|
-
{
|
|
290
|
-
url: 'http://localhost:3000',
|
|
291
|
-
description: '开发环境'
|
|
292
|
-
}
|
|
293
|
-
],
|
|
294
|
-
paths: {},
|
|
295
|
-
components: {
|
|
296
|
-
schemas: {},
|
|
297
|
-
securitySchemes: {}
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
|
|
301
|
-
// 处理每个控制器
|
|
302
|
-
controllers.forEach(controller => {
|
|
303
|
-
const controllerMetadata = this.processController(controller);
|
|
304
|
-
|
|
305
|
-
// 获取控制器的路由信息
|
|
306
|
-
const httpMethods = this.getHttpMethods(controller);
|
|
307
|
-
|
|
308
|
-
httpMethods.forEach(methodName => {
|
|
309
|
-
const methodMetadata = controllerMetadata.methods.get(methodName);
|
|
310
|
-
if (methodMetadata) {
|
|
311
|
-
// 获取路由路径
|
|
312
|
-
const routePath = this.getRoutePath(controller, methodName);
|
|
313
|
-
if (routePath) {
|
|
314
|
-
const swaggerPath = routePath.replace(/:(\w+)/g, '{$1}');
|
|
315
|
-
const httpMethod = this.getHttpMethod(controller, methodName);
|
|
316
|
-
|
|
317
|
-
if (!spec.paths[swaggerPath]) {
|
|
318
|
-
spec.paths[swaggerPath] = {};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
spec.paths[swaggerPath][httpMethod] = {
|
|
322
|
-
operationId: methodMetadata.operationId,
|
|
323
|
-
summary: methodMetadata.summary,
|
|
324
|
-
description: methodMetadata.description,
|
|
325
|
-
tags: methodMetadata.tags,
|
|
326
|
-
parameters: methodMetadata.parameters,
|
|
327
|
-
responses: this.convertResponsesToOpenAPI(methodMetadata.responses)
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
if (methodMetadata.requestBody) {
|
|
331
|
-
spec.paths[swaggerPath][httpMethod].requestBody = methodMetadata.requestBody;
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
});
|
|
336
|
-
});
|
|
337
|
-
|
|
338
|
-
logger.info(`生成OpenAPI规范完成,包含 ${Object.keys(spec.paths).length} 个路径`);
|
|
339
|
-
return spec;
|
|
340
|
-
|
|
341
|
-
} catch (error) {
|
|
342
|
-
logger.error('生成OpenAPI规范失败:', error as Error);
|
|
343
|
-
throw error;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* 处理参数
|
|
349
|
-
*/
|
|
350
|
-
private processParameters(params: any[]): SwaggerParameter[] {
|
|
351
|
-
return params.map(param => ({
|
|
352
|
-
name: param.name,
|
|
353
|
-
in: param.in,
|
|
354
|
-
description: param.description,
|
|
355
|
-
required: param.required || false,
|
|
356
|
-
schema: param.schema || { type: 'string' },
|
|
357
|
-
example: param.example
|
|
358
|
-
}));
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
/**
|
|
362
|
-
* 自动推断路径参数
|
|
363
|
-
*/
|
|
364
|
-
private autoInferParameters(controller: any, methodName: string): SwaggerParameter[] {
|
|
365
|
-
const parameters: SwaggerParameter[] = [];
|
|
366
|
-
|
|
367
|
-
try {
|
|
368
|
-
// 获取方法的URL路径
|
|
369
|
-
const urlPath = this.getMethodUrlPath(controller, methodName);
|
|
370
|
-
if (urlPath) {
|
|
371
|
-
// 提取路径参数 (:paramName)
|
|
372
|
-
const pathParamMatches = urlPath.match(/:(\w+)/g);
|
|
373
|
-
if (pathParamMatches) {
|
|
374
|
-
pathParamMatches.forEach(paramMatch => {
|
|
375
|
-
const paramName = paramMatch.substring(1); // 移除冒号
|
|
376
|
-
|
|
377
|
-
// 检查是否已经通过@ApiParam定义了
|
|
378
|
-
const swaggerMetadata = getSwaggerMetadata(controller);
|
|
379
|
-
const existingParams = swaggerMetadata.params.get(methodName) || [];
|
|
380
|
-
const alreadyDefined = existingParams.some((p: any) => p.name === paramName && p.in === 'path');
|
|
381
|
-
|
|
382
|
-
if (!alreadyDefined) {
|
|
383
|
-
parameters.push({
|
|
384
|
-
name: paramName,
|
|
385
|
-
in: 'path',
|
|
386
|
-
description: this.generateParameterDescription(paramName),
|
|
387
|
-
required: true,
|
|
388
|
-
schema: { type: 'string' }
|
|
389
|
-
});
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
logger.debug(`为方法 ${methodName} 自动推断出 ${parameters.length} 个路径参数`);
|
|
396
|
-
return parameters;
|
|
397
|
-
|
|
398
|
-
} catch (error) {
|
|
399
|
-
logger.warn(`自动推断方法 ${methodName} 的参数失败:`, error as Error);
|
|
400
|
-
return [];
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* 获取方法的URL路径
|
|
406
|
-
*/
|
|
407
|
-
private getMethodUrlPath(controller: any, methodName: string): string | null {
|
|
408
|
-
// 检查GET方法
|
|
409
|
-
if (controller.$_GetMethods) {
|
|
410
|
-
const getMethods = Array.from(controller.$_GetMethods) as Array<{methodName: string, url: string}>;
|
|
411
|
-
const method = getMethods.find(m => m.methodName === methodName);
|
|
412
|
-
if (method) return method.url;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
// 检查POST方法
|
|
416
|
-
if (controller.$_PostMethods) {
|
|
417
|
-
const postMethods = Array.from(controller.$_PostMethods) as Array<{methodName: string, url: string}>;
|
|
418
|
-
const method = postMethods.find(m => m.methodName === methodName);
|
|
419
|
-
if (method) return method.url;
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
// 检查PUT方法
|
|
423
|
-
if (controller.$_PutMethods) {
|
|
424
|
-
const putMethods = Array.from(controller.$_PutMethods) as Array<{methodName: string, url: string}>;
|
|
425
|
-
const method = putMethods.find(m => m.methodName === methodName);
|
|
426
|
-
if (method) return method.url;
|
|
427
|
-
}
|
|
428
|
-
|
|
429
|
-
// 检查DELETE方法
|
|
430
|
-
if (controller.$_DelMethods) {
|
|
431
|
-
const delMethods = Array.from(controller.$_DelMethods) as Array<{methodName: string, url: string}>;
|
|
432
|
-
const method = delMethods.find(m => m.methodName === methodName);
|
|
433
|
-
if (method) return method.url;
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
return null;
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
/**
|
|
440
|
-
* 生成参数描述
|
|
441
|
-
*/
|
|
442
|
-
private generateParameterDescription(paramName: string): string {
|
|
443
|
-
const descriptions: Record<string, string> = {
|
|
444
|
-
'id': 'ID',
|
|
445
|
-
'userId': '用户ID',
|
|
446
|
-
'productId': '产品ID',
|
|
447
|
-
'orderId': '订单ID',
|
|
448
|
-
'categoryId': '分类ID',
|
|
449
|
-
'page': '页码',
|
|
450
|
-
'size': '每页数量',
|
|
451
|
-
'limit': '限制数量',
|
|
452
|
-
'offset': '偏移量'
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
return descriptions[paramName] || `${paramName}参数`;
|
|
456
|
-
}
|
|
457
|
-
|
|
458
|
-
/**
|
|
459
|
-
* 处理请求体
|
|
460
|
-
*/
|
|
461
|
-
private processRequestBody(body: any): SwaggerRequestBody {
|
|
462
|
-
return {
|
|
463
|
-
description: body.description,
|
|
464
|
-
required: body.required || false,
|
|
465
|
-
content: {
|
|
466
|
-
'application/json': {
|
|
467
|
-
schema: body.schema,
|
|
468
|
-
examples: body.examples
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
|
|
474
|
-
/**
|
|
475
|
-
* 处理响应
|
|
476
|
-
*/
|
|
477
|
-
private processResponses(responses: any[]): SwaggerResponse[] {
|
|
478
|
-
return responses.map(response => ({
|
|
479
|
-
status: response.status,
|
|
480
|
-
description: response.description,
|
|
481
|
-
content: response.schema ? {
|
|
482
|
-
'application/json': {
|
|
483
|
-
schema: response.schema,
|
|
484
|
-
examples: response.examples
|
|
485
|
-
}
|
|
486
|
-
} : undefined
|
|
487
|
-
}));
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
/**
|
|
491
|
-
* 转换响应为OpenAPI格式
|
|
492
|
-
*/
|
|
493
|
-
private convertResponsesToOpenAPI(responses: SwaggerResponse[]): Record<string, any> {
|
|
494
|
-
const openAPIResponses: Record<string, any> = {};
|
|
495
|
-
|
|
496
|
-
responses.forEach(response => {
|
|
497
|
-
openAPIResponses[response.status.toString()] = {
|
|
498
|
-
description: response.description,
|
|
499
|
-
content: response.content
|
|
500
|
-
};
|
|
501
|
-
});
|
|
502
|
-
|
|
503
|
-
return openAPIResponses;
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
/**
|
|
507
|
-
* 获取HTTP方法
|
|
508
|
-
*/
|
|
509
|
-
private getHttpMethods(target: any): string[] {
|
|
510
|
-
const methods: string[] = [];
|
|
511
|
-
|
|
512
|
-
if (target.$_GetMethods) {
|
|
513
|
-
const getMethods = Array.from(target.$_GetMethods) as Array<{methodName: string}>;
|
|
514
|
-
methods.push(...getMethods.map(m => m.methodName));
|
|
515
|
-
}
|
|
516
|
-
|
|
517
|
-
if (target.$_PostMethods) {
|
|
518
|
-
const postMethods = Array.from(target.$_PostMethods) as Array<{methodName: string}>;
|
|
519
|
-
methods.push(...postMethods.map(m => m.methodName));
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
if (target.$_PutMethods) {
|
|
523
|
-
const putMethods = Array.from(target.$_PutMethods) as Array<{methodName: string}>;
|
|
524
|
-
methods.push(...putMethods.map(m => m.methodName));
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
if (target.$_DelMethods) {
|
|
528
|
-
const delMethods = Array.from(target.$_DelMethods) as Array<{methodName: string}>;
|
|
529
|
-
methods.push(...delMethods.map(m => m.methodName));
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
return methods;
|
|
533
|
-
}
|
|
534
|
-
|
|
535
|
-
/**
|
|
536
|
-
* 获取路由路径
|
|
537
|
-
*/
|
|
538
|
-
private getRoutePath(target: any, methodName: string): string | null {
|
|
539
|
-
// 这里需要根据实际的路由注册逻辑来获取路径
|
|
540
|
-
// 暂时返回null,需要与路由系统集成
|
|
541
|
-
return null;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
/**
|
|
545
|
-
* 获取HTTP方法
|
|
546
|
-
*/
|
|
547
|
-
private getHttpMethod(target: any, methodName: string): string {
|
|
548
|
-
if (target.$_GetMethods) {
|
|
549
|
-
const getMethods = Array.from(target.$_GetMethods) as Array<{methodName: string}>;
|
|
550
|
-
if (getMethods.some(m => m.methodName === methodName)) return 'get';
|
|
551
|
-
}
|
|
552
|
-
|
|
553
|
-
if (target.$_PostMethods) {
|
|
554
|
-
const postMethods = Array.from(target.$_PostMethods) as Array<{methodName: string}>;
|
|
555
|
-
if (postMethods.some(m => m.methodName === methodName)) return 'post';
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
if (target.$_PutMethods) {
|
|
559
|
-
const putMethods = Array.from(target.$_PutMethods) as Array<{methodName: string}>;
|
|
560
|
-
if (putMethods.some(m => m.methodName === methodName)) return 'put';
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (target.$_DelMethods) {
|
|
564
|
-
const delMethods = Array.from(target.$_DelMethods) as Array<{methodName: string}>;
|
|
565
|
-
if (delMethods.some(m => m.methodName === methodName)) return 'delete';
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
return 'get'; // 默认
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
/**
|
|
572
|
-
* 生成默认摘要
|
|
573
|
-
*/
|
|
574
|
-
private generateDefaultSummary(methodName: string): string {
|
|
575
|
-
const methodMap: Record<string, string> = {
|
|
576
|
-
'get': '获取',
|
|
577
|
-
'post': '创建',
|
|
578
|
-
'put': '更新',
|
|
579
|
-
'delete': '删除'
|
|
580
|
-
};
|
|
581
|
-
|
|
582
|
-
const httpMethod = this.getHttpMethod({}, methodName);
|
|
583
|
-
const action = methodMap[httpMethod] || '操作';
|
|
584
|
-
|
|
585
|
-
return `${action}${methodName}`;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* 生成默认描述
|
|
590
|
-
*/
|
|
591
|
-
private generateDefaultDescription(methodName: string): string {
|
|
592
|
-
const httpMethod = this.getHttpMethod({}, methodName);
|
|
593
|
-
const descriptions: Record<string, string> = {
|
|
594
|
-
'get': '获取数据',
|
|
595
|
-
'post': '创建数据',
|
|
596
|
-
'put': '更新数据',
|
|
597
|
-
'delete': '删除数据'
|
|
598
|
-
};
|
|
599
|
-
|
|
600
|
-
return descriptions[httpMethod] || 'API操作';
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
/**
|
|
605
|
-
* 创建Swagger处理器实例
|
|
606
|
-
*/
|
|
607
|
-
export const swaggerProcessor = new SwaggerProcessorImpl();
|
|
608
|
-
|
|
609
|
-
/**
|
|
610
|
-
* 导出Swagger处理器
|
|
611
|
-
*/
|
|
612
|
-
export { SwaggerProcessorImpl };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 注解处理器导出文件
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { PerformanceMonitorProcessor } from './PerformanceMonitorProcessor';
|
|
6
|
-
export { EnterprisePerformanceProcessor } from './EnterprisePerformanceProcessor';
|
|
7
|
-
export { SecurityAuditProcessor } from './SecurityAuditProcessor';
|
|
8
|
-
export { DistributedTracingProcessor } from './DistributedTracingProcessor';
|
|
9
|
-
export { ConfigManagementProcessor } from './ConfigManagementProcessor';
|
|
10
|
-
export { SwaggerProcessor, swaggerProcessor } from './SwaggerProcessor';
|