Skip to content

Commit

Permalink
Ignore empty string for optional args (#498)
Browse files Browse the repository at this point in the history
* Ignore empty string for optional args

* Remove auto-generated code diff

* Add auto-generated codes
  • Loading branch information
habara-k authored Oct 31, 2024
1 parent ea28484 commit d151fe3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 20 deletions.
17 changes: 13 additions & 4 deletions generator/src/main/resources/line-bot-sdk-go-generator/api.pebble
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,19 @@ func (client *{{ classname }}) {{ op.operationId }}WithHttpInfo(
req.Header.Set("Content-Type", writer.FormDataContentType())
{% elseif op.hasFormParams %}
vs := url.Values{
{% for fp in op.formParams -%}
"{{ fp.baseName }}": []string{ string({{ fp.paramName }}) },
{% endfor %}
}
{% for fp in op.formParams -%}
{% if not fp.isString or fp.required -%}
"{{ fp.baseName }}": []string{ string({{ fp.paramName }}) },
{% endif -%}
{% endfor %}
}
{% for fp in op.formParams -%}
{% if fp.isString and not fp.required -%}
if {{ fp.paramName }} != "" {
vs["{{ fp.baseName }}"] = []string{ {{ fp.paramName }} }
}
{% endif -%}
{% endfor -%}
buf := vs.Encode()
body := bytes.NewBufferString(buf)

Expand Down
21 changes: 15 additions & 6 deletions linebot/channel_access_token/api_channel_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,21 @@ func (client *ChannelAccessTokenAPI) IssueStatelessChannelTokenWithHttpInfo(
) (*http.Response, *IssueStatelessChannelAccessTokenResponse, error) {
path := "/oauth2/v3/token"

vs := url.Values{
"grant_type": []string{string(grantType)},
"client_assertion_type": []string{string(clientAssertionType)},
"client_assertion": []string{string(clientAssertion)},
"client_id": []string{string(clientId)},
"client_secret": []string{string(clientSecret)},
vs := url.Values{}
if grantType != "" {
vs["grant_type"] = []string{grantType}
}
if clientAssertionType != "" {
vs["client_assertion_type"] = []string{clientAssertionType}
}
if clientAssertion != "" {
vs["client_assertion"] = []string{clientAssertion}
}
if clientId != "" {
vs["client_id"] = []string{clientId}
}
if clientSecret != "" {
vs["client_secret"] = []string{clientSecret}
}
buf := vs.Encode()
body := bytes.NewBufferString(buf)
Expand Down
34 changes: 24 additions & 10 deletions linebot/module_attach/api_line_module_attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,30 @@ func (client *LineModuleAttachAPI) AttachModuleWithHttpInfo(
path := "/module/auth/v1/token"

vs := url.Values{
"grant_type": []string{string(grantType)},
"code": []string{string(code)},
"redirect_uri": []string{string(redirectUri)},
"code_verifier": []string{string(codeVerifier)},
"client_id": []string{string(clientId)},
"client_secret": []string{string(clientSecret)},
"region": []string{string(region)},
"basic_search_id": []string{string(basicSearchId)},
"scope": []string{string(scope)},
"brand_type": []string{string(brandType)},
"grant_type": []string{string(grantType)},
"code": []string{string(code)},
"redirect_uri": []string{string(redirectUri)},
}
if codeVerifier != "" {
vs["code_verifier"] = []string{codeVerifier}
}
if clientId != "" {
vs["client_id"] = []string{clientId}
}
if clientSecret != "" {
vs["client_secret"] = []string{clientSecret}
}
if region != "" {
vs["region"] = []string{region}
}
if basicSearchId != "" {
vs["basic_search_id"] = []string{basicSearchId}
}
if scope != "" {
vs["scope"] = []string{scope}
}
if brandType != "" {
vs["brand_type"] = []string{brandType}
}
buf := vs.Encode()
body := bytes.NewBufferString(buf)
Expand Down

0 comments on commit d151fe3

Please sign in to comment.