Skip to content

Commit

Permalink
fix: multi-value query params for vAPI methods
Browse files Browse the repository at this point in the history
vAPI methods can have multi-value query params, but the vapi/rest.Resource helper was setting to a single value.
  • Loading branch information
dougm committed Oct 6, 2021
1 parent 798b727 commit 57c4be5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion vapi/rest/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (r *Resource) WithAction(action string) *Resource {
func (r *Resource) WithParam(name string, value string) *Resource {
// ParseQuery handles empty case, and we control access to query string so shouldn't encounter an error case
params, _ := url.ParseQuery(r.u.RawQuery)
params[name] = []string{value}
params[name] = append(params[name], value)
r.u.RawQuery = params.Encode()
return r
}
Expand Down
7 changes: 7 additions & 0 deletions vapi/rest/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,12 @@ func TestResource_WithParam(t *testing.T) {
if !strings.Contains(url.String(), expectedPath) {
t.Errorf("Param incorrectly updated on resource, URL %q, expected path %q", url.String(), expectedPath)
}

url = c.Resource("api/some/resource")
url = url.WithParam("names", "foo").WithParam("names", "bar")
expectedPath = "api/some/resource?names=foo&names=bar"
if !strings.Contains(url.String(), expectedPath) {
t.Errorf("Param incorrectly updated on resource, URL %q, expected path %q", url.String(), expectedPath)
}
})
}

0 comments on commit 57c4be5

Please sign in to comment.