All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m55s
46 lines
1.2 KiB
Go
46 lines
1.2 KiB
Go
package main
|
||
|
||
import (
|
||
"log"
|
||
"path/filepath"
|
||
|
||
"github.com/gofiber/fiber/v2"
|
||
|
||
"github.com/break/junhong_cmp_fiber/internal/bootstrap"
|
||
"github.com/break/junhong_cmp_fiber/internal/routes"
|
||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||
)
|
||
|
||
func main() {
|
||
outputFile := "./docs/admin-openapi.yaml"
|
||
if err := generateAdminDocs(outputFile); err != nil {
|
||
log.Fatalf("生成 OpenAPI 文档失败: %v", err)
|
||
}
|
||
|
||
absPath, _ := filepath.Abs(outputFile)
|
||
log.Printf("成功在以下位置生成 OpenAPI 文档: %s", absPath)
|
||
}
|
||
|
||
// generateAdminDocs 生成 Admin API 的 OpenAPI 文档
|
||
func generateAdminDocs(outputPath string) error {
|
||
// 1. 创建生成器
|
||
adminDoc := openapi.NewGenerator("Admin API", "1.0")
|
||
|
||
// 2. 创建临时 Fiber App 用于路由注册
|
||
app := fiber.New()
|
||
|
||
// 3. 创建所有 Handler(使用 nil 依赖,因为只需要路由结构)
|
||
// 新增 Handler 必须注册到 openapi.BuildDocHandlers,代理开放接口也从该入口进入文档生成器。
|
||
handlers := openapi.BuildDocHandlers()
|
||
|
||
// 4. 注册所有路由到文档生成器
|
||
routes.RegisterRoutesWithDoc(app, handlers, &bootstrap.Middlewares{}, adminDoc)
|
||
|
||
// 5. 保存规范到指定路径
|
||
if err := adminDoc.Save(outputPath); err != nil {
|
||
return err
|
||
}
|
||
|
||
return nil
|
||
}
|