@@ -187,7 +187,7 @@ func TestAddRoutes(t *testing.T) {
187187 fixturesPath : "testdata/params.json" ,
188188 },
189189 {
190- name : "schema without params autofilled " ,
190+ name : "schema without explicit params autofill them " ,
191191 routes : func (t * testing.T , router * TestRouter ) {
192192 _ , err := router .AddRoute (http .MethodGet , "/users/{userId}" , okHandler , Definitions {
193193 Querystring : ParameterValue {
@@ -200,8 +200,11 @@ func TestAddRoutes(t *testing.T) {
200200
201201 _ , err = router .AddRoute (http .MethodGet , "/cars/{carId}/drivers/{driverId}" , okHandler , Definitions {})
202202 require .NoError (t , err )
203+
204+ _ , err = router .AddRoute (http .MethodGet , "/files/{name}.{extension}" , okHandler , Definitions {})
205+ require .NoError (t , err )
203206 },
204- testPath : "/users/12 " ,
207+ testPath : "/files/myid.yaml " ,
205208 fixturesPath : "testdata/params-autofill.json" ,
206209 },
207210 {
@@ -1118,3 +1121,61 @@ func getBaseSwagger(t *testing.T) *openapi3.T {
11181121 },
11191122 }
11201123}
1124+
1125+ func TestGetPathParamsAutoComplete (t * testing.T ) {
1126+ testCases := map [string ]struct {
1127+ schemaDefinition Definitions
1128+ path string
1129+ expected ParameterValue
1130+ }{
1131+ "no path params" : {
1132+ schemaDefinition : Definitions {},
1133+ path : "/users" ,
1134+ expected : nil ,
1135+ },
1136+ "with path params" : {
1137+ schemaDefinition : Definitions {},
1138+ path : "/users/{userId}" ,
1139+ expected : ParameterValue {
1140+ "userId" : {
1141+ Schema : & Schema {Value : "" },
1142+ },
1143+ },
1144+ },
1145+ "with multiple path params" : {
1146+ schemaDefinition : Definitions {},
1147+ path : "/foo/{bar}.{taz}" ,
1148+ expected : ParameterValue {
1149+ "bar" : {
1150+ Schema : & Schema {Value : "" },
1151+ },
1152+ "taz" : {
1153+ Schema : & Schema {Value : "" },
1154+ },
1155+ },
1156+ },
1157+ "with nested multiple path params" : {
1158+ schemaDefinition : Definitions {},
1159+ path : "/foo/{bar}.{taz}/{baz}/ok" ,
1160+ expected : ParameterValue {
1161+ "bar" : {
1162+ Schema : & Schema {Value : "" },
1163+ },
1164+ "taz" : {
1165+ Schema : & Schema {Value : "" },
1166+ },
1167+ "baz" : {
1168+ Schema : & Schema {Value : "" },
1169+ },
1170+ },
1171+ },
1172+ }
1173+
1174+ for name , test := range testCases {
1175+ t .Run (name , func (t * testing.T ) {
1176+ actual := getPathParamsAutoComplete (test .schemaDefinition , test .path )
1177+
1178+ require .Equal (t , test .expected , actual )
1179+ })
1180+ }
1181+ }
0 commit comments