Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pkg/parsers/parsers.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ func ParsePath(httpPath string, queryRespMap map[string]gjson.Result) (string, e
newPath = append(newPath, value)
}

if len(pathParts)%2 == 0 {
// Always append the trailing path segment after the last match.
// With N matches, Split produces N+1 parts; the loop above covers
// indices 0..N-1, so the final part (index N) must be added here.
if len(pathParts) > len(matches) {
newPath = append(newPath, pathParts[len(pathParts)-1])
}

Expand Down
12 changes: 12 additions & 0 deletions pkg/parsers/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ func TestParseTwoParam(t *testing.T) {
assert.Equal(t, "/v1/charges/char_12345/capture/cust_12345", path)
}

func TestParsePathTwoParamsWithTrailing(t *testing.T) {
queryRespMap := map[string]gjson.Result{
"customer": gjson.Parse(`{"id": "cus_12345"}`),
"bank_account": gjson.Parse(`{"id": "ba_12345"}`),
}

httpPath := "/v1/customers/${customer:id}/sources/${bank_account:id}/verify"

path, _ := ParsePath(httpPath, queryRespMap)
assert.Equal(t, "/v1/customers/cus_12345/sources/ba_12345/verify", path)
}

func TestParsePathOneParamWithTrailing(t *testing.T) {
queryRespMap := map[string]gjson.Result{
"char_bender": gjson.Parse(`{"id": "char_12345"}`),
Expand Down
Loading