Skip to content

Commit 7acd9ee

Browse files
authored
Add WithHttpInfo method (#731)
This PR is based on #730
1 parent 0c7293e commit 7acd9ee

File tree

13 files changed

+1690
-363
lines changed

13 files changed

+1690
-363
lines changed

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,30 @@ 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];
77+
}
78+
79+
/**
80+
* {{op.notes}}.
81+
* This method includes HttpInfo object to return additional information.
82+
{% if op.summary -%}
83+
* @summary {{op.summary}}
84+
{% endif -%}
85+
{% for param in op.allParams -%}
86+
* @param {{param.paramName}} {{param.description}}
87+
{% endfor -%}
88+
{% if op.isDeprecated -%}
89+
* @deprecated
90+
{% endif -%}
91+
{% if op.externalDocs != null -%}
92+
* {{op.externalDocs.description}}
93+
* @see <a href="{{op.externalDocs.url}}">{{op.summary}} Documentation</a>
94+
{% endif -%}
95+
*/
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 %}]> {
7697
{% if op.isMultipart %}
7798
{% include "./apiBody/multipart.pebble" %}
78-
{% else %}
99+
{% else %}
79100
{% include "./apiBody/normal.pebble" %}
80101
{% endif %}
81102
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,4 @@
1414
{% endfor %},
1515
form,
1616
);
17-
const result = (await this.parseHTTPResponse(res)) as {% if op.returnType %}{{ op.returnType }}{% else %}Types.MessageAPIResponseBase{% endif %};
18-
return ensureJSON(result);
17+
return [res, await res.json()];

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

Lines changed: 2 additions & 3 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 convertResponseToReadable(response);
9+
return [response, convertResponseToReadable(response)];
1010
{% else %}
1111
{% if op.hasBodyParam %}const params = {{op.bodyParam.paramName}};
1212
{% elseif op.hasFormParams %}const formParams = {
@@ -43,6 +43,5 @@
4343
{% elseif op.hasQueryParams %}queryParams,{% endif %}
4444
{% if op.hasHeaderParams %}{headers: headerParams},{% endif %}
4545
);
46-
const result = (await this.parseHTTPResponse(res)) as {% if op.returnType %}{{ op.returnType }}{% else %}Types.MessageAPIResponseBase{% endif %};
47-
return ensureJSON(result);
46+
return [res, await res.json()];
4847
{% endif %}

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

Lines changed: 165 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,26 @@ export class ChannelAccessTokenClient {
7070
clientAssertionType: string,
7171
clientAssertion: string,
7272
): Promise<ChannelAccessTokenKeyIdsResponse> {
73+
return (
74+
await this.getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(
75+
clientAssertionType,
76+
clientAssertion,
77+
)
78+
)[1];
79+
}
80+
81+
/**
82+
* Gets all valid channel access token key IDs..
83+
* This method includes HttpInfo object to return additional information.
84+
* @param clientAssertionType `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
85+
* @param clientAssertion A JSON Web Token (JWT) (opens new window)the client needs to create and sign with the private key.
86+
*
87+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#get-all-valid-channel-access-token-key-ids-v2-1"> Documentation</a>
88+
*/
89+
public async getsAllValidChannelAccessTokenKeyIdsWithHttpInfo(
90+
clientAssertionType: string,
91+
clientAssertion: string,
92+
): Promise<[Response, ChannelAccessTokenKeyIdsResponse]> {
7393
const queryParams = {
7494
clientAssertionType: clientAssertionType,
7595
clientAssertion: clientAssertion,
@@ -79,10 +99,7 @@ export class ChannelAccessTokenClient {
7999
"/oauth2/v2.1/tokens/kid",
80100
queryParams,
81101
);
82-
const result = (await this.parseHTTPResponse(
83-
res,
84-
)) as ChannelAccessTokenKeyIdsResponse;
85-
return ensureJSON(result);
102+
return [res, await res.json()];
86103
}
87104
/**
88105
* Issue short-lived channel access token
@@ -97,6 +114,29 @@ export class ChannelAccessTokenClient {
97114
clientId?: string,
98115
clientSecret?: string,
99116
): Promise<IssueShortLivedChannelAccessTokenResponse> {
117+
return (
118+
await this.issueChannelTokenWithHttpInfo(
119+
grantType,
120+
clientId,
121+
clientSecret,
122+
)
123+
)[1];
124+
}
125+
126+
/**
127+
* Issue short-lived channel access token.
128+
* This method includes HttpInfo object to return additional information.
129+
* @param grantType `client_credentials`
130+
* @param clientId Channel ID.
131+
* @param clientSecret Channel secret.
132+
*
133+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-shortlived-channel-access-token"> Documentation</a>
134+
*/
135+
public async issueChannelTokenWithHttpInfo(
136+
grantType?: string,
137+
clientId?: string,
138+
clientSecret?: string,
139+
): Promise<[Response, IssueShortLivedChannelAccessTokenResponse]> {
100140
const formParams = {
101141
grant_type: grantType,
102142
client_id: clientId,
@@ -112,10 +152,7 @@ export class ChannelAccessTokenClient {
112152
"/v2/oauth/accessToken",
113153
formParams,
114154
);
115-
const result = (await this.parseHTTPResponse(
116-
res,
117-
)) as IssueShortLivedChannelAccessTokenResponse;
118-
return ensureJSON(result);
155+
return [res, await res.json()];
119156
}
120157
/**
121158
* Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication.
@@ -130,6 +167,29 @@ export class ChannelAccessTokenClient {
130167
clientAssertionType?: string,
131168
clientAssertion?: string,
132169
): Promise<IssueChannelAccessTokenResponse> {
170+
return (
171+
await this.issueChannelTokenByJWTWithHttpInfo(
172+
grantType,
173+
clientAssertionType,
174+
clientAssertion,
175+
)
176+
)[1];
177+
}
178+
179+
/**
180+
* Issues a channel access token that allows you to specify a desired expiration date. This method lets you use JWT assertion for authentication..
181+
* This method includes HttpInfo object to return additional information.
182+
* @param grantType client_credentials
183+
* @param clientAssertionType urn:ietf:params:oauth:client-assertion-type:jwt-bearer
184+
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
185+
*
186+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-channel-access-token-v2-1"> Documentation</a>
187+
*/
188+
public async issueChannelTokenByJWTWithHttpInfo(
189+
grantType?: string,
190+
clientAssertionType?: string,
191+
clientAssertion?: string,
192+
): Promise<[Response, IssueChannelAccessTokenResponse]> {
133193
const formParams = {
134194
grant_type: grantType,
135195
client_assertion_type: clientAssertionType,
@@ -145,10 +205,7 @@ export class ChannelAccessTokenClient {
145205
"/oauth2/v2.1/token",
146206
formParams,
147207
);
148-
const result = (await this.parseHTTPResponse(
149-
res,
150-
)) as IssueChannelAccessTokenResponse;
151-
return ensureJSON(result);
208+
return [res, await res.json()];
152209
}
153210
/**
154211
* 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.
@@ -167,6 +224,35 @@ export class ChannelAccessTokenClient {
167224
clientId?: string,
168225
clientSecret?: string,
169226
): Promise<IssueStatelessChannelAccessTokenResponse> {
227+
return (
228+
await this.issueStatelessChannelTokenWithHttpInfo(
229+
grantType,
230+
clientAssertionType,
231+
clientAssertion,
232+
clientId,
233+
clientSecret,
234+
)
235+
)[1];
236+
}
237+
238+
/**
239+
* 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. .
240+
* This method includes HttpInfo object to return additional information.
241+
* @param grantType `client_credentials`
242+
* @param clientAssertionType URL-encoded value of `urn:ietf:params:oauth:client-assertion-type:jwt-bearer`
243+
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
244+
* @param clientId Channel ID.
245+
* @param clientSecret Channel secret.
246+
*
247+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token"> Documentation</a>
248+
*/
249+
public async issueStatelessChannelTokenWithHttpInfo(
250+
grantType?: string,
251+
clientAssertionType?: string,
252+
clientAssertion?: string,
253+
clientId?: string,
254+
clientSecret?: string,
255+
): Promise<[Response, IssueStatelessChannelAccessTokenResponse]> {
170256
const formParams = {
171257
grant_type: grantType,
172258
client_assertion_type: clientAssertionType,
@@ -181,10 +267,7 @@ export class ChannelAccessTokenClient {
181267
});
182268

183269
const res = await this.httpClient.postForm("/oauth2/v3/token", formParams);
184-
const result = (await this.parseHTTPResponse(
185-
res,
186-
)) as IssueStatelessChannelAccessTokenResponse;
187-
return ensureJSON(result);
270+
return [res, await res.json()];
188271
}
189272
/**
190273
* Revoke short-lived or long-lived channel access token
@@ -195,6 +278,19 @@ export class ChannelAccessTokenClient {
195278
public async revokeChannelToken(
196279
accessToken?: string,
197280
): Promise<Types.MessageAPIResponseBase> {
281+
return (await this.revokeChannelTokenWithHttpInfo(accessToken))[1];
282+
}
283+
284+
/**
285+
* Revoke short-lived or long-lived channel access token.
286+
* This method includes HttpInfo object to return additional information.
287+
* @param accessToken Channel access token
288+
*
289+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-longlived-or-shortlived-channel-access-token"> Documentation</a>
290+
*/
291+
public async revokeChannelTokenWithHttpInfo(
292+
accessToken?: string,
293+
): Promise<[Response, Types.MessageAPIResponseBase]> {
198294
const formParams = {
199295
access_token: accessToken,
200296
};
@@ -205,10 +301,7 @@ export class ChannelAccessTokenClient {
205301
});
206302

207303
const res = await this.httpClient.postForm("/v2/oauth/revoke", formParams);
208-
const result = (await this.parseHTTPResponse(
209-
res,
210-
)) as Types.MessageAPIResponseBase;
211-
return ensureJSON(result);
304+
return [res, await res.json()];
212305
}
213306
/**
214307
* Revoke channel access token v2.1
@@ -223,6 +316,29 @@ export class ChannelAccessTokenClient {
223316
clientSecret?: string,
224317
accessToken?: string,
225318
): Promise<Types.MessageAPIResponseBase> {
319+
return (
320+
await this.revokeChannelTokenByJWTWithHttpInfo(
321+
clientId,
322+
clientSecret,
323+
accessToken,
324+
)
325+
)[1];
326+
}
327+
328+
/**
329+
* Revoke channel access token v2.1.
330+
* This method includes HttpInfo object to return additional information.
331+
* @param clientId Channel ID
332+
* @param clientSecret Channel Secret
333+
* @param accessToken Channel access token
334+
*
335+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#revoke-channel-access-token-v2-1"> Documentation</a>
336+
*/
337+
public async revokeChannelTokenByJWTWithHttpInfo(
338+
clientId?: string,
339+
clientSecret?: string,
340+
accessToken?: string,
341+
): Promise<[Response, Types.MessageAPIResponseBase]> {
226342
const formParams = {
227343
client_id: clientId,
228344
client_secret: clientSecret,
@@ -238,10 +354,7 @@ export class ChannelAccessTokenClient {
238354
"/oauth2/v2.1/revoke",
239355
formParams,
240356
);
241-
const result = (await this.parseHTTPResponse(
242-
res,
243-
)) as Types.MessageAPIResponseBase;
244-
return ensureJSON(result);
357+
return [res, await res.json()];
245358
}
246359
/**
247360
* Verify the validity of short-lived and long-lived channel access tokens
@@ -252,6 +365,19 @@ export class ChannelAccessTokenClient {
252365
public async verifyChannelToken(
253366
accessToken?: string,
254367
): Promise<VerifyChannelAccessTokenResponse> {
368+
return (await this.verifyChannelTokenWithHttpInfo(accessToken))[1];
369+
}
370+
371+
/**
372+
* Verify the validity of short-lived and long-lived channel access tokens.
373+
* This method includes HttpInfo object to return additional information.
374+
* @param accessToken A short-lived or long-lived channel access token.
375+
*
376+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verfiy-channel-access-token"> Documentation</a>
377+
*/
378+
public async verifyChannelTokenWithHttpInfo(
379+
accessToken?: string,
380+
): Promise<[Response, VerifyChannelAccessTokenResponse]> {
255381
const formParams = {
256382
access_token: accessToken,
257383
};
@@ -262,10 +388,7 @@ export class ChannelAccessTokenClient {
262388
});
263389

264390
const res = await this.httpClient.postForm("/v2/oauth/verify", formParams);
265-
const result = (await this.parseHTTPResponse(
266-
res,
267-
)) as VerifyChannelAccessTokenResponse;
268-
return ensureJSON(result);
391+
return [res, await res.json()];
269392
}
270393
/**
271394
* You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid.
@@ -276,14 +399,24 @@ export class ChannelAccessTokenClient {
276399
public async verifyChannelTokenByJWT(
277400
accessToken: string,
278401
): Promise<VerifyChannelAccessTokenResponse> {
402+
return (await this.verifyChannelTokenByJWTWithHttpInfo(accessToken))[1];
403+
}
404+
405+
/**
406+
* You can verify whether a Channel access token with a user-specified expiration (Channel Access Token v2.1) is valid..
407+
* This method includes HttpInfo object to return additional information.
408+
* @param accessToken Channel access token with a user-specified expiration (Channel Access Token v2.1).
409+
*
410+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#verfiy-channel-access-token-v2-1"> Documentation</a>
411+
*/
412+
public async verifyChannelTokenByJWTWithHttpInfo(
413+
accessToken: string,
414+
): Promise<[Response, VerifyChannelAccessTokenResponse]> {
279415
const queryParams = {
280416
accessToken: accessToken,
281417
};
282418

283419
const res = await this.httpClient.get("/oauth2/v2.1/verify", queryParams);
284-
const result = (await this.parseHTTPResponse(
285-
res,
286-
)) as VerifyChannelAccessTokenResponse;
287-
return ensureJSON(result);
420+
return [res, await res.json()];
288421
}
289422
}

0 commit comments

Comments
 (0)