Skip to content

Commit

Permalink
bugfix: int32 is converted to incorrect string (#416)
Browse files Browse the repository at this point in the history
* bugfix: int32 is incorrectly converted to string

* ignore stringify for string type

* generate go code

* add test case
  • Loading branch information
mekpavit authored Jan 22, 2024
1 parent e159509 commit 247a707
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ func With{{ classname contains "Blob" ? "Blob" : "" }}Endpoint(endpoint string)
{% macro stringify(param) -%}
{%- if param.isLong -%}
strconv.FormatInt({{ param.paramName }}, 10)
{%- elseif param.isInteger -%}
strconv.FormatInt(int64({{ param.paramName }}), 10)
{%- elseif param.isBoolean -%}
strconv.FormatBool({{ param.paramName }})
{%- elseif param.isString -%}
{{ param.paramName }}
{%- else -%}
string({{ param.paramName }})
{%- endif -%}
Expand Down Expand Up @@ -193,7 +197,7 @@ func (client *{{ classname }}) {{ op.operationId }}WithHttpInfo(
) (*http.Response, {% if op.isResponseFile %}*http.Response{% elseif op.returnType %}*{{ op.returnType }}{% else %}struct{}{% endif %}, error) {
path := "{{ op.path }}"
{% for pp in op.pathParams %}
path = strings.Replace(path, "{{ "{" }}{{ pp.paramName }}{{ "}" }}", {% if pp.isInteger or pp.isLong %}strconv.FormatInt({{ pp.paramName }}, 10){% else %}{{ pp.paramName }}{% endif %}, -1)
path = strings.Replace(path, "{{ "{" }}{{ pp.paramName }}{{ "}" }}", {{ stringify(pp) }}, -1)
{% endfor %}
{% if op.bodyParam != null and op.bodyParam.isFile %}
req, err := http.NewRequest(http.Method{{ op.httpMethod }}, client.Url(path), {{ op.bodyParam.paramName }}Reader)
Expand Down
6 changes: 3 additions & 3 deletions linebot/channel_access_token/api_channel_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ func (client *ChannelAccessTokenAPI) GetsAllValidChannelAccessTokenKeyIdsWithHtt
}

var query url.Values
query = url.Values{"clientAssertionType": []string{string(clientAssertionType)}}
query = url.Values{"clientAssertion": []string{string(clientAssertion)}}
query = url.Values{"clientAssertionType": []string{clientAssertionType}}
query = url.Values{"clientAssertion": []string{clientAssertion}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -742,7 +742,7 @@ func (client *ChannelAccessTokenAPI) VerifyChannelTokenByJWTWithHttpInfo(
}

var query url.Values
query = url.Values{"accessToken": []string{string(accessToken)}}
query = url.Values{"accessToken": []string{accessToken}}

req.URL.RawQuery = query.Encode()

Expand Down
12 changes: 6 additions & 6 deletions linebot/insight/api_insight.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ func (client *InsightAPI) GetMessageEventWithHttpInfo(
}

var query url.Values
query = url.Values{"requestId": []string{string(requestId)}}
query = url.Values{"requestId": []string{requestId}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -278,7 +278,7 @@ func (client *InsightAPI) GetNumberOfFollowersWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -349,7 +349,7 @@ func (client *InsightAPI) GetNumberOfMessageDeliveriesWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -436,9 +436,9 @@ func (client *InsightAPI) GetStatisticsPerUnitWithHttpInfo(
}

var query url.Values
query = url.Values{"customAggregationUnit": []string{string(customAggregationUnit)}}
query = url.Values{"from": []string{string(from)}}
query = url.Values{"to": []string{string(to)}}
query = url.Values{"customAggregationUnit": []string{customAggregationUnit}}
query = url.Values{"from": []string{from}}
query = url.Values{"to": []string{to}}

req.URL.RawQuery = query.Encode()

Expand Down
2 changes: 1 addition & 1 deletion linebot/manage_audience/api_manage_audience.go
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,7 @@ func (client *ManageAudienceAPI) GetAudienceGroupsWithHttpInfo(

var query url.Values
query = url.Values{"page": []string{strconv.FormatInt(page, 10)}}
query = url.Values{"description": []string{string(description)}}
query = url.Values{"description": []string{description}}
query = url.Values{"status": []string{string(status)}}
query = url.Values{"size": []string{strconv.FormatInt(size, 10)}}
query = url.Values{"includesExternalPublicGroups": []string{strconv.FormatBool(includesExternalPublicGroups)}}
Expand Down
6 changes: 3 additions & 3 deletions linebot/manage_audience/api_manage_audience_blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func (client *ManageAudienceBlobAPI) AddUserIdsToAudienceWithHttpInfo(

writer.WriteField("audienceGroupId", strconv.FormatInt(audienceGroupId, 10))

writer.WriteField("uploadDescription", string(uploadDescription))
writer.WriteField("uploadDescription", uploadDescription)

fileWriter, err := writer.CreateFormFile("file", file.Name())
if err != nil {
Expand Down Expand Up @@ -274,11 +274,11 @@ func (client *ManageAudienceBlobAPI) CreateAudienceForUploadingUserIdsWithHttpIn
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)

writer.WriteField("description", string(description))
writer.WriteField("description", description)

writer.WriteField("isIfaAudience", strconv.FormatBool(isIfaAudience))

writer.WriteField("uploadDescription", string(uploadDescription))
writer.WriteField("uploadDescription", uploadDescription)

fileWriter, err := writer.CreateFormFile("file", file.Name())
if err != nil {
Expand Down
39 changes: 20 additions & 19 deletions linebot/messaging_api/api_messaging_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"

"github.com/line/line-bot-sdk-go/v8/linebot"
Expand Down Expand Up @@ -235,7 +236,7 @@ func (client *MessagingApiAPI) BroadcastWithHttpInfo(
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")

req.Header.Set("X-Line-Retry-Key", string(xLineRetryKey))
req.Header.Set("X-Line-Retry-Key", xLineRetryKey)

res, err := client.Do(req)

Expand Down Expand Up @@ -617,7 +618,7 @@ func (client *MessagingApiAPI) GetAdPhoneMessageStatisticsWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -696,8 +697,8 @@ func (client *MessagingApiAPI) GetAggregationUnitNameListWithHttpInfo(
}

var query url.Values
query = url.Values{"limit": []string{string(limit)}}
query = url.Values{"start": []string{string(start)}}
query = url.Values{"limit": []string{limit}}
query = url.Values{"start": []string{start}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -935,8 +936,8 @@ func (client *MessagingApiAPI) GetFollowersWithHttpInfo(
}

var query url.Values
query = url.Values{"start": []string{string(start)}}
query = url.Values{"limit": []string{string(limit)}}
query = url.Values{"start": []string{start}}
query = url.Values{"limit": []string{strconv.FormatInt(int64(limit), 10)}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1163,7 +1164,7 @@ func (client *MessagingApiAPI) GetGroupMembersIdsWithHttpInfo(
}

var query url.Values
query = url.Values{"start": []string{string(start)}}
query = url.Values{"start": []string{start}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1408,7 +1409,7 @@ func (client *MessagingApiAPI) GetNarrowcastProgressWithHttpInfo(
}

var query url.Values
query = url.Values{"requestId": []string{string(requestId)}}
query = url.Values{"requestId": []string{requestId}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1479,7 +1480,7 @@ func (client *MessagingApiAPI) GetNumberOfSentBroadcastMessagesWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1550,7 +1551,7 @@ func (client *MessagingApiAPI) GetNumberOfSentMulticastMessagesWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1621,7 +1622,7 @@ func (client *MessagingApiAPI) GetNumberOfSentPushMessagesWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1692,7 +1693,7 @@ func (client *MessagingApiAPI) GetNumberOfSentReplyMessagesWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -1763,7 +1764,7 @@ func (client *MessagingApiAPI) GetPNPMessageStatisticsWithHttpInfo(
}

var query url.Values
query = url.Values{"date": []string{string(date)}}
query = url.Values{"date": []string{date}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -2091,7 +2092,7 @@ func (client *MessagingApiAPI) GetRichMenuBatchProgressWithHttpInfo(
}

var query url.Values
query = url.Values{"requestId": []string{string(requestId)}}
query = url.Values{"requestId": []string{requestId}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -2439,7 +2440,7 @@ func (client *MessagingApiAPI) GetRoomMembersIdsWithHttpInfo(
}

var query url.Values
query = url.Values{"start": []string{string(start)}}
query = url.Values{"start": []string{start}}

req.URL.RawQuery = query.Encode()

Expand Down Expand Up @@ -2977,7 +2978,7 @@ func (client *MessagingApiAPI) MulticastWithHttpInfo(
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")

req.Header.Set("X-Line-Retry-Key", string(xLineRetryKey))
req.Header.Set("X-Line-Retry-Key", xLineRetryKey)

res, err := client.Do(req)

Expand Down Expand Up @@ -3059,7 +3060,7 @@ func (client *MessagingApiAPI) NarrowcastWithHttpInfo(
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")

req.Header.Set("X-Line-Retry-Key", string(xLineRetryKey))
req.Header.Set("X-Line-Retry-Key", xLineRetryKey)

res, err := client.Do(req)

Expand Down Expand Up @@ -3141,7 +3142,7 @@ func (client *MessagingApiAPI) PushMessageWithHttpInfo(
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")

req.Header.Set("X-Line-Retry-Key", string(xLineRetryKey))
req.Header.Set("X-Line-Retry-Key", xLineRetryKey)

res, err := client.Do(req)

Expand Down Expand Up @@ -3223,7 +3224,7 @@ func (client *MessagingApiAPI) PushMessagesByPhoneWithHttpInfo(
}
req.Header.Set("Content-Type", "application/json; charset=UTF-8")

req.Header.Set("X-Line-Delivery-Tag", string(xLineDeliveryTag))
req.Header.Set("X-Line-Delivery-Tag", xLineDeliveryTag)

res, err := client.Do(req)

Expand Down
42 changes: 42 additions & 0 deletions linebot/messaging_api/tests/handwritten/api_GetFollowers_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package tests

import (
"encoding/json"
"fmt"
"log"
"net/http"
"net/http/httptest"
"testing"

"github.com/line/line-bot-sdk-go/v8/linebot/messaging_api"
)

func TestGetFollowers_ItShouldCorrectlyPassLimitQueryParameter(t *testing.T) {
expectedLimit := "1000"
server := httptest.NewServer(
http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gotLimit := r.URL.Query().Get("limit")
if gotLimit != expectedLimit {
w.Header().Set("TEST-ERROR", fmt.Sprintf("incorrect limit being sent from client. expected %s, got %s", expectedLimit, gotLimit))
w.WriteHeader(http.StatusInternalServerError)
return
}
json.NewEncoder(w).Encode(messaging_api.GetFollowersResponse{UserIds: []string{}, Next: "abcdef"})
}),
)
client, err := messaging_api.NewMessagingApiAPI(
"channelToken",
messaging_api.WithEndpoint(server.URL),
)
if err != nil {
t.Fatalf("Failed to create client: %v", err)
}
resp, _, err := client.GetFollowersWithHttpInfo("", 1000)
if err != nil {
t.Fatalf("Failed to get followers: %v", err)
}
log.Printf("Got response: %v", resp)
if resp.StatusCode != http.StatusOK {
t.Errorf("Not getting 200 response back: %s", resp.Header.Get("TEST-ERROR"))
}
}
5 changes: 3 additions & 2 deletions linebot/module/api_line_module.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"net/http"
"net/url"
"path"
"strconv"
"strings"

"github.com/line/line-bot-sdk-go/v8/linebot"
Expand Down Expand Up @@ -307,8 +308,8 @@ func (client *LineModuleAPI) GetModulesWithHttpInfo(
}

var query url.Values
query = url.Values{"start": []string{string(start)}}
query = url.Values{"limit": []string{string(limit)}}
query = url.Values{"start": []string{start}}
query = url.Values{"limit": []string{strconv.FormatInt(int64(limit), 10)}}

req.URL.RawQuery = query.Encode()

Expand Down

0 comments on commit 247a707

Please sign in to comment.