Skip to content

Commit

Permalink
fix: array type template (twilio#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
shamigor authored Jun 4, 2021
1 parent 931d872 commit 3ed5c3a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
31 changes: 31 additions & 0 deletions examples/go/test/unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,34 @@ func TestQueryParams(t *testing.T) {
twilio := openapi.NewDefaultApiServiceWithClient(testClient)
twilio.ListCallRecording("CA1234", &params)
}

func TestArrayTypeParam(t *testing.T) {
callbackEvents := []string{"http://test1.com/", "http://test2.com"}
params := openapi.CreateCallRecordingParams{
RecordingStatusCallbackEvent: &callbackEvents,
}

expectedData := url.Values{}
for _, item := range callbackEvents {
expectedData.Add("RecordingStatusCallbackEvent", item)
}

mockCtrl := gomock.NewController(t)
testClient := NewMockBaseClient(mockCtrl)
testClient.EXPECT().AccountSid().DoAndReturn(func() string {
return accountSid
})
testClient.EXPECT().SendRequest(
gomock.Any(),
gomock.Any(),
gomock.Any(),
gomock.Any()).
DoAndReturn(func(method string, rawURL string, data url.Values,
headers map[string]interface{}) (*http.Response, error) {
assert.Equal(t, data, expectedData)
return &http.Response{Body: ioutil.NopCloser(bytes.NewReader(nil))}, nil
},
)
twilio := openapi.NewDefaultApiServiceWithClient(testClient)
twilio.CreateCallRecording("CA1234", &params)
}
9 changes: 8 additions & 1 deletion src/main/resources/twilio-go/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ func (c *{{{classname}}}Service) {{{nickname}}}({{#allParams}}{{#required}}{{par
data.Set("{{{baseName}}}", string(v))
{{/isFreeFormObject}}
{{^isFreeFormObject}}
data.Set("{{{baseName}}}", {{^isArray}}{{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}}){{/isArray}} {{#isArray}}strings.Join(*params.{{paramName}}, ",")){{/isArray}}
{{#isArray}}
for _, item := range *params.{{paramName}} {
data.Add("{{{baseName}}}", item)
}
{{/isArray}}
{{^isArray}}
data.Set("{{{baseName}}}", {{^isString}}fmt.Sprint({{/isString}}{{#isDateTime}}({{/isDateTime}}*params.{{paramName}}{{^isString}}{{#isDateTime}}).Format(time.RFC3339){{/isDateTime}}){{/isString}})
{{/isArray}}
{{/isFreeFormObject}}
}
{{/isHeaderParam}}
Expand Down

0 comments on commit 3ed5c3a

Please sign in to comment.