create-dp-koa 1.0.0 → 1.0.2
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 +2 -2
- package/template/.cursor/commands/cheatsheet-backend-controller.md +45 -0
- package/template/.cursor/commands/implement-backend-api-controller.md +60 -0
- package/template/.cursor/commands/plan-backend.md +97 -0
- package/template/.cursor/rules/00-backend-core.skill.md +61 -0
- package/template/.cursor/rules/01-backend-skill-router.skill.md +57 -0
- package/template/.cursor/rules/10-backend-api.skill.md +55 -0
- package/template/.cursor/rules/11-backend-controller-recipes.skill.md +188 -0
- package/template/.cursor/rules/20-backend-repository.skill.md +25 -0
- package/template/.cursor/rules/21-backend-service.skill.md +137 -0
- package/template/.cursor/rules/25-backend-comments-and-doc.skill.md +98 -0
- package/template/.cursor/rules/30-backend-validation.skill.md +342 -0
- package/template/.cursor/rules/40-backend-error-logging.skill.md +21 -0
- package/template/.cursor/rules/50-backend-bootstrap-lifecycle.skill.md +105 -0
- package/template/.cursor/rules/60-backend-router-registration.skill.md +73 -0
- package/template/.cursor/rules/70-backend-middleware.skill.md +100 -0
- package/template/.cursor/rules/80-backend-utils-and-libs.skill.md +108 -0
- package/template/.cursor/rules/85-backend-plugins.rule.md +65 -0
- package/template/.cursor/rules/90-backend-testing.skill.md +29 -0
- package/template/.cursor/rules/README.md +49 -0
- package/template/.trae/skills/11-backend-controller-recipes.skill.md +91 -10
- package/template/scripts/sync-template.mjs +0 -1
- package/template/src/controllers/example/ExampleController.ts +14 -0
- package/template/src/entity/index.ts +1 -15
- package/template/src/framework/decorator/processor/AnnotationProcessor.ts +5 -1
- package/template/src/routers/index.ts +0 -35
- package/template/src/utils/testDataInitializer.ts +2 -269
- package/template/test/controllers/example/ExampleController.test.ts +29 -31
- package/template/test/framework/annotation/AnnotationDecorators.test.ts +15 -15
- package/template/test/framework/annotation/AnnotationExecutor.test.ts +27 -32
- package/template/test/framework/annotation/AnnotationProcessor.test.ts +25 -24
- package/template/test/framework/annotation/CustomProcessors.test.ts +15 -25
- package/template/test/framework/annotation/NewRouter.test.ts +9 -7
- package/template/test/framework/annotation/ProcessorManager.test.ts +14 -27
- package/template/test/framework/databaseConfig.test.ts +2 -2
- package/template/test/integration/integration.test.ts +15 -72
- package/template/src/controllers/cacheManagement.controller.ts +0 -131
- package/template/src/controllers/captcha.controller.ts +0 -57
- package/template/src/controllers/example/NewAnnotationExampleController.ts +0 -159
- package/template/src/controllers/example/SwaggerExampleController.ts +0 -205
- package/template/src/controllers/example/TransactionExample.controller.ts +0 -336
- package/template/src/controllers/health.controller.ts +0 -235
- package/template/src/controllers/home/register.controller.ts +0 -58
- package/template/src/controllers/home/ytGoods.controller.ts +0 -92
- package/template/src/controllers/home/ytShop.controller.ts +0 -135
- package/template/src/controllers/home/ytUser.controller.ts +0 -89
- package/template/src/controllers/logManagement.controller.ts +0 -396
- package/template/src/controllers/public/emailSend.controller.ts +0 -65
- package/template/src/controllers/public/ytUserAuth.controller.ts +0 -174
- package/template/src/controllers/testData.controller.ts +0 -253
- package/template/src/dto/controller/example/NewAnnotationExampleController.dto.ts +0 -73
- package/template/src/dto/controller/home/emailSend.controller.dto.ts +0 -40
- package/template/src/dto/controller/home/register.controller.dto.ts +0 -45
- package/template/src/dto/controller/home/ytGoods.controller.dto.ts +0 -55
- package/template/src/dto/controller/home/ytShop.controller.dto.ts +0 -69
- package/template/src/dto/controller/home/ytUser.controller.dto.ts +0 -44
- package/template/src/dto/controller/public/ytUserAuth.controller.dto.ts +0 -63
- package/template/src/dto/goods.dto.ts +0 -212
- package/template/src/dto/service/ytService.dto.ts +0 -13
- package/template/src/dto/user.dto.ts +0 -177
- package/template/src/entity/columnTypes.ts +0 -13
- package/template/src/entity/goodsImagesUnlockKey.entity.ts +0 -33
- package/template/src/entity/goodsUnlocker.entity.ts +0 -34
- package/template/src/entity/shop.entity.ts +0 -52
- package/template/src/entity/shopUser.entity.ts +0 -41
- package/template/src/entity/ytGoods.entity.ts +0 -94
- package/template/src/entity/ytUser.entity.ts +0 -96
- package/template/src/examples/SwaggerProcessorExample.ts +0 -169
- package/template/src/examples/TransactionManagerDemo.ts +0 -377
- package/template/src/framework/utils/dynamicSwagger.ts +0 -410
- package/template/src/repository/UserRepository.ts +0 -122
- package/template/src/service/paramValidateTest.service.ts +0 -139
- package/template/src/service/ytGoods.service.ts +0 -42
- package/template/src/service/ytShop.service.ts +0 -90
- package/template/src/service/ytUser.service.ts +0 -451
- package/template/src/test/swaggerParameterTest.ts +0 -90
- package/template/test/controllers/controllers.test.ts +0 -173
- package/template/test/controllers/example/NewAnnotationExampleController.test.ts +0 -200
- package/template/test/framework/TransactionManagerDemo.test.ts +0 -363
- package/template/test/service/business.test.ts +0 -87
- package/template/test/service/paramValidateTest.service.test.ts +0 -184
- package/template/test/service/ytUser.service.test.ts +0 -566
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { Column, Entity, OneToMany, OneToOne } from "typeorm";
|
|
2
|
-
import { BaseEntity } from "@src/entity/base.entity";
|
|
3
|
-
import { YtGoodsEntity } from "@src/entity/ytGoods.entity";
|
|
4
|
-
import { ShopAndUserEntity } from "@src/entity/shopUser.entity";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export enum ShopStatusEnum {
|
|
8
|
-
CHECKING = "CHECKING", // 审核中
|
|
9
|
-
NORMAL = "NORMAL",
|
|
10
|
-
FORBIDDEN = "FORBIDDEN",
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
@Entity({
|
|
15
|
-
name: "shop"
|
|
16
|
-
})
|
|
17
|
-
export class ShopEntity extends BaseEntity {
|
|
18
|
-
|
|
19
|
-
@Column({
|
|
20
|
-
default: "",
|
|
21
|
-
})
|
|
22
|
-
name: string;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@Column({
|
|
26
|
-
default:""
|
|
27
|
-
})
|
|
28
|
-
description:string;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
@Column({
|
|
32
|
-
type: "varchar",
|
|
33
|
-
length: 50,
|
|
34
|
-
default: ShopStatusEnum.NORMAL
|
|
35
|
-
})
|
|
36
|
-
status: ShopStatusEnum;
|
|
37
|
-
|
|
38
|
-
// 关系定义
|
|
39
|
-
/**
|
|
40
|
-
* 店铺的商品列表
|
|
41
|
-
*/
|
|
42
|
-
@OneToMany(() => YtGoodsEntity, goods => goods.shop)
|
|
43
|
-
goods: YtGoodsEntity[];
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* 店铺与用户的关系
|
|
47
|
-
*/
|
|
48
|
-
@OneToOne(() => ShopAndUserEntity, shopUser => shopUser.shop)
|
|
49
|
-
userRelation: ShopAndUserEntity;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { Column, Entity, Index, ManyToOne, JoinColumn } from "typeorm";
|
|
2
|
-
import { BaseEntity } from "@src/entity/base.entity";
|
|
3
|
-
import { ShopEntity } from "@src/entity/shop.entity";
|
|
4
|
-
import { YtUserEntity } from "@src/entity/ytUser.entity";
|
|
5
|
-
|
|
6
|
-
@Entity({
|
|
7
|
-
name: "shop_and_user"
|
|
8
|
-
})
|
|
9
|
-
export class ShopAndUserEntity extends BaseEntity {
|
|
10
|
-
|
|
11
|
-
@Index()
|
|
12
|
-
@Column({
|
|
13
|
-
default: 0,
|
|
14
|
-
type: "integer"
|
|
15
|
-
})
|
|
16
|
-
shopId: number;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
@Index()
|
|
20
|
-
@Column({
|
|
21
|
-
default: 0,
|
|
22
|
-
type: "integer"
|
|
23
|
-
})
|
|
24
|
-
userId: number
|
|
25
|
-
|
|
26
|
-
// 关系定义
|
|
27
|
-
/**
|
|
28
|
-
* 关联的店铺
|
|
29
|
-
*/
|
|
30
|
-
@ManyToOne(() => ShopEntity, shop => shop.userRelation)
|
|
31
|
-
@JoinColumn({ name: 'shopId' })
|
|
32
|
-
shop: ShopEntity;
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 关联的用户
|
|
36
|
-
*/
|
|
37
|
-
@ManyToOne(() => YtUserEntity, user => user.shopRelation)
|
|
38
|
-
@JoinColumn({ name: 'userId' })
|
|
39
|
-
user: YtUserEntity;
|
|
40
|
-
|
|
41
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import { Column, Entity, Index, ManyToOne, OneToMany, JoinColumn } from "typeorm";
|
|
2
|
-
import { BaseEntity } from "@src/entity/base.entity";
|
|
3
|
-
import { ShopEntity } from "@src/entity/shop.entity";
|
|
4
|
-
import { YtGoodsUnlockerEntity } from "@src/entity/goodsUnlocker.entity";
|
|
5
|
-
import { GoodsImagesUnlockKeyEntity } from "@src/entity/goodsImagesUnlockKey.entity";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export enum YtGoodsStatusEnum {
|
|
9
|
-
NORMAL = "NORMAL",
|
|
10
|
-
FORBIDDEN = "FORBIDDEN",
|
|
11
|
-
CHECKING = "CHECKING",
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
@Entity({
|
|
16
|
-
name: "yt_goods"
|
|
17
|
-
})
|
|
18
|
-
export class YtGoodsEntity extends BaseEntity {
|
|
19
|
-
|
|
20
|
-
@Index()
|
|
21
|
-
@Column({ default: "" })
|
|
22
|
-
name: string;
|
|
23
|
-
|
|
24
|
-
@Index()
|
|
25
|
-
@Column({
|
|
26
|
-
default: 0,
|
|
27
|
-
type: "integer"
|
|
28
|
-
})
|
|
29
|
-
shopId: number
|
|
30
|
-
|
|
31
|
-
@Column({
|
|
32
|
-
type: "simple-array",
|
|
33
|
-
default: ""
|
|
34
|
-
})
|
|
35
|
-
albums: string[]
|
|
36
|
-
|
|
37
|
-
@Column({ default: 0 })
|
|
38
|
-
price: number;
|
|
39
|
-
|
|
40
|
-
@Column({
|
|
41
|
-
type: "simple-array",
|
|
42
|
-
default: ""
|
|
43
|
-
})
|
|
44
|
-
tags: string[];
|
|
45
|
-
|
|
46
|
-
@Column({
|
|
47
|
-
default: ""
|
|
48
|
-
})
|
|
49
|
-
description: string;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
@Column({
|
|
53
|
-
type: "text",
|
|
54
|
-
default: ""
|
|
55
|
-
})
|
|
56
|
-
content: string
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 商品内容中的图片,产品的照片相册
|
|
60
|
-
*/
|
|
61
|
-
@Column({
|
|
62
|
-
type: "simple-array",
|
|
63
|
-
default: ""
|
|
64
|
-
})
|
|
65
|
-
imagesContent: string[]
|
|
66
|
-
|
|
67
|
-
@Column({
|
|
68
|
-
type: "varchar",
|
|
69
|
-
length: 50,
|
|
70
|
-
default: YtGoodsStatusEnum.NORMAL
|
|
71
|
-
})
|
|
72
|
-
status: YtGoodsStatusEnum;
|
|
73
|
-
|
|
74
|
-
// 关系定义
|
|
75
|
-
/**
|
|
76
|
-
* 商品所属的店铺
|
|
77
|
-
*/
|
|
78
|
-
@ManyToOne(() => ShopEntity, shop => shop.goods)
|
|
79
|
-
@JoinColumn({ name: 'shopId' })
|
|
80
|
-
shop: ShopEntity;
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 商品解锁记录
|
|
84
|
-
*/
|
|
85
|
-
@OneToMany(() => YtGoodsUnlockerEntity, unlocker => unlocker.goods)
|
|
86
|
-
unlockRecords: YtGoodsUnlockerEntity[];
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 商品图片解锁密钥
|
|
90
|
-
*/
|
|
91
|
-
@OneToMany(() => GoodsImagesUnlockKeyEntity, key => key.goods)
|
|
92
|
-
unlockKeys: GoodsImagesUnlockKeyEntity[];
|
|
93
|
-
|
|
94
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { Column, Entity, OneToMany, OneToOne } from "typeorm";
|
|
2
|
-
import { BaseEntity } from "@src/entity/base.entity";
|
|
3
|
-
import { ShopAndUserEntity } from "@src/entity/shopUser.entity";
|
|
4
|
-
import { YtGoodsUnlockerEntity } from "@src/entity/goodsUnlocker.entity";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export enum YtUserStatusEnum {
|
|
8
|
-
NORMAL = "normal",
|
|
9
|
-
FORBIDDEN = "forbidden"
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export enum YtUserTypeEnum {
|
|
13
|
-
CUSTOMER = "CUSTOMER", // 消费者
|
|
14
|
-
SHOP = "SHOP" // 商家
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
@Entity({
|
|
19
|
-
name: "yt_user"
|
|
20
|
-
})
|
|
21
|
-
export class YtUserEntity extends BaseEntity {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
@Column({
|
|
26
|
-
default: ""
|
|
27
|
-
})
|
|
28
|
-
nickName: string
|
|
29
|
-
|
|
30
|
-
@Column({
|
|
31
|
-
default: ""
|
|
32
|
-
})
|
|
33
|
-
telnumber: string
|
|
34
|
-
|
|
35
|
-
@Column({
|
|
36
|
-
default: ""
|
|
37
|
-
})
|
|
38
|
-
email: string
|
|
39
|
-
|
|
40
|
-
@Column({
|
|
41
|
-
default: ""
|
|
42
|
-
})
|
|
43
|
-
password: string
|
|
44
|
-
|
|
45
|
-
@Column({
|
|
46
|
-
type: "varchar",
|
|
47
|
-
length: 50,
|
|
48
|
-
default: YtUserTypeEnum.CUSTOMER
|
|
49
|
-
})
|
|
50
|
-
userType: YtUserTypeEnum
|
|
51
|
-
|
|
52
|
-
@Column({
|
|
53
|
-
default: 0,
|
|
54
|
-
})
|
|
55
|
-
gender: number
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
@Column({
|
|
59
|
-
default: 0,
|
|
60
|
-
})
|
|
61
|
-
age: number
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// 星座
|
|
65
|
-
@Column({
|
|
66
|
-
default: ""
|
|
67
|
-
})
|
|
68
|
-
constellation: string
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
@Column({
|
|
72
|
-
default: ""
|
|
73
|
-
})
|
|
74
|
-
avatar: string;
|
|
75
|
-
|
|
76
|
-
@Column({
|
|
77
|
-
default: YtUserStatusEnum.NORMAL,
|
|
78
|
-
type: "varchar",
|
|
79
|
-
length: 50
|
|
80
|
-
})
|
|
81
|
-
status: YtUserStatusEnum;
|
|
82
|
-
|
|
83
|
-
// 关系定义
|
|
84
|
-
/**
|
|
85
|
-
* 用户与店铺的关系(一个用户只能拥有一个店铺)
|
|
86
|
-
*/
|
|
87
|
-
@OneToOne(() => ShopAndUserEntity, shopUser => shopUser.user)
|
|
88
|
-
shopRelation: ShopAndUserEntity;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* 用户解锁的商品记录
|
|
92
|
-
*/
|
|
93
|
-
@OneToMany(() => YtGoodsUnlockerEntity, unlocker => unlocker.user)
|
|
94
|
-
unlockedGoods: YtGoodsUnlockerEntity[];
|
|
95
|
-
|
|
96
|
-
}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Swagger处理器使用示例
|
|
3
|
-
* 展示如何使用SwaggerProcessor来处理Swagger注解
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { swaggerProcessor } from '@src/annotations/processors/SwaggerProcessor';
|
|
7
|
-
import { SwaggerExampleController } from '@src/controllers/example/SwaggerExampleController';
|
|
8
|
-
import { logger } from '@src/framework/utils/logger';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Swagger处理器使用示例
|
|
12
|
-
*/
|
|
13
|
-
export class SwaggerProcessorExample {
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* 示例1:处理单个控制器的Swagger注解
|
|
17
|
-
*/
|
|
18
|
-
static async processSingleController() {
|
|
19
|
-
try {
|
|
20
|
-
logger.info('=== Swagger处理器示例:处理单个控制器 ===');
|
|
21
|
-
|
|
22
|
-
// 处理SwaggerExampleController
|
|
23
|
-
const controllerMetadata = swaggerProcessor.processController(SwaggerExampleController);
|
|
24
|
-
|
|
25
|
-
logger.info('控制器标签:', controllerMetadata.tags);
|
|
26
|
-
logger.info('方法数量:', controllerMetadata.methods.size);
|
|
27
|
-
|
|
28
|
-
// 遍历所有方法
|
|
29
|
-
controllerMetadata.methods.forEach((methodMetadata, methodName) => {
|
|
30
|
-
logger.info(`方法 ${methodName}:`);
|
|
31
|
-
logger.info(` - 操作ID: ${methodMetadata.operationId}`);
|
|
32
|
-
logger.info(` - 摘要: ${methodMetadata.summary}`);
|
|
33
|
-
logger.info(` - 描述: ${methodMetadata.description}`);
|
|
34
|
-
logger.info(` - 标签: ${methodMetadata.tags.join(', ')}`);
|
|
35
|
-
logger.info(` - 参数数量: ${methodMetadata.parameters.length}`);
|
|
36
|
-
logger.info(` - 响应数量: ${methodMetadata.responses.length}`);
|
|
37
|
-
|
|
38
|
-
if (methodMetadata.requestBody) {
|
|
39
|
-
logger.info(` - 请求体: ${methodMetadata.requestBody.description}`);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
} catch (error) {
|
|
44
|
-
logger.error('处理单个控制器失败:', error as Error);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* 示例2:验证Swagger注解的完整性
|
|
50
|
-
*/
|
|
51
|
-
static async validateSwaggerAnnotations() {
|
|
52
|
-
try {
|
|
53
|
-
logger.info('=== Swagger处理器示例:验证注解完整性 ===');
|
|
54
|
-
|
|
55
|
-
const validationResult = swaggerProcessor.validateSwaggerAnnotations(SwaggerExampleController);
|
|
56
|
-
|
|
57
|
-
logger.info('验证结果:', {
|
|
58
|
-
isValid: validationResult.isValid,
|
|
59
|
-
errors: validationResult.errors,
|
|
60
|
-
warnings: validationResult.warnings
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
if (validationResult.errors.length > 0) {
|
|
64
|
-
logger.error('验证错误:', new Error(validationResult.errors.join(', ')));
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
if (validationResult.warnings.length > 0) {
|
|
68
|
-
logger.warn('验证警告:', validationResult.warnings.join(', '));
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
} catch (error) {
|
|
72
|
-
logger.error('验证Swagger注解失败:', error as Error);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* 示例3:生成OpenAPI规范
|
|
78
|
-
*/
|
|
79
|
-
static async generateOpenAPISpec() {
|
|
80
|
-
try {
|
|
81
|
-
logger.info('=== Swagger处理器示例:生成OpenAPI规范 ===');
|
|
82
|
-
|
|
83
|
-
const controllers = [SwaggerExampleController];
|
|
84
|
-
const openAPISpec = swaggerProcessor.generateOpenAPISpec(controllers);
|
|
85
|
-
|
|
86
|
-
logger.info('OpenAPI规范生成成功:');
|
|
87
|
-
logger.info(` - OpenAPI版本: ${openAPISpec.openapi}`);
|
|
88
|
-
logger.info(` - API标题: ${openAPISpec.info.title}`);
|
|
89
|
-
logger.info(` - API版本: ${openAPISpec.info.version}`);
|
|
90
|
-
logger.info(` - 服务器数量: ${openAPISpec.servers.length}`);
|
|
91
|
-
logger.info(` - 路径数量: ${Object.keys(openAPISpec.paths).length}`);
|
|
92
|
-
|
|
93
|
-
// 输出路径信息
|
|
94
|
-
Object.keys(openAPISpec.paths).forEach(path => {
|
|
95
|
-
const pathInfo = openAPISpec.paths[path];
|
|
96
|
-
const methods = Object.keys(pathInfo);
|
|
97
|
-
logger.info(` - 路径 ${path}: ${methods.join(', ')}`);
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
return openAPISpec;
|
|
101
|
-
|
|
102
|
-
} catch (error) {
|
|
103
|
-
logger.error('生成OpenAPI规范失败:', error as Error);
|
|
104
|
-
throw error;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 示例4:处理方法级别的Swagger注解
|
|
110
|
-
*/
|
|
111
|
-
static async processMethodAnnotations() {
|
|
112
|
-
try {
|
|
113
|
-
logger.info('=== Swagger处理器示例:处理方法级别注解 ===');
|
|
114
|
-
|
|
115
|
-
const methodName = 'updateUser';
|
|
116
|
-
const methodMetadata = swaggerProcessor.processMethod(SwaggerExampleController, methodName);
|
|
117
|
-
|
|
118
|
-
logger.info(`方法 ${methodName} 的Swagger元数据:`);
|
|
119
|
-
logger.info(` - 操作ID: ${methodMetadata.operationId}`);
|
|
120
|
-
logger.info(` - 摘要: ${methodMetadata.summary}`);
|
|
121
|
-
logger.info(` - 描述: ${methodMetadata.description}`);
|
|
122
|
-
logger.info(` - 标签: ${methodMetadata.tags.join(', ')}`);
|
|
123
|
-
|
|
124
|
-
// 输出参数信息
|
|
125
|
-
if (methodMetadata.parameters.length > 0) {
|
|
126
|
-
logger.info(' - 参数:');
|
|
127
|
-
methodMetadata.parameters.forEach(param => {
|
|
128
|
-
logger.info(` * ${param.name} (${param.in}): ${param.description || '无描述'}`);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// 输出请求体信息
|
|
133
|
-
if (methodMetadata.requestBody) {
|
|
134
|
-
logger.info(` - 请求体: ${methodMetadata.requestBody.description || '无描述'}`);
|
|
135
|
-
logger.info(` * 必需: ${methodMetadata.requestBody.required}`);
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// 输出响应信息
|
|
139
|
-
if (methodMetadata.responses.length > 0) {
|
|
140
|
-
logger.info(' - 响应:');
|
|
141
|
-
methodMetadata.responses.forEach(response => {
|
|
142
|
-
logger.info(` * ${response.status}: ${response.description}`);
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
} catch (error) {
|
|
147
|
-
logger.error('处理方法级别注解失败:', error as Error);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* 运行所有示例
|
|
153
|
-
*/
|
|
154
|
-
static async runAllExamples() {
|
|
155
|
-
try {
|
|
156
|
-
logger.info('开始运行Swagger处理器示例...');
|
|
157
|
-
|
|
158
|
-
await this.processSingleController();
|
|
159
|
-
await this.validateSwaggerAnnotations();
|
|
160
|
-
await this.processMethodAnnotations();
|
|
161
|
-
await this.generateOpenAPISpec();
|
|
162
|
-
|
|
163
|
-
logger.info('所有Swagger处理器示例运行完成!');
|
|
164
|
-
|
|
165
|
-
} catch (error) {
|
|
166
|
-
logger.error('运行Swagger处理器示例失败:', error as Error);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|