Skip to content

Commit 093c434

Browse files
synack-evanrbretecher
authored andcommitted
feat: add support for QueryParam
1 parent fb148ca commit 093c434

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

collection_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -475,18 +475,14 @@ func (suite *CollectionTestSuite) TestSimpleGETItem() {
475475

476476
defer file.Close()
477477

478-
m1 := map[string]interface{}{"key": "param1", "value": "value1"}
479-
m2 := map[string]interface{}{"key": "param2", "value": "value2"}
480-
481-
var arrMaps []map[string]interface{}
482-
arrMaps = append(arrMaps, m1)
483-
arrMaps = append(arrMaps, m2)
484-
485478
pURL := URL{
486479
Raw: "https://test.com?a=3",
487480
Protocol: "https",
488481
Host: []string{"test", "com"},
489-
Query: arrMaps,
482+
Query: []*QueryParam{
483+
{Key: "param1", Value: "value1"},
484+
{Key: "param2", Value: "value2"},
485+
},
490486
}
491487

492488
headers := []*Header{}

url.go

+14-8
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,25 @@ import (
1010
// Raw contains the complete URL.
1111
type URL struct {
1212
version version
13-
Raw string `json:"raw"`
14-
Protocol string `json:"protocol,omitempty"`
15-
Host []string `json:"host,omitempty"`
16-
Path []string `json:"path,omitempty"`
17-
Port string `json:"port,omitempty"`
18-
Query interface{} `json:"query,omitempty"`
19-
Hash string `json:"hash,omitempty"`
20-
Variables []*Variable `json:"variable,omitempty" mapstructure:"variable"`
13+
Raw string `json:"raw"`
14+
Protocol string `json:"protocol,omitempty"`
15+
Host []string `json:"host,omitempty"`
16+
Path []string `json:"path,omitempty"`
17+
Port string `json:"port,omitempty"`
18+
Query []*QueryParam `json:"query,omitempty"`
19+
Hash string `json:"hash,omitempty"`
20+
Variables []*Variable `json:"variable,omitempty" mapstructure:"variable"`
2121
}
2222

2323
// mURL is used for marshalling/unmarshalling.
2424
type mURL URL
2525

26+
type QueryParam struct {
27+
Key string `json:"key"`
28+
Value string `json:"value"`
29+
Description *string `json:"description"`
30+
}
31+
2632
// String returns the raw version of the URL.
2733
func (u URL) String() string {
2834
return u.Raw

url_test.go

+14
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,20 @@ func TestURLUnmarshalJSON(t *testing.T) {
103103
},
104104
nil,
105105
},
106+
{
107+
"Successfully unmarshalling an URL with query as a struct",
108+
[]byte("{\"raw\":\"http://www.google.fr\",\"query\":[{\"key\":\"param1\",\"value\":\"an-awesome-value\"}]}"),
109+
URL{
110+
Raw: "http://www.google.fr",
111+
Query: []*QueryParam{
112+
{
113+
Key: "param1",
114+
Value: "an-awesome-value",
115+
},
116+
},
117+
},
118+
nil,
119+
},
106120
{
107121
"Failed to unmarshal an URL because of an unsupported type",
108122
[]byte("not-a-valid-url"),

0 commit comments

Comments
 (0)