| 1 | /* |
| 2 | * @Author: nevin |
| 3 | * @Date: 2021-12-21 18:05:12 |
| 4 | * @LastEditors: nevin |
| 5 | * @LastEditTime: 2025-01-15 14:24:51 |
| 6 | * @Description: 文档插件 |
| 7 | */ |
| 8 | import { INestApplication } from '@nestjs/common'; |
| 9 | import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'; |
| 10 | const API_URL = '/docs'; |
| 11 | export function createSwagger(app: INestApplication) { |
| 12 | // const version = require('../package.json').version || ''; // 获取同项目一致版本号 |
| 13 | const version = '1.0.0'; // 获取同项目一致版本号 |
| 14 | |
| 15 | const docConfig = new DocumentBuilder() |
| 16 | .setTitle('爱团团AiToEarnAPI文档') |
| 17 | .setVersion(version) |
| 18 | .addBearerAuth() |
| 19 | .build(); |
| 20 | |
| 21 | const document = SwaggerModule.createDocument(app, docConfig, {}); |
| 22 | SwaggerModule.setup(API_URL, app, document, { |
| 23 | customSiteTitle: `爱团团AiToEarnAPI文档`, |
| 24 | jsonDocumentUrl: `${API_URL}/openapi.json`, // 文档JSON |
| 25 | swaggerOptions: { |
| 26 | persistAuthorization: true, // 保持登录 |
| 27 | }, |
| 28 | }); |
| 29 | return API_URL; |
| 30 | } |
| 31 |