|
1 | 1 | package swaggerspectests |
2 | 2 |
|
3 | | -// import ( |
4 | | -// "mime/multipart" |
5 | | -// "net/http" |
6 | | -// "testing" |
7 | | - |
8 | | -// simplapi "github.com/go-simpl/simplapi" |
9 | | -// _ "github.com/go-simpl/simplapi/pkg/framework/fiberframework" |
10 | | -// ) |
11 | | - |
12 | | -// type JsonInput struct { |
13 | | -// ContentType string `header:"Content-Type" example:"application/json"` |
14 | | -// Body struct { |
15 | | -// Name string `json:"name" example:"John Doe"` |
16 | | -// Age int `json:"age" example:"25"` |
17 | | -// IsAdmin *bool `json:"is_admin" example:"false"` |
18 | | -// Rating float64 `json:"rating" example:"4.5"` |
19 | | -// Tags []string `json:"tags" example:"[\"tag1\", \"tag2\"]"` |
20 | | -// } `body:"json"` |
21 | | -// } |
22 | | - |
23 | | -// type FormInput struct { |
24 | | -// Body struct { |
25 | | -// Name string `form:"name" example:"John Doe"` |
26 | | -// Age int `form:"age" example:"25"` |
27 | | -// IsAdmin *bool `form:"is_admin" example:"false"` |
28 | | -// Rating float64 `form:"rating" example:"4.5"` |
29 | | -// } `body:"urlencoded"` |
30 | | -// } |
31 | | - |
32 | | -// type MultipartInput struct { |
33 | | -// Body struct { |
34 | | -// Name string `form:"name" example:"John Doe"` |
35 | | -// Age int `form:"age" example:"25"` |
36 | | -// IsAdmin *bool `form:"is_admin" example:"false"` |
37 | | -// Rating float64 `form:"rating" example:"4.5"` |
38 | | -// Picture *multipart.FileHeader `form:"picture" example:"picture.jpg"` |
39 | | -// } `body:"multipart"` |
40 | | -// } |
41 | | - |
42 | | -// type Response1 struct { |
43 | | -// Status string `json:"status" example:"OK"` |
44 | | -// Nested []struct { |
45 | | -// Field1 string `json:"field1" example:"value1"` |
46 | | -// Field2 string `json:"field2" example:"value2"` |
47 | | -// Random complex64 `json:"random"` |
48 | | -// } `json:"nested"` |
49 | | -// } |
50 | | - |
51 | | -// func (r *Response1) GetStatusCode() int { |
52 | | -// return http.StatusOK |
53 | | -// } |
54 | | - |
55 | | -// type Response2 struct { |
56 | | -// Status string `json:"status" example:"NOT_OK"` |
57 | | -// } |
58 | | - |
59 | | -// func (r *Response2) GetStatusCode() int { |
60 | | -// return http.StatusOK |
61 | | -// } |
62 | | - |
63 | | -// type Response3 struct { |
64 | | -// Status string `json:"status" example:"OK"` |
65 | | -// Nested []struct { |
66 | | -// Field1 string `json:"field1" example:"value1"` |
67 | | -// Field2 string `json:"field2" example:"value2"` |
68 | | -// } `json:"nested"` |
69 | | -// } |
70 | | - |
71 | | -// func (r *Response3) GetStatusCode() int { |
72 | | -// return http.StatusOK |
73 | | -// } |
74 | | - |
75 | | -// func TestAllPossibleSchemaStuff(t *testing.T) { |
76 | | -// app := simplapi.New() |
77 | | - |
78 | | -// app.POST("/json", nil, func(input JsonInput) (*Response1, *Response2, *Response3, error) { |
79 | | -// return nil, nil, nil, nil |
80 | | -// }) |
81 | | - |
82 | | -// app.POST("/form", nil, func(input FormInput) (*Response1, *Response2, *Response3, error) { |
83 | | -// return nil, nil, nil, nil |
84 | | -// }) |
85 | | - |
86 | | -// app.POST("/multipart", nil, func(input MultipartInput) (*Response1, *Response2, *Response3, error) { |
87 | | -// return nil, nil, nil, nil |
88 | | -// }) |
89 | | -// } |
| 3 | +import ( |
| 4 | + "mime/multipart" |
| 5 | + "net/http" |
| 6 | + "testing" |
| 7 | + |
| 8 | + simplapi "github.com/go-simpl/simplapi" |
| 9 | + "github.com/go-simpl/simplapi/tests/utils" |
| 10 | +) |
| 11 | + |
| 12 | +type JsonInput struct { |
| 13 | + ContentType string `header:"Content-Type" example:"application/json"` |
| 14 | + Body struct { |
| 15 | + Name string `json:"name" example:"John Doe"` |
| 16 | + Age int `json:"age" example:"25"` |
| 17 | + IsAdmin *bool `json:"is_admin" example:"false"` |
| 18 | + Rating float64 `json:"rating" example:"4.5"` |
| 19 | + Tags []string `json:"tags" example:"[\"tag1\", \"tag2\"]"` |
| 20 | + } `body:"json"` |
| 21 | +} |
| 22 | + |
| 23 | +type FormInput struct { |
| 24 | + Body struct { |
| 25 | + Name string `form:"name" example:"John Doe"` |
| 26 | + Age int `form:"age" example:"25"` |
| 27 | + IsAdmin *bool `form:"is_admin" example:"false"` |
| 28 | + Rating float64 `form:"rating" example:"4.5"` |
| 29 | + } `body:"urlencoded"` |
| 30 | +} |
| 31 | + |
| 32 | +type MultipartInput struct { |
| 33 | + Body struct { |
| 34 | + Name string `form:"name" example:"John Doe"` |
| 35 | + Age int `form:"age" example:"25"` |
| 36 | + IsAdmin *bool `form:"is_admin" example:"false"` |
| 37 | + Rating float64 `form:"rating" example:"4.5"` |
| 38 | + Picture *multipart.FileHeader `form:"picture" example:"picture.jpg"` |
| 39 | + } `body:"multipart"` |
| 40 | +} |
| 41 | + |
| 42 | +type Response1 struct { |
| 43 | + Status string `json:"status" example:"OK"` |
| 44 | + Nested []struct { |
| 45 | + Field1 string `json:"field1" example:"value1"` |
| 46 | + Field2 string `json:"field2" example:"value2"` |
| 47 | + Random complex64 `json:"random"` |
| 48 | + } `json:"nested"` |
| 49 | +} |
| 50 | + |
| 51 | +func (r *Response1) GetStatusCode() int { |
| 52 | + return http.StatusOK |
| 53 | +} |
| 54 | + |
| 55 | +type Response2 struct { |
| 56 | + Status string `json:"status" example:"NOT_OK"` |
| 57 | +} |
| 58 | + |
| 59 | +func (r *Response2) GetStatusCode() int { |
| 60 | + return http.StatusOK |
| 61 | +} |
| 62 | + |
| 63 | +type Response3 struct { |
| 64 | + Status string `json:"status" example:"OK"` |
| 65 | + Nested []struct { |
| 66 | + Field1 string `json:"field1" example:"value1"` |
| 67 | + Field2 string `json:"field2" example:"value2"` |
| 68 | + } `json:"nested"` |
| 69 | +} |
| 70 | + |
| 71 | +func (r *Response3) GetStatusCode() int { |
| 72 | + return http.StatusOK |
| 73 | +} |
| 74 | + |
| 75 | +func TestAllPossibleSchemaStuff(t *testing.T) { |
| 76 | + frameworks := utils.GetAllFrameworks() |
| 77 | + for _, framework := range frameworks { |
| 78 | + app := simplapi.New(framework) |
| 79 | + |
| 80 | + app.POST("/json", func(input JsonInput) (*Response1, *Response2, *Response3, error) { |
| 81 | + return nil, nil, nil, nil |
| 82 | + }) |
| 83 | + |
| 84 | + app.POST("/form", func(input FormInput) (*Response1, *Response2, *Response3, error) { |
| 85 | + return nil, nil, nil, nil |
| 86 | + }) |
| 87 | + |
| 88 | + app.POST("/multipart", func(input MultipartInput) (*Response1, *Response2, *Response3, error) { |
| 89 | + return nil, nil, nil, nil |
| 90 | + }) |
| 91 | + |
| 92 | + app.Sync() |
| 93 | + } |
| 94 | +} |
0 commit comments