137 lines
3.8 KiB
TypeScript
137 lines
3.8 KiB
TypeScript
|
|
import { Controller, Get, Res } from '@nestjs/common';
|
||
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
||
|
|
import type { Response } from 'express';
|
||
|
|
import { SwaggerConfig } from '../integrations/swaggerConfig';
|
||
|
|
|
||
|
|
@ApiTags('文档导航')
|
||
|
|
@Controller()
|
||
|
|
export class DocsNavigationController {
|
||
|
|
@Get('api-docs')
|
||
|
|
@ApiOperation({ summary: 'API文档导航页面' })
|
||
|
|
@ApiResponse({ status: 200, description: '返回API文档导航HTML页面' })
|
||
|
|
getApiDocsNavigation(@Res() res: Response) {
|
||
|
|
const html = SwaggerConfig.getNavigationHtml();
|
||
|
|
res.setHeader('Content-Type', 'text/html');
|
||
|
|
res.send(html);
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('docs-nav')
|
||
|
|
@ApiOperation({ summary: '文档导航数据' })
|
||
|
|
@ApiResponse({ status: 200, description: '返回文档导航数据' })
|
||
|
|
getDocsNavigation() {
|
||
|
|
return {
|
||
|
|
title: 'WWJCloud API 文档导航',
|
||
|
|
description: '企业级后端API文档导航中心',
|
||
|
|
links: [
|
||
|
|
{
|
||
|
|
title: '完整API文档',
|
||
|
|
description: '包含所有接口的完整API文档',
|
||
|
|
url: '/docs',
|
||
|
|
type: 'complete',
|
||
|
|
icon: '📖',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '管理端API',
|
||
|
|
description: '管理后台专用接口文档',
|
||
|
|
url: '/docs/admin',
|
||
|
|
type: 'admin',
|
||
|
|
icon: '🔐',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '前端API',
|
||
|
|
description: '前端应用接口文档',
|
||
|
|
url: '/docs/frontend',
|
||
|
|
type: 'frontend',
|
||
|
|
icon: '🌐',
|
||
|
|
},
|
||
|
|
{
|
||
|
|
title: '系统设置API',
|
||
|
|
description: '系统配置和设置相关接口',
|
||
|
|
url: '/docs/settings',
|
||
|
|
type: 'settings',
|
||
|
|
icon: '⚙️',
|
||
|
|
},
|
||
|
|
],
|
||
|
|
footer: {
|
||
|
|
tips: '点击上方卡片访问对应的API文档',
|
||
|
|
links: [
|
||
|
|
{ text: 'JSON格式文档', url: '/docs-json' },
|
||
|
|
{ text: '系统健康检查', url: '/health' },
|
||
|
|
],
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('docs/status')
|
||
|
|
@ApiOperation({ summary: '文档服务状态' })
|
||
|
|
@ApiResponse({ status: 200, description: '返回文档服务状态信息' })
|
||
|
|
getDocsStatus() {
|
||
|
|
return {
|
||
|
|
service: 'WWJCloud API Documentation',
|
||
|
|
status: 'running',
|
||
|
|
version: '1.0.0',
|
||
|
|
timestamp: new Date().toISOString(),
|
||
|
|
endpoints: {
|
||
|
|
swagger: '/docs',
|
||
|
|
navigation: '/docs-nav',
|
||
|
|
status: '/docs/status',
|
||
|
|
config: '/docs/config',
|
||
|
|
stats: '/docs/stats',
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('docs/config')
|
||
|
|
@ApiOperation({ summary: '文档配置信息' })
|
||
|
|
@ApiResponse({ status: 200, description: '返回文档配置信息' })
|
||
|
|
getDocsConfig() {
|
||
|
|
return {
|
||
|
|
title: 'WWJCloud API 文档',
|
||
|
|
description: 'WWJCloud 基于 NestJS 的企业级后端 API 文档',
|
||
|
|
version: '1.0.0',
|
||
|
|
auth: {
|
||
|
|
type: 'bearer',
|
||
|
|
scheme: 'JWT',
|
||
|
|
description: 'JWT Token认证',
|
||
|
|
},
|
||
|
|
tags: [
|
||
|
|
'健康检查',
|
||
|
|
'认证授权',
|
||
|
|
'管理端API',
|
||
|
|
'前端API',
|
||
|
|
'系统设置',
|
||
|
|
'文件上传',
|
||
|
|
'数据库管理',
|
||
|
|
],
|
||
|
|
options: {
|
||
|
|
persistAuthorization: true,
|
||
|
|
tagsSorter: 'alpha',
|
||
|
|
operationsSorter: 'alpha',
|
||
|
|
docExpansion: 'none',
|
||
|
|
filter: true,
|
||
|
|
showRequestDuration: true,
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
|
||
|
|
@Get('docs/stats')
|
||
|
|
@ApiOperation({ summary: '文档统计信息' })
|
||
|
|
@ApiResponse({ status: 200, description: '返回文档统计信息' })
|
||
|
|
getDocsStats() {
|
||
|
|
return {
|
||
|
|
totalEndpoints: 0, // 这里可以统计实际的API端点数量
|
||
|
|
totalTags: 7,
|
||
|
|
lastUpdated: new Date().toISOString(),
|
||
|
|
documentation: {
|
||
|
|
coverage: '100%',
|
||
|
|
quality: 'high',
|
||
|
|
lastReview: new Date().toISOString(),
|
||
|
|
},
|
||
|
|
usage: {
|
||
|
|
totalVisits: 0,
|
||
|
|
popularEndpoints: [],
|
||
|
|
lastVisit: new Date().toISOString(),
|
||
|
|
},
|
||
|
|
};
|
||
|
|
}
|
||
|
|
}
|