Files
bw-mini-app-server/src/config/swagger.config.ts
imeepos 2bac851e6d refactor: 实现正确的CurrentUser装饰器并修复类型问题
- 新增CurrentUser装饰器和CurrentUserData类型定义
- 替换content-moderation.controller.ts中的模拟装饰器实现
- 修复测试文件中的用户数据结构,确保包含必要的platform字段
- 修复app.module.ts中已删除控制器的引用
- 优化Swagger配置使用环境变量定义服务器地址
2025-09-08 11:06:09 +08:00

88 lines
2.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { INestApplication } from '@nestjs/common';
export function setupSwagger(app: INestApplication): void {
const config = new DocumentBuilder()
.setTitle('多平台小程序统一后台API')
.setDescription(
`
## 功能特性
- 🔐 统一用户认证 (微信/支付宝/百度/字节跳动等)
- 🎨 AI模板系统 (图片/视频生成)
- 💰 积分系统 (积分获取、消耗、管理)
- 📱 多平台适配 (8大平台支持)
- 🧩 扩展数据存储 (灵活的JSON数据)
## 认证方式
使用JWT Bearer Token进行API认证
## 响应格式
所有API响应都遵循统一格式
\`\`\`json
{
"code": 200,
"message": "success",
"data": {},
"timestamp": 1703001000000,
"traceId": "trace-uuid"
}
\`\`\`
`,
)
.setVersion('1.0.0')
.setContact('开发团队', 'https://example.com', 'dev@example.com')
.setLicense('MIT', 'https://opensource.org/licenses/MIT')
.addBearerAuth(
{
type: 'http',
scheme: 'bearer',
bearerFormat: 'JWT',
name: 'JWT',
description: 'Enter JWT token',
in: 'header',
},
'JWT-auth',
)
.addTag('用户管理', '用户注册、登录、信息管理')
.addTag('平台适配', '各平台特定接口和数据同步')
.addTag('AI模板系统', 'AI图片/视频生成模板管理')
.addTag('积分系统', '积分获取、消耗、查询管理')
.addTag('扩展服务', '预留的扩展功能接口')
.addServer(`http://localhost:${process.env.PORT || 3003}`, '开发环境')
.addServer(
process.env.TEST_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com',
'测试环境',
)
.addServer(
process.env.PROD_SERVER_URL || 'https://sd2s2bl25ni4n75na2bog.apigateway-cn-beijing.volceapi.com',
'生产环境',
)
.build();
const document = SwaggerModule.createDocument(app as any, config, {
operationIdFactory: (controllerKey: string, methodKey: string) => methodKey,
});
console.log('🔧 Setting up Swagger documentation...');
SwaggerModule.setup('docs', app as any, document, {
swaggerOptions: {
persistAuthorization: true,
tagsSorter: 'alpha',
operationsSorter: 'alpha',
docExpansion: 'none',
filter: true,
showRequestDuration: true,
},
customSiteTitle: '多平台API文档',
customfavIcon: '/favicon.ico',
customJs: [
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-bundle.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui-standalone-preset.min.js',
],
customCssUrl: [
'https://cdnjs.cloudflare.com/ajax/libs/swagger-ui/4.15.5/swagger-ui.min.css',
],
});
console.log('✅ Swagger documentation setup completed at /api/docs');
}