Skip to content

Commit 2e59cad

Browse files
authored
Define api response type instead of array to access response and body easily (#733)
`[response, body]` -> `{httpResponse, body}`
1 parent 8abaf48 commit 2e59cad

File tree

14 files changed

+339
-327
lines changed

14 files changed

+339
-327
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export class {{operations.classname}} {
7373
{% endif -%}
7474
*/
7575
public async {{op.nickname}}({% for param in op.allParams %}{{param.paramName}}{% if not param.required %}?{% endif %}: {{param.dataType}}, {% endfor %}) : Promise<{% if op.returnType %}{{ op.returnType }}{% else %}Types.MessageAPIResponseBase{% endif %}> {
76-
return (await this.{{op.nickname}}WithHttpInfo({% for param in op.allParams %}{{param.paramName}}, {% endfor %}))[1];
76+
return (await this.{{op.nickname}}WithHttpInfo({% for param in op.allParams %}{{param.paramName}}, {% endfor %})).body;
7777
}
7878

7979
/**
@@ -93,7 +93,7 @@ export class {{operations.classname}} {
9393
* @see <a href="{{op.externalDocs.url}}">{{op.summary}} Documentation</a>
9494
{% endif -%}
9595
*/
96-
public async {{op.nickname}}WithHttpInfo({% for param in op.allParams %}{{param.paramName}}{% if not param.required %}?{% endif %}: {{param.dataType}}, {% endfor %}) : Promise<[Response, {% if op.returnType %}{{ op.returnType }}{% else %}Types.MessageAPIResponseBase{% endif %}]> {
96+
public async {{op.nickname}}WithHttpInfo({% for param in op.allParams %}{{param.paramName}}{% if not param.required %}?{% endif %}: {{param.dataType}}, {% endfor %}) : Promise<Types.ApiResponseType<{% if op.returnType %}{{ op.returnType }}{% else %}Types.MessageAPIResponseBase{% endif %}>> {
9797
{% if op.isMultipart %}
9898
{% include "./apiBody/multipart.pebble" %}
9999
{% else %}

generator/src/main/resources/line-bot-sdk-nodejs-generator/apiBody/multipart.pebble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@
1414
{% endfor %},
1515
form,
1616
);
17-
return [res, await res.json()];
17+
return {httpResponse: res, body: await res.json()};

generator/src/main/resources/line-bot-sdk-nodejs-generator/apiBody/normal.pebble

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
.replace('{' + "{{param.baseName}}" + '}', String({{param.paramName}}))
77
{% endfor %}
88
);
9-
return [response, convertResponseToReadable(response)];
9+
return {httpResponse: response, body: convertResponseToReadable(response)};
1010
{% else %}
1111
{% if op.hasBodyParam %}const params = {{op.bodyParam.paramName}};
1212
{% elseif op.hasFormParams %}const formParams = {
@@ -43,5 +43,5 @@
4343
{% elseif op.hasQueryParams %}queryParams,{% endif %}
4444
{% if op.hasHeaderParams %}{headers: headerParams},{% endif %}
4545
);
46-
return [res, await res.json()];
46+
return {httpResponse: res, body: await res.json()};
4747
{% endif %}

lib/channel-access-token/api/channelAccessTokenClient.ts

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export class ChannelAccessTokenClient {
7575
clientAssertionType,
7676
clientAssertion,
7777
)
78-
)[1];
78+
).body;
7979
}
8080

8181
/**
@@ -89,7 +89,7 @@ export class ChannelAccessTokenClient {
8989
public async getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(
9090
clientAssertionType: string,
9191
clientAssertion: string,
92-
): Promise<[Response, ChannelAccessTokenKeyIdsResponse]> {
92+
): Promise<Types.ApiResponseType<ChannelAccessTokenKeyIdsResponse>> {
9393
const queryParams = {
9494
clientAssertionType: clientAssertionType,
9595
clientAssertion: clientAssertion,
@@ -99,7 +99,7 @@ export class ChannelAccessTokenClient {
9999
"/oauth2/v2.1/tokens/kid",
100100
queryParams,
101101
);
102-
return [res, await res.json()];
102+
return { httpResponse: res, body: await res.json() };
103103
}
104104
/**
105105
* Issue short-lived channel access token
@@ -120,7 +120,7 @@ export class ChannelAccessTokenClient {
120120
clientId,
121121
clientSecret,
122122
)
123-
)[1];
123+
).body;
124124
}
125125

126126
/**
@@ -136,7 +136,7 @@ export class ChannelAccessTokenClient {
136136
grantType?: string,
137137
clientId?: string,
138138
clientSecret?: string,
139-
): Promise<[Response, IssueShortLivedChannelAccessTokenResponse]> {
139+
): Promise<Types.ApiResponseType<IssueShortLivedChannelAccessTokenResponse>> {
140140
const formParams = {
141141
grant_type: grantType,
142142
client_id: clientId,
@@ -152,7 +152,7 @@ export class ChannelAccessTokenClient {
152152
"/v2/oauth/accessToken",
153153
formParams,
154154
);
155-
return [res, await res.json()];
155+
return { httpResponse: res, body: await res.json() };
156156
}
157157
/**
158158
* Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
@@ -173,7 +173,7 @@ export class ChannelAccessTokenClient {
173173
clientAssertionType,
174174
clientAssertion,
175175
)
176-
)[1];
176+
).body;
177177
}
178178

179179
/**
@@ -189,7 +189,7 @@ export class ChannelAccessTokenClient {
189189
grantType?: string,
190190
clientAssertionType?: string,
191191
clientAssertion?: string,
192-
): Promise<[Response, IssueChannelAccessTokenResponse]> {
192+
): Promise<Types.ApiResponseType<IssueChannelAccessTokenResponse>> {
193193
const formParams = {
194194
grant_type: grantType,
195195
client_assertion_type: clientAssertionType,
@@ -205,7 +205,7 @@ export class ChannelAccessTokenClient {
205205
"/oauth2/v2.1/token",
206206
formParams,
207207
);
208-
return [res, await res.json()];
208+
return { httpResponse: res, body: await res.json() };
209209
}
210210
/**
211211
* Issues a new stateless channel access token, which doesn\'t have max active token limit unlike the other token types. The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
@@ -232,7 +232,7 @@ export class ChannelAccessTokenClient {
232232
clientId,
233233
clientSecret,
234234
)
235-
)[1];
235+
).body;
236236
}
237237

238238
/**
@@ -252,7 +252,7 @@ export class ChannelAccessTokenClient {
252252
clientAssertion?: string,
253253
clientId?: string,
254254
clientSecret?: string,
255-
): Promise<[Response, IssueStatelessChannelAccessTokenResponse]> {
255+
): Promise<Types.ApiResponseType<IssueStatelessChannelAccessTokenResponse>> {
256256
const formParams = {
257257
grant_type: grantType,
258258
client_assertion_type: clientAssertionType,
@@ -267,7 +267,7 @@ export class ChannelAccessTokenClient {
267267
});
268268

269269
const res = await this.httpClient.postForm("/oauth2/v3/token", formParams);
270-
return [res, await res.json()];
270+
return { httpResponse: res, body: await res.json() };
271271
}
272272
/**
273273
* Revoke short-lived or long-lived channel access token
@@ -278,7 +278,7 @@ export class ChannelAccessTokenClient {
278278
public async revokeChannelToken(
279279
accessToken?: string,
280280
): Promise<Types.MessageAPIResponseBase> {
281-
return (await this.revokeChannelTokenWithHttpInfo(accessToken))[1];
281+
return (await this.revokeChannelTokenWithHttpInfo(accessToken)).body;
282282
}
283283

284284
/**
@@ -290,7 +290,7 @@ export class ChannelAccessTokenClient {
290290
*/
291291
public async revokeChannelTokenWithHttpInfo(
292292
accessToken?: string,
293-
): Promise<[Response, Types.MessageAPIResponseBase]> {
293+
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
294294
const formParams = {
295295
access_token: accessToken,
296296
};
@@ -301,7 +301,7 @@ export class ChannelAccessTokenClient {
301301
});
302302

303303
const res = await this.httpClient.postForm("/v2/oauth/revoke", formParams);
304-
return [res, await res.json()];
304+
return { httpResponse: res, body: await res.json() };
305305
}
306306
/**
307307
* Revoke channel access token v2.1
@@ -322,7 +322,7 @@ export class ChannelAccessTokenClient {
322322
clientSecret,
323323
accessToken,
324324
)
325-
)[1];
325+
).body;
326326
}
327327

328328
/**
@@ -338,7 +338,7 @@ export class ChannelAccessTokenClient {
338338
clientId?: string,
339339
clientSecret?: string,
340340
accessToken?: string,
341-
): Promise<[Response, Types.MessageAPIResponseBase]> {
341+
): Promise<Types.ApiResponseType<Types.MessageAPIResponseBase>> {
342342
const formParams = {
343343
client_id: clientId,
344344
client_secret: clientSecret,
@@ -354,7 +354,7 @@ export class ChannelAccessTokenClient {
354354
"/oauth2/v2.1/revoke",
355355
formParams,
356356
);
357-
return [res, await res.json()];
357+
return { httpResponse: res, body: await res.json() };
358358
}
359359
/**
360360
* Verify the validity of short-lived and long-lived channel access tokens
@@ -365,7 +365,7 @@ export class ChannelAccessTokenClient {
365365
public async verifyChannelToken(
366366
accessToken?: string,
367367
): Promise<VerifyChannelAccessTokenResponse> {
368-
return (await this.verifyChannelTokenWithHttpInfo(accessToken))[1];
368+
return (await this.verifyChannelTokenWithHttpInfo(accessToken)).body;
369369
}
370370

371371
/**
@@ -377,7 +377,7 @@ export class ChannelAccessTokenClient {
377377
*/
378378
public async verifyChannelTokenWithHttpInfo(
379379
accessToken?: string,
380-
): Promise<[Response, VerifyChannelAccessTokenResponse]> {
380+
): Promise<Types.ApiResponseType<VerifyChannelAccessTokenResponse>> {
381381
const formParams = {
382382
access_token: accessToken,
383383
};
@@ -388,7 +388,7 @@ export class ChannelAccessTokenClient {
388388
});
389389

390390
const res = await this.httpClient.postForm("/v2/oauth/verify", formParams);
391-
return [res, await res.json()];
391+
return { httpResponse: res, body: await res.json() };
392392
}
393393
/**
394394
* You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
@@ -399,7 +399,7 @@ export class ChannelAccessTokenClient {
399399
public async verifyChannelTokenByJWT(
400400
accessToken: string,
401401
): Promise<VerifyChannelAccessTokenResponse> {
402-
return (await this.verifyChannelTokenByJWTWithHttpInfo(accessToken))[1];
402+
return (await this.verifyChannelTokenByJWTWithHttpInfo(accessToken)).body;
403403
}
404404

405405
/**
@@ -411,12 +411,12 @@ export class ChannelAccessTokenClient {
411411
*/
412412
public async verifyChannelTokenByJWTWithHttpInfo(
413413
accessToken: string,
414-
): Promise<[Response, VerifyChannelAccessTokenResponse]> {
414+
): Promise<Types.ApiResponseType<VerifyChannelAccessTokenResponse>> {
415415
const queryParams = {
416416
accessToken: accessToken,
417417
};
418418

419419
const res = await this.httpClient.get("/oauth2/v2.1/verify", queryParams);
420-
return [res, await res.json()];
420+
return { httpResponse: res, body: await res.json() };
421421
}
422422
}

lib/insight/api/insightClient.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class InsightClient {
6767
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-demographic"> Documentation</a>
6868
*/
6969
public async getFriendsDemographics(): Promise<GetFriendsDemographicsResponse> {
70-
return (await this.getFriendsDemographicsWithHttpInfo())[1];
70+
return (await this.getFriendsDemographicsWithHttpInfo()).body;
7171
}
7272

7373
/**
@@ -77,10 +77,10 @@ export class InsightClient {
7777
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-demographic"> Documentation</a>
7878
*/
7979
public async getFriendsDemographicsWithHttpInfo(): Promise<
80-
[Response, GetFriendsDemographicsResponse]
80+
Types.ApiResponseType<GetFriendsDemographicsResponse>
8181
> {
8282
const res = await this.httpClient.get("/v2/bot/insight/demographic");
83-
return [res, await res.json()];
83+
return { httpResponse: res, body: await res.json() };
8484
}
8585
/**
8686
* Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account.
@@ -92,7 +92,7 @@ export class InsightClient {
9292
public async getMessageEvent(
9393
requestId: string,
9494
): Promise<GetMessageEventResponse> {
95-
return (await this.getMessageEventWithHttpInfo(requestId))[1];
95+
return (await this.getMessageEventWithHttpInfo(requestId)).body;
9696
}
9797

9898
/**
@@ -105,7 +105,7 @@ export class InsightClient {
105105
*/
106106
public async getMessageEventWithHttpInfo(
107107
requestId: string,
108-
): Promise<[Response, GetMessageEventResponse]> {
108+
): Promise<Types.ApiResponseType<GetMessageEventResponse>> {
109109
const queryParams = {
110110
requestId: requestId,
111111
};
@@ -114,7 +114,7 @@ export class InsightClient {
114114
"/v2/bot/insight/message/event",
115115
queryParams,
116116
);
117-
return [res, await res.json()];
117+
return { httpResponse: res, body: await res.json() };
118118
}
119119
/**
120120
* Returns the number of users who have added the LINE Official Account on or before a specified date.
@@ -126,7 +126,7 @@ export class InsightClient {
126126
public async getNumberOfFollowers(
127127
date?: string,
128128
): Promise<GetNumberOfFollowersResponse> {
129-
return (await this.getNumberOfFollowersWithHttpInfo(date))[1];
129+
return (await this.getNumberOfFollowersWithHttpInfo(date)).body;
130130
}
131131

132132
/**
@@ -139,7 +139,7 @@ export class InsightClient {
139139
*/
140140
public async getNumberOfFollowersWithHttpInfo(
141141
date?: string,
142-
): Promise<[Response, GetNumberOfFollowersResponse]> {
142+
): Promise<Types.ApiResponseType<GetNumberOfFollowersResponse>> {
143143
const queryParams = {
144144
date: date,
145145
};
@@ -148,7 +148,7 @@ export class InsightClient {
148148
"/v2/bot/insight/followers",
149149
queryParams,
150150
);
151-
return [res, await res.json()];
151+
return { httpResponse: res, body: await res.json() };
152152
}
153153
/**
154154
* Returns the number of messages sent from LINE Official Account on a specified day.
@@ -160,7 +160,7 @@ export class InsightClient {
160160
public async getNumberOfMessageDeliveries(
161161
date: string,
162162
): Promise<GetNumberOfMessageDeliveriesResponse> {
163-
return (await this.getNumberOfMessageDeliveriesWithHttpInfo(date))[1];
163+
return (await this.getNumberOfMessageDeliveriesWithHttpInfo(date)).body;
164164
}
165165

166166
/**
@@ -173,7 +173,7 @@ export class InsightClient {
173173
*/
174174
public async getNumberOfMessageDeliveriesWithHttpInfo(
175175
date: string,
176-
): Promise<[Response, GetNumberOfMessageDeliveriesResponse]> {
176+
): Promise<Types.ApiResponseType<GetNumberOfMessageDeliveriesResponse>> {
177177
const queryParams = {
178178
date: date,
179179
};
@@ -182,7 +182,7 @@ export class InsightClient {
182182
"/v2/bot/insight/message/delivery",
183183
queryParams,
184184
);
185-
return [res, await res.json()];
185+
return { httpResponse: res, body: await res.json() };
186186
}
187187
/**
188188
* You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account.
@@ -203,7 +203,7 @@ export class InsightClient {
203203
from,
204204
to,
205205
)
206-
)[1];
206+
).body;
207207
}
208208

209209
/**
@@ -219,7 +219,7 @@ export class InsightClient {
219219
customAggregationUnit: string,
220220
from: string,
221221
to: string,
222-
): Promise<[Response, GetStatisticsPerUnitResponse]> {
222+
): Promise<Types.ApiResponseType<GetStatisticsPerUnitResponse>> {
223223
const queryParams = {
224224
customAggregationUnit: customAggregationUnit,
225225
from: from,
@@ -230,6 +230,6 @@ export class InsightClient {
230230
"/v2/bot/insight/message/event/aggregation",
231231
queryParams,
232232
);
233-
return [res, await res.json()];
233+
return { httpResponse: res, body: await res.json() };
234234
}
235235
}

0 commit comments

Comments
 (0)