-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreflect_test.go
executable file
·108 lines (95 loc) · 2.27 KB
/
reflect_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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package swaggos
import (
"encoding/json"
"fmt"
"github.com/stretchr/testify/require"
"net/http"
"testing"
)
type AS string
type Arr []string
type MAp map[string]struct{}
type Fun func()
type ArrayMap []map[string]struct{}
type A struct {
Int int `json:"int" doc:"required,number,整型数据"`
Str string
IntArray [3]int
IntString [3]string
IntArrayArray [][][][][][]int
ExampleArray [][][]ExampleObject
ExamplePtrArrayArray [][][][][][]*ExampleObject
ObjectArray [3]ObjectTest
ObjectSlice []*ExampleObject
Object *ExampleObject
Bool bool
Interface interface{}
Map map[string]interface{}
ExampleObject
MAp
Arr
ObjectOne ObjectTest
AS
Fun `json:"-"`
}
type ObjectTest struct {
Int int
Str string
IntArray [3]int
IntString [3]string
Slice []string
ObjectSlice []*ExampleObject
Object *ExampleObject
Bool bool
Interface interface{}
Map map[string]interface{}
}
type ExampleObject struct {
UserName string
Password string
}
func TestYiDoc(t *testing.T) {
yd := new(Swaggos)
yd.Define(new(A))
def, err := json.MarshalIndent(yd.definitions, "", " ")
fmt.Println(string(def), err)
}
func TestDocs(t *testing.T) {
d := NewSwaggo()
d.JWT("Token").
Oauth2Password("https://www.oauth2.com/token", []string{"openid"}).
HostInfo("localhost:8899", "/api/v1")
d.Get("/{id}").Query("orderBy", Attribute{
Description: "排序",
Required: false,
Type: "string",
Format: "string",
}).
Description("排序的用户").
Tag("orders").
Summary("排序").
JSON(new(A))
data, err := d.Build()
fmt.Println(string(data))
require.Nil(t, err)
http.HandleFunc("/", func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Access-Control-Allow-Origin", "*")
writer.Write(data)
})
http.ListenAndServe(":9991", nil)
}
type ArrayTest struct {
ObjectArray []TObject
ObjectArrayArray [][]*TObject
ObjectArrayArray2 [][][][]*TObject
}
type TObject struct {
Attr string `json:"attr"`
}
func TestBuildSchema(t *testing.T) {
y := NewSwaggo()
v := new(ArrayTest)
y.Define(v)
data, _ := y.Build()
fmt.Println(string(data))
}