调试文档集成
This commit is contained in:
parent
c3df76e94d
commit
d832eef5a0
4
go.mod
4
go.mod
@ -79,3 +79,7 @@ require (
|
||||
gopkg.in/olahol/melody.v1 v1.0.0-20170518105555-d52139073376 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
replace (
|
||||
git.zhangdeman.cn/gateway/api-doc => ../api-doc
|
||||
)
|
@ -67,4 +67,5 @@ const (
|
||||
const (
|
||||
SwaggerUIThemeDefault = "swaggerUI" // 文档默认主题
|
||||
SwaggerUIThemeKnife4go = "knife4go" // knife4go 主题
|
||||
SwaggerUIThemeYDocLucky = "YDocLuckyUI" // YDoc Lucky UI 主题: https://github.com/NoBugBoy/LuckyUI
|
||||
)
|
||||
|
@ -30,7 +30,7 @@ type TestOut struct {
|
||||
}
|
||||
|
||||
type TestForm struct {
|
||||
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"get"`
|
||||
Meta `tag:"测试表单" path:"/a/b/c/d" desc:"测试接口" method:"GET"`
|
||||
Age int `json:"age" form:"age" binding:"min=20" err_msg:"年龄不能小于20"`
|
||||
Name string `json:"name" form:"name"`
|
||||
Test *Test `json:"test" form:"test"`
|
||||
@ -42,7 +42,7 @@ type Test struct {
|
||||
|
||||
func Test_parseController(t *testing.T) {
|
||||
SetValidateErrTag("err_msg")
|
||||
s := NewServer(8080, nil)
|
||||
s := NewServer(8888, nil)
|
||||
s.Group("test", nil, TestController{})
|
||||
s.Start()
|
||||
}
|
||||
|
@ -102,7 +102,22 @@ func (s *server) Group(routerPrefix string, middlewareList []gin.HandlerFunc, cL
|
||||
//
|
||||
// Date : 21:45 2025/2/15
|
||||
func (s *server) SwaggerUI() {
|
||||
swaggerInstance := NewSwaggerUI(s.docInstance, SwaggerUIThemeDefault)
|
||||
swaggerInstance := NewSwaggerUI(s.docInstance, SwaggerUIThemeKnife4go)
|
||||
s.router.GET("/swagger-resources", func(ctx *gin.Context) { // lucky UI获取分组信息
|
||||
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*") // 允许访问所有域
|
||||
ctx.JSON(http.StatusOK, []map[string]any{
|
||||
{
|
||||
"name": "服务文档",
|
||||
"url": "/swagger-ui/doc/openapi.json",
|
||||
"swaggerVersion": consts.SwaggerDocVersion3,
|
||||
},
|
||||
})
|
||||
// ctx.JSON(http.StatusOK, swaggerInstance.docInstance.Data())
|
||||
})
|
||||
s.router.GET("/swagger-ui/doc/openapi.json", func(ctx *gin.Context) {
|
||||
ctx.Writer.Header().Set("Access-Control-Allow-Origin", "*") // 允许访问所有域
|
||||
ctx.JSON(http.StatusOK, swaggerInstance.docInstance.Data())
|
||||
})
|
||||
s.router.GET("/doc/swagger/*any", func(ctx *gin.Context) {
|
||||
if ctx.Request.RequestURI == "/doc/swagger/doc.json" {
|
||||
// 默认swagger, 通过此接口读取文档数据
|
||||
|
Loading…
x
Reference in New Issue
Block a user