-
Notifications
You must be signed in to change notification settings - Fork 13
/
emit_openapi_test.go
56 lines (45 loc) · 1.11 KB
/
emit_openapi_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
package fastapi
import (
"github.com/gin-gonic/gin"
"testing"
)
type InnerStruct struct {
XYZ string `json:"XYZ"`
}
type In struct {
Input string `json:"input"`
X int `json:"x"`
Y float32 `json:"y"`
Z bool `json:"z"`
I []string `json:"i"`
J map[string]int8 `json:"j"`
}
type In2 struct {
InputTwo string `json:"input_two"`
Inner InnerStruct `json:"-"`
}
type Out struct {
Output string `json:"output"`
}
func RequestHandler(ctx *gin.Context, in In) (out Out, err error) {
return
}
func RequestHandlerTwo(ctx *gin.Context, in In2) (out Out, err error) {
return
}
func TestOpenAPIDefinition(t *testing.T) {
myRouter := NewRouter()
myRouter.AddCall("/ping", RequestHandler)
myRouter.AddCall("/pong", RequestHandlerTwo)
sw := myRouter.EmitOpenAPIDefinition()
if len(sw.Paths.Paths) != 2 {
t.Fatal("Wrong number of pathes")
}
if len(sw.Definitions) != 4 {
t.Fatal("Wrong number of definitions")
}
_, innerPresent := sw.Definitions["InnerStruct"]
if !innerPresent {
t.Fatal("Nested structure is not present in definitions")
}
}