fix: 升级适配api-doc

This commit is contained in:
2025-09-30 17:07:28 +08:00
parent 0698c0d1e3
commit de7c864678
5 changed files with 46 additions and 6 deletions

4
go.mod
View File

@ -5,7 +5,7 @@ go 1.24.1
toolchain go1.24.2
require (
git.zhangdeman.cn/zhangdeman/api-doc v1.0.2
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20250930090005-69177ebcd195
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20250429065800-fc340b9417cf
git.zhangdeman.cn/zhangdeman/exception v0.0.0-20250510123912-a0d52fc093ab
@ -13,7 +13,7 @@ require (
git.zhangdeman.cn/zhangdeman/logger v0.0.0-20250817142254-a501f79e7894
git.zhangdeman.cn/zhangdeman/network v0.0.0-20250726060351-78810e906bfa
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250830115953-2779077bc555
git.zhangdeman.cn/zhangdeman/wrapper v0.0.0-20250321102712-1cbfbe959740
github.com/gin-contrib/pprof v1.5.3
github.com/gin-gonic/gin v1.11.0

4
go.sum
View File

@ -1,5 +1,7 @@
git.zhangdeman.cn/zhangdeman/api-doc v1.0.2 h1:zLbHBlRQwg3iXqj/40gMiv4AO0pGs/WzTr/2icFmz+4=
git.zhangdeman.cn/zhangdeman/api-doc v1.0.2/go.mod h1:PgZIhEk8yK/YU2xfj6OmtH/6XGxUJ3K2cmr34CzYjyM=
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20250930090005-69177ebcd195 h1:S1DqbZdJxKxzEbanmG2I/yycScml7dJbYR+VrXzeuo0=
git.zhangdeman.cn/zhangdeman/api-doc v1.0.3-0.20250930090005-69177ebcd195/go.mod h1:tMqiqByNQ5WmFieruKEcEVJv0g2QqA5XSqV0S9WvOZU=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772 h1:Yo1ur3LnDF5s7F7tpJsNrdUSF8LwYKnN9TdQU32F3eU=
git.zhangdeman.cn/zhangdeman/consts v0.0.0-20250916024308-d378e6c57772/go.mod h1:5p8CEKGBxi7qPtTXDI3HDmqKAfIm5i/aBWdrbkbdNjc=
git.zhangdeman.cn/zhangdeman/dynamic-struct v0.0.0-20250429065800-fc340b9417cf h1:xCPM3U6i62UvLo9VNvDP45Ue3dPl7ratHu1rSEJRE2k=
@ -22,6 +24,8 @@ git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9 h1:/GL
git.zhangdeman.cn/zhangdeman/serialize v0.0.0-20250504055908-8d68e6106ea9/go.mod h1:ABJ655C5QenQNOzf7LjCe4sSB52CXvaWLX2Zg4uwDJY=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5 h1:dD1Q/MIrRmIhKqfYPH+y167ca9CKwTPuQt3c1hXWGJ8=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250412104923-c1ecb1bfe8d5/go.mod h1:PB486NC82nuvn5yi+U2i48ogX/9EAETWAHd8O9TwY9k=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250830115953-2779077bc555 h1:XQgYVEui0QKl5NXOvYpAg48zSc81obXF9cOinU8JuqQ=
git.zhangdeman.cn/zhangdeman/trace v0.0.0-20250830115953-2779077bc555/go.mod h1:+tLRnfL+ddqljSTOacSJoIv7TpbdWih3efd8Yvk/Hh8=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e h1:Q973S6CcWr1ICZhFI1STFOJ+KUImCl2BaIXm6YppBqI=
git.zhangdeman.cn/zhangdeman/util v0.0.0-20240618042405-6ee2c904644e/go.mod h1:VpPjBlwz8U+OxZuxzHQBv1aEEZ3pStH6bZvT21ADEbI=
git.zhangdeman.cn/zhangdeman/websocket v0.0.0-20241125101541-c5ea194c9c1e h1:YE2Gi+M03UDImIpWa3I7jzSesyfu2RL8x/4ONs5v0oE=

View File

@ -15,8 +15,42 @@ import (
)
func NewDoc(info *define.Info, servers []*define.ServerItem) *Doc {
if nil == info {
info = &define.Info{
Description: "",
Title: "",
TermsOfService: "",
Contact: &define.Contact{
Name: "",
Url: "",
Email: "",
},
License: nil,
Version: "",
}
}
if nil == info.Contact {
info.Contact = &define.Contact{
Name: "",
Url: "",
Email: "",
}
}
if nil == info.License {
info.License = &define.License{
Name: "",
Url: "",
}
}
return &Doc{
instance: apiDoc.NewOpenapiDoc(info, servers),
instance: apiDoc.NewOpenapiDoc(
apiDoc.WithDocDescription(info.Description),
apiDoc.WithDocTitle(info.Title),
apiDoc.WithDocContactEmail(info.Contact.Email),
apiDoc.WithDocContactName(info.Contact.Name),
apiDoc.WithDocLicense(info.License.Name),
apiDoc.WithDocServers(servers),
),
}
}

View File

@ -23,12 +23,13 @@ import (
"github.com/gin-contrib/pprof"
apiDocDefine "git.zhangdeman.cn/zhangdeman/api-doc/define"
apiDocEnum "git.zhangdeman.cn/zhangdeman/api-doc/enums"
"github.com/gin-gonic/gin"
)
func newServerOption(port int, optionList ...SetServerOptionFunc) *serverOption {
option := &serverOption{
swaggerUiTheme: apiDocDefine.SwaggerUIThemeRedocFree,
swaggerUiTheme: apiDocEnum.SwaggerUIThemeRedocFree.String(),
swaggerBaseUri: "/doc/swagger",
globalMiddlewareList: nil,
disableSwaggerDoc: false,
@ -125,7 +126,7 @@ func NewServer(port int, optionList ...SetServerOptionFunc) *server {
}
return &server{
router: r,
uiInstance: apiDoc.NewSwaggerUI(option.serverInfo, option.serverList, option.swaggerUiTheme),
uiInstance: apiDoc.NewSwaggerUI(option.serverInfo, option.serverList, apiDocEnum.SwaggerUITheme(option.swaggerUiTheme)),
port: port,
option: option,
}

View File

@ -8,8 +8,9 @@
package router
import (
"github.com/gin-gonic/gin"
"testing"
"github.com/gin-gonic/gin"
)
func TestNewServer(t *testing.T) {