Files
junhong_cmp_fiber/cmd/gendocs/main.go
huang 98ff88d5c3
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m55s
开放接口,修复上游同步不对的问题
2026-05-11 11:20:48 +08:00

46 lines
1.2 KiB
Go
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.
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
}