@@ -9,8 +9,12 @@ import (
9
9
"github.com/stretchr/testify/require"
10
10
)
11
11
12
- func TestValidateRequestDefault (t * testing.T ) {
13
- const spec = `
12
+ func generateSpec (explode bool ) string {
13
+ explodeStr := "false"
14
+ if explode {
15
+ explodeStr = "true"
16
+ }
17
+ return `
14
18
openapi: 3.0.0
15
19
info:
16
20
title: 'Validator'
@@ -29,6 +33,7 @@ components:
29
33
in: query
30
34
name: type
31
35
required: false
36
+ explode: ` + explodeStr + `
32
37
description: Type parameter
33
38
schema:
34
39
type: array
@@ -43,9 +48,9 @@ components:
43
48
- B
44
49
- C
45
50
`
51
+ }
46
52
47
- router := setupTestRouter (t , spec )
48
-
53
+ func TestValidateRequestDefault (t * testing.T ) {
49
54
type args struct {
50
55
url string
51
56
expected []string
@@ -55,42 +60,57 @@ components:
55
60
args args
56
61
expectedModification bool
57
62
expectedErr error
63
+ spec string
58
64
}{
59
65
{
60
- name : "Valid request without type parameters set" ,
66
+ name : "Valid request without type parameters set and explode is false " ,
61
67
args : args {
62
68
url : "/category" ,
63
- expected : []string {"A" , "B" , " C" },
69
+ expected : []string {"A,B, C" },
64
70
},
65
71
expectedModification : false ,
66
72
expectedErr : nil ,
73
+ spec : generateSpec (false ),
67
74
},
68
75
{
69
- name : "Valid request with 1 type parameters set" ,
76
+ name : "Valid request with 1 type parameters set and explode is false " ,
70
77
args : args {
71
78
url : "/category?type=A" ,
72
79
expected : []string {"A" },
73
80
},
74
81
expectedModification : false ,
75
82
expectedErr : nil ,
83
+ spec : generateSpec (false ),
76
84
},
77
85
{
78
- name : "Valid request with 2 type parameters set" ,
86
+ name : "Valid request with 2 type parameters set and explode is false " ,
79
87
args : args {
80
88
url : "/category?type=A&type=C" ,
81
89
expected : []string {"A" , "C" },
82
90
},
83
91
expectedModification : false ,
84
92
expectedErr : nil ,
93
+ spec : generateSpec (false ),
85
94
},
86
95
{
87
- name : "Valid request with 1 type parameters set out of enum" ,
96
+ name : "Valid request with 1 type parameters set out of enum and explode is false " ,
88
97
args : args {
89
98
url : "/category?type=X" ,
90
99
expected : nil ,
91
100
},
92
101
expectedModification : false ,
93
102
expectedErr : & RequestError {},
103
+ spec : generateSpec (false ),
104
+ },
105
+ {
106
+ name : "Valid request without type parameters set and explode is true" ,
107
+ args : args {
108
+ url : "/category" ,
109
+ expected : []string {"A" , "B" , "C" },
110
+ },
111
+ expectedModification : false ,
112
+ expectedErr : nil ,
113
+ spec : generateSpec (true ),
94
114
},
95
115
}
96
116
for _ , tc := range tests {
@@ -99,6 +119,7 @@ components:
99
119
req , err := http .NewRequest (http .MethodGet , tc .args .url , nil )
100
120
require .NoError (t , err )
101
121
122
+ router := setupTestRouter (t , tc .spec )
102
123
route , pathParams , err := router .FindRoute (req )
103
124
require .NoError (t , err )
104
125
0 commit comments