-
Notifications
You must be signed in to change notification settings - Fork 0
/
api-def-srvc_test.go
59 lines (47 loc) · 1.37 KB
/
api-def-srvc_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
package apido
import (
"fmt"
)
type SomeThing struct {
IsImportant bool `json:"is_important" summary:"maybe"`
}
// serv_group with locale
type DemoStruct struct {
Id int32 `json:"id" summary:"unique number"`
Name string `json:"name" summary:"name of object"`
ArrSomeThing []*SomeThing `json:"arr_some_thing" summary:"array of some things"`
OptProp *string `json:"opt_prop" summary:"Optional property"`
OptInt *int32 `json:"opt_int"`
ItemUnderStruct *UnderStruct `json:"under_struct"`
}
type UnderStruct struct {
VeryProp string `json:"very_prop" summary:"Very"`
}
func ExampleToSwag() {
result := ToSwag(DemoStruct{})
fmt.Println(result["id"].SwagType)
fmt.Println(result["id"].SwagFormat)
fmt.Println(result["name"].SwagType)
fmt.Println(result["arr_some_thing"].SwagType)
// name convention for child elements: arr_child_name
fmt.Println(result["arr_some_thing"].ArrItem.RefParam)
fmt.Println("==opt_prop==")
fmt.Println(result["opt_prop"].SwagType)
fmt.Println("==opt_int==")
fmt.Println(result["opt_int"].SwagType)
fmt.Println(result["opt_int"].SwagFormat)
fmt.Println("==under_struct==")
fmt.Println(result["under_struct"].RefParam)
// OUTPUT: integer
// int32
// string
// array
// some_thing
// ==opt_prop==
// string
// ==opt_int==
// integer
// int32
// ==under_struct==
// under_struct
}