@@ -32,6 +32,7 @@ func TestMain(m *testing.M) {
3232 g .GET ("/scalar" , tonic .Handler (scalarHandler , 200 ))
3333 g .GET ("/error" , tonic .Handler (errorHandler , 200 ))
3434 g .GET ("/path/:param" , tonic .Handler (pathHandler , 200 ))
35+ g .GET ("/path-list/:param-path-list" , tonic .Handler (pathListHandler , 200 ))
3536 g .GET ("/query" , tonic .Handler (queryHandler , 200 ))
3637 g .GET ("/query-old" , tonic .Handler (queryHandlerOld , 200 ))
3738 g .POST ("/body" , tonic .Handler (bodyHandler , 200 ))
@@ -87,13 +88,13 @@ func TestPathQuery(t *testing.T) {
8788
8889 tester .AddCall ("query-complex" , "GET" , fmt .Sprintf ("/query?param=foo¶m-complex=%s" , now ), "" ).Checkers (iffy .ExpectStatus (200 ), expectString ("param-complex" , string (now )))
8990
90- // Explode.
91- tester .AddCall ("query-explode " , "GET" , "/query?param=foo¶m-explode =a¶m-explode =b¶m-explode =c" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-explode " , "a" , "b" , "c" ))
92- tester .AddCall ("query-explode-disabled-ok " , "GET" , "/query?param=foo¶m-explode-disabled =x,y,z" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-explode-disabled " , "x" , "y" , "z" ))
93- tester .AddCall ("query-explode-disabled-error " , "GET" , "/query?param=foo¶m-explode-disabled =a¶m-explode-disabled =b" , "" ).Checkers (iffy .ExpectStatus (400 ))
94- tester .AddCall ("query-explode-string " , "GET" , "/query?param=foo¶m-explode -string=x,y,z" , "" ).Checkers (iffy .ExpectStatus (200 ), expectString ("param-explode -string" , "x,y,z" ))
95- tester .AddCall ("query-explode -default" , "GET" , "/query?param=foo" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-explode -default" , "1" , "2" , "3" )) // default with explode
96- tester .AddCall ("query-explode-disabled-default " , "GET" , "/query?param=foo " , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-explode-disabled-default " , "1,2, 3" )) // default without explode
91+ // Array split
92+ tester .AddCall ("query-list-nosplit " , "GET" , "/query?param=foo¶m-list-nosplit =a¶m-list-nosplit =b¶m-list-nosplit =c" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-list-nosplit " , "a" , "b" , "c" ))
93+ tester .AddCall ("query-list-split " , "GET" , "/query?param=foo¶m-list-split =x,y,z" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-list-split " , "x" , "y" , "z" ))
94+ tester .AddCall ("query-list-split-repeated " , "GET" , "/query?param=foo¶m-list-split =a¶m-list-split =b" , "" ).Checkers (iffy .ExpectStatus (400 ))
95+ tester .AddCall ("query-list-nosplit-single " , "GET" , "/query?param=foo¶m-list -string-nosplit =x,y,z" , "" ).Checkers (iffy .ExpectStatus (200 ), expectString ("param-list -string-nosplit " , "x,y,z" ))
96+ tester .AddCall ("query-list -default" , "GET" , "/query?param=foo" , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-list -default" , "1" , "2" , "3" )) // default with explode
97+ tester .AddCall ("path-list " , "GET" , "/path-list/1,2,3 " , "" ).Checkers (iffy .ExpectStatus (200 ), expectStringArr ("param-path-list " , "1" , "2" , " 3" ))
9798
9899 tester .Run ()
99100}
@@ -150,20 +151,27 @@ func pathHandler(c *gin.Context, in *pathIn) (*pathIn, error) {
150151 return in , nil
151152}
152153
154+ type pathListIn struct {
155+ ParamPathList []string `path:"param-path-list" json:"param-path-list" commalist:"true"`
156+ }
157+
158+ func pathListHandler (c * gin.Context , in * pathListIn ) (* pathListIn , error ) {
159+ return in , nil
160+ }
161+
153162type queryIn struct {
154- Param string `query:"param" json:"param" validate:"required"`
155- ParamOptional string `query:"param-optional" json:"param-optional"`
156- Params []string `query:"params" json:"params"`
157- ParamInt int `query:"param-int" json:"param-int"`
158- ParamBool bool `query:"param-bool" json:"param-bool"`
159- ParamDefault string `query:"param-default" json:"param-default" default:"default" validate:"required"`
160- ParamPtr * string `query:"param-ptr" json:"param-ptr"`
161- ParamComplex time.Time `query:"param-complex" json:"param-complex"`
162- ParamExplode []string `query:"param-explode" json:"param-explode" explode:"true"`
163- ParamExplodeDisabled []string `query:"param-explode-disabled" json:"param-explode-disabled" explode:"false"`
164- ParamExplodeString string `query:"param-explode-string" json:"param-explode-string" explode:"true"`
165- ParamExplodeDefault []string `query:"param-explode-default" json:"param-explode-default" default:"1,2,3" explode:"true"`
166- ParamExplodeDefaultDisabled []string `query:"param-explode-disabled-default" json:"param-explode-disabled-default" default:"1,2,3" explode:"false"`
163+ Param string `query:"param" json:"param" validate:"required"`
164+ ParamOptional string `query:"param-optional" json:"param-optional"`
165+ Params []string `query:"params" json:"params"`
166+ ParamInt int `query:"param-int" json:"param-int"`
167+ ParamBool bool `query:"param-bool" json:"param-bool"`
168+ ParamDefault string `query:"param-default" json:"param-default" default:"default" validate:"required"`
169+ ParamPtr * string `query:"param-ptr" json:"param-ptr"`
170+ ParamComplex time.Time `query:"param-complex" json:"param-complex"`
171+ ParamListNoSplit []string `query:"param-list-nosplit" json:"param-list-nosplit"`
172+ ParamListSplit []string `query:"param-list-split" json:"param-list-split" commalist:"true"`
173+ ParamListStringNoSplit string `query:"param-list-string-nosplit" json:"param-list-string-nosplit"`
174+ ParamListDefault []string `query:"param-list-default" json:"param-list-default" default:"1,2,3" commalist:"true"`
167175 * DoubleEmbedded
168176}
169177
0 commit comments