Skip to content

Commit d151fe3

Browse files
authored
Ignore empty string for optional args (#498)
* Ignore empty string for optional args * Remove auto-generated code diff * Add auto-generated codes
1 parent ea28484 commit d151fe3

File tree

3 files changed

+52
-20
lines changed

3 files changed

+52
-20
lines changed

generator/src/main/resources/line-bot-sdk-go-generator/api.pebble

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,10 +242,19 @@ func (client *{{ classname }}) {{ op.operationId }}WithHttpInfo(
242242
req.Header.Set("Content-Type", writer.FormDataContentType())
243243
{% elseif op.hasFormParams %}
244244
vs := url.Values{
245-
{% for fp in op.formParams -%}
246-
"{{ fp.baseName }}": []string{ string({{ fp.paramName }}) },
247-
{% endfor %}
248-
}
245+
{% for fp in op.formParams -%}
246+
{% if not fp.isString or fp.required -%}
247+
"{{ fp.baseName }}": []string{ string({{ fp.paramName }}) },
248+
{% endif -%}
249+
{% endfor %}
250+
}
251+
{% for fp in op.formParams -%}
252+
{% if fp.isString and not fp.required -%}
253+
if {{ fp.paramName }} != "" {
254+
vs["{{ fp.baseName }}"] = []string{ {{ fp.paramName }} }
255+
}
256+
{% endif -%}
257+
{% endfor -%}
249258
buf := vs.Encode()
250259
body := bytes.NewBufferString(buf)
251260

linebot/channel_access_token/api_channel_access_token.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,21 @@ func (client *ChannelAccessTokenAPI) IssueStatelessChannelTokenWithHttpInfo(
432432
) (*http.Response, *IssueStatelessChannelAccessTokenResponse, error) {
433433
path := "/oauth2/v3/token"
434434

435-
vs := url.Values{
436-
"grant_type": []string{string(grantType)},
437-
"client_assertion_type": []string{string(clientAssertionType)},
438-
"client_assertion": []string{string(clientAssertion)},
439-
"client_id": []string{string(clientId)},
440-
"client_secret": []string{string(clientSecret)},
435+
vs := url.Values{}
436+
if grantType != "" {
437+
vs["grant_type"] = []string{grantType}
438+
}
439+
if clientAssertionType != "" {
440+
vs["client_assertion_type"] = []string{clientAssertionType}
441+
}
442+
if clientAssertion != "" {
443+
vs["client_assertion"] = []string{clientAssertion}
444+
}
445+
if clientId != "" {
446+
vs["client_id"] = []string{clientId}
447+
}
448+
if clientSecret != "" {
449+
vs["client_secret"] = []string{clientSecret}
441450
}
442451
buf := vs.Encode()
443452
body := bytes.NewBufferString(buf)

linebot/module_attach/api_line_module_attach.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,30 @@ func (client *LineModuleAttachAPI) AttachModuleWithHttpInfo(
221221
path := "/module/auth/v1/token"
222222

223223
vs := url.Values{
224-
"grant_type": []string{string(grantType)},
225-
"code": []string{string(code)},
226-
"redirect_uri": []string{string(redirectUri)},
227-
"code_verifier": []string{string(codeVerifier)},
228-
"client_id": []string{string(clientId)},
229-
"client_secret": []string{string(clientSecret)},
230-
"region": []string{string(region)},
231-
"basic_search_id": []string{string(basicSearchId)},
232-
"scope": []string{string(scope)},
233-
"brand_type": []string{string(brandType)},
224+
"grant_type": []string{string(grantType)},
225+
"code": []string{string(code)},
226+
"redirect_uri": []string{string(redirectUri)},
227+
}
228+
if codeVerifier != "" {
229+
vs["code_verifier"] = []string{codeVerifier}
230+
}
231+
if clientId != "" {
232+
vs["client_id"] = []string{clientId}
233+
}
234+
if clientSecret != "" {
235+
vs["client_secret"] = []string{clientSecret}
236+
}
237+
if region != "" {
238+
vs["region"] = []string{region}
239+
}
240+
if basicSearchId != "" {
241+
vs["basic_search_id"] = []string{basicSearchId}
242+
}
243+
if scope != "" {
244+
vs["scope"] = []string{scope}
245+
}
246+
if brandType != "" {
247+
vs["brand_type"] = []string{brandType}
234248
}
235249
buf := vs.Encode()
236250
body := bytes.NewBufferString(buf)

0 commit comments

Comments
 (0)