-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger_test.go
51 lines (43 loc) · 1.52 KB
/
swagger_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package swagger_test
import (
"github.com/darwinOrg/go-common/page"
"github.com/darwinOrg/go-common/result"
"github.com/darwinOrg/go-common/utils"
"github.com/darwinOrg/go-swagger"
"github.com/darwinOrg/go-web/wrapper"
"github.com/gin-gonic/gin"
"testing"
)
func TestExportSwaggerFile(t *testing.T) {
engine := gin.Default()
wrapper.Get(&wrapper.RequestHolder[wrapper.MapRequest, *result.Result[*result.Void]]{
Remark: "测试get接口",
RouterGroup: engine.Group("/test"),
RelativePath: "/get",
})
wrapper.Post(&wrapper.RequestHolder[UserRequest, *result.Result[*page.PageList[*UserRequest]]]{
Remark: "测试post接口",
RouterGroup: engine.Group("/test"),
RelativePath: "post",
})
swagger.ExportSwaggerFile(&swagger.ExportSwaggerRequest{
ServiceName: "test-service",
//Title: "测试服务标题",
//Description: "测试服务描述",
//OutDir: "openapi/v1",
//Version: "v0.0.1",
RequestApis: wrapper.GetRequestApis(),
})
}
func TestCreateSchemaForObject(t *testing.T) {
schema := swagger.CreateSchemaForObject(&UserRequest{})
t.Log(utils.MustConvertBeanToJsonString(schema))
}
type UserRequest struct {
Name string `binding:"required" errMsg:"姓名错误:不能为空" title:"名称" remark:"名称"`
Age int `binding:"required,gt=0,lt=100" title:"年龄" remark:"年龄"`
UserInfo *userInfo `binding:"required"`
}
type userInfo struct {
Sex int `binding:"required,gt=0,lt=5" errMsg:"性别错误" title:"性别" remark:"性别,0:男,1:女"`
}