|
1 | 1 | package parameter_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "context" |
4 | 5 | "mokapi/providers/openapi/parameter" |
5 | 6 | "mokapi/providers/openapi/schema/schematest" |
6 | 7 | "net/http" |
@@ -268,6 +269,43 @@ func TestParsePath(t *testing.T) { |
268 | 269 | require.Equal(t, map[string]interface{}{"role": "admin", "firstName": "Alex"}, result[parameter.Path]["foo"].Value) |
269 | 270 | }, |
270 | 271 | }, |
| 272 | + { |
| 273 | + name: "path parameter and base path", |
| 274 | + param: ¶meter.Parameter{ |
| 275 | + Name: "foo", |
| 276 | + Type: parameter.Path, |
| 277 | + Schema: schematest.New("string"), |
| 278 | + Style: "", |
| 279 | + Explode: explode(false), |
| 280 | + }, |
| 281 | + route: "/{foo}", |
| 282 | + request: func() *http.Request { |
| 283 | + r := httptest.NewRequest(http.MethodGet, "https://foo.bar/mokapi/foo/bar", nil) |
| 284 | + return r.WithContext(context.WithValue(r.Context(), "servicePath", "/mokapi/foo")) |
| 285 | + }, |
| 286 | + test: func(t *testing.T, result parameter.RequestParameters, err error) { |
| 287 | + require.NoError(t, err) |
| 288 | + require.Equal(t, "bar", result[parameter.Path]["foo"].Value) |
| 289 | + }, |
| 290 | + }, |
| 291 | + { |
| 292 | + name: "path parameter and trailing slash in request", |
| 293 | + param: ¶meter.Parameter{ |
| 294 | + Name: "foo", |
| 295 | + Type: parameter.Path, |
| 296 | + Schema: schematest.New("string"), |
| 297 | + Style: "", |
| 298 | + Explode: explode(false), |
| 299 | + }, |
| 300 | + route: "/{foo}", |
| 301 | + request: func() *http.Request { |
| 302 | + return httptest.NewRequest(http.MethodGet, "https://foo.bar/bar/", nil) |
| 303 | + }, |
| 304 | + test: func(t *testing.T, result parameter.RequestParameters, err error) { |
| 305 | + require.NoError(t, err) |
| 306 | + require.Equal(t, "bar", result[parameter.Path]["foo"].Value) |
| 307 | + }, |
| 308 | + }, |
271 | 309 | } |
272 | 310 |
|
273 | 311 | for _, tc := range testcases { |
|
0 commit comments