@@ -9,8 +9,12 @@ import (
99 "github.com/stretchr/testify/require"
1010)
1111
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 `
1418openapi: 3.0.0
1519info:
1620 title: 'Validator'
@@ -29,6 +33,7 @@ components:
2933 in: query
3034 name: type
3135 required: false
36+ explode: ` + explodeStr + `
3237 description: Type parameter
3338 schema:
3439 type: array
@@ -43,9 +48,9 @@ components:
4348 - B
4449 - C
4550`
51+ }
4652
47- router := setupTestRouter (t , spec )
48-
53+ func TestValidateRequestDefault (t * testing.T ) {
4954 type args struct {
5055 url string
5156 expected []string
@@ -55,42 +60,57 @@ components:
5560 args args
5661 expectedModification bool
5762 expectedErr error
63+ spec string
5864 }{
5965 {
60- name : "Valid request without type parameters set" ,
66+ name : "Valid request without type parameters set and explode is false " ,
6167 args : args {
6268 url : "/category" ,
63- expected : []string {"A" , "B" , " C" },
69+ expected : []string {"A,B, C" },
6470 },
6571 expectedModification : false ,
6672 expectedErr : nil ,
73+ spec : generateSpec (false ),
6774 },
6875 {
69- name : "Valid request with 1 type parameters set" ,
76+ name : "Valid request with 1 type parameters set and explode is false " ,
7077 args : args {
7178 url : "/category?type=A" ,
7279 expected : []string {"A" },
7380 },
7481 expectedModification : false ,
7582 expectedErr : nil ,
83+ spec : generateSpec (false ),
7684 },
7785 {
78- name : "Valid request with 2 type parameters set" ,
86+ name : "Valid request with 2 type parameters set and explode is false " ,
7987 args : args {
8088 url : "/category?type=A&type=C" ,
8189 expected : []string {"A" , "C" },
8290 },
8391 expectedModification : false ,
8492 expectedErr : nil ,
93+ spec : generateSpec (false ),
8594 },
8695 {
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 " ,
8897 args : args {
8998 url : "/category?type=X" ,
9099 expected : nil ,
91100 },
92101 expectedModification : false ,
93102 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 ),
94114 },
95115 }
96116 for _ , tc := range tests {
@@ -99,6 +119,7 @@ components:
99119 req , err := http .NewRequest (http .MethodGet , tc .args .url , nil )
100120 require .NoError (t , err )
101121
122+ router := setupTestRouter (t , tc .spec )
102123 route , pathParams , err := router .FindRoute (req )
103124 require .NoError (t , err )
104125
0 commit comments