Skip to content

Commit ef44b43

Browse files
authored
Add more inline comments (#1668)
This change adds more detailed comments, and example usage to make things easier for developers. The documentation coverage is now closer to that of line-bot-sdk-ruby. (some comments in pebble template are imported) The change seems big, but it's ok to review only `generator/src/main/resources/line-bot-sdk-nodejs-generator/*.pebble` (3 files)
1 parent 6d70c38 commit ef44b43

74 files changed

Lines changed: 2324 additions & 1412 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

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

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ import HTTPFetchClient, { convertResponseToReadable, mergeHeaders } from "../../
1818
// ===============================================
1919

2020
interface httpClientConfig {
21+
/**
22+
* Base URL for requests.
23+
* Defaults to '{{endpoint(operations.classname)}}'.
24+
* You can override this for testing or to use a mock server.
25+
*/
2126
baseURL?: string;
2227
{% if authMethods != null -%}
28+
/**
29+
* Channel access token used for authorization.
30+
*/
2331
channelAccessToken: string;
2432
{% endif -%}
33+
/**
34+
* Extra headers merged into every request.
35+
*/
2536
defaultHeaders?: Record<string, string>;
2637
}
2738

@@ -34,6 +45,23 @@ interface httpClientConfig {
3445
export class {{operations.classname}} {
3546
private httpClient: HTTPFetchClient;
3647

48+
/**
49+
* Initializes a new `{{operations.classname}}`.
50+
*
51+
* @param config Configuration for this API client.
52+
* @param config.baseURL The base URL for requests. Defaults to `{{endpoint(operations.classname)}}`.
53+
{% if authMethods != null -%}
54+
* @param config.channelAccessToken The channel access token used for authorization.
55+
{% endif -%}
56+
* @param config.defaultHeaders Extra headers merged into every request.
57+
*
58+
* @example
59+
* const client = new {{operations.classname}}({
60+
{% if authMethods != null -%}
61+
* channelAccessToken: process.env.LINE_CHANNEL_ACCESS_TOKEN!,
62+
{% endif -%}
63+
* });
64+
*/
3765
constructor(config: httpClientConfig) {
3866
const baseURL = config.baseURL || '{{endpoint(operations.classname)}}';
3967
const defaultHeaders = mergeHeaders(
@@ -53,45 +81,58 @@ export class {{operations.classname}} {
5381
{% for op in operations.operation -%}
5482
/**
5583
* {{op.notes}}
84+
* Calls `{{op.httpMethod}} {{endpoint(operations.classname)}}{{op.path}}`.
85+
* To inspect the HTTP status code or response headers, use {@link {{op.nickname}}WithHttpInfo}.
5686
{% if op.summary -%}
5787
* @summary {{op.summary}}
5888
{% endif -%}
5989
{% for param in op.allParams -%}
6090
* @param {{param.paramName}} {{param.description}}
6191
{% endfor -%}
92+
* @returns A promise resolving to the response body.
6293
{% if op.isDeprecated -%}
6394
* @deprecated
6495
{% endif -%}
6596
{% if op.operationId == "issueStatelessChannelToken" -%}
6697
* @deprecated Use {@link issueStatelessChannelTokenByJWTAssertion} or {@link issueStatelessChannelTokenByClientSecret} instead.
6798
{% endif -%}
6899
{% if op.externalDocs != null -%}
100+
{% if op.externalDocs.description != null -%}
69101
* {{op.externalDocs.description}}
70-
* @see <a href="{{op.externalDocs.url}}">{{op.summary}} Documentation</a>
102+
{% endif -%}
103+
{% if op.externalDocs.url != null -%}
104+
* @see <a href="{{op.externalDocs.url}}">LINE Developers documentation</a>
105+
{% endif -%}
71106
{% endif -%}
72107
*/
73108
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 %}> {
74109
return (await this.{{op.nickname}}WithHttpInfo({% for param in op.allParams %}{{param.paramName}}, {% endfor %})).body;
75110
}
76111

77112
/**
78-
* {{op.notes}}.
79-
* This method includes HttpInfo object to return additional information.
113+
* {{op.notes}}
114+
* Calls `{{op.httpMethod}} {{endpoint(operations.classname)}}{{op.path}}`.
115+
* This method returns the response body together with the underlying `httpResponse`.
80116
{% if op.summary -%}
81117
* @summary {{op.summary}}
82118
{% endif -%}
83119
{% for param in op.allParams -%}
84120
* @param {{param.paramName}} {{param.description}}
85121
{% endfor -%}
122+
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
86123
{% if op.isDeprecated -%}
87124
* @deprecated
88125
{% endif -%}
89126
{% if op.operationId == "issueStatelessChannelToken" -%}
90127
* @deprecated Use {@link issueStatelessChannelTokenByJWTAssertionWithHttpInfo} or {@link issueStatelessChannelTokenByClientSecretWithHttpInfo} instead.
91128
{% endif -%}
92129
{% if op.externalDocs != null -%}
130+
{% if op.externalDocs.description != null -%}
93131
* {{op.externalDocs.description}}
94-
* @see <a href="{{op.externalDocs.url}}">{{op.summary}} Documentation</a>
132+
{% endif -%}
133+
{% if op.externalDocs.url != null -%}
134+
* @see <a href="{{op.externalDocs.url}}">LINE Developers documentation</a>
135+
{% endif -%}
95136
{% endif -%}
96137
*/
97138
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 %}>> {

generator/src/main/resources/line-bot-sdk-nodejs-generator/body/api/ChannelAccessTokenClient.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
/**
22
* Issues a new stateless channel access token by JWT assertion.
33
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
4+
* Calls `POST https://api.line.me/oauth2/v3/token`.
5+
* To inspect the HTTP status code or response headers, use {@link issueStatelessChannelTokenByJWTAssertionWithHttpInfo}.
46
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
5-
* @returns A promise containing the {@link IssueStatelessChannelAccessTokenResponse}.
6-
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">Documentation</a>
7+
* @returns A promise resolving to the response body.
8+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
79
*/
810
public async issueStatelessChannelTokenByJWTAssertion(
911
clientAssertion: string,
@@ -18,10 +20,12 @@
1820
/**
1921
* Issues a new stateless channel access token by client secret.
2022
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
23+
* Calls `POST https://api.line.me/oauth2/v3/token`.
24+
* To inspect the HTTP status code or response headers, use {@link issueStatelessChannelTokenByClientSecretWithHttpInfo}.
2125
* @param clientId Channel ID.
2226
* @param clientSecret Channel secret.
23-
* @returns A promise containing the {@link IssueStatelessChannelAccessTokenResponse}.
24-
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">Documentation</a>
27+
* @returns A promise resolving to the response body.
28+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
2529
*/
2630
public async issueStatelessChannelTokenByClientSecret(
2731
clientId: string,
@@ -39,10 +43,11 @@
3943
/**
4044
* Issues a new stateless channel access token by JWT assertion.
4145
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
42-
* This method includes HttpInfo object to return additional information.
46+
* Calls `POST https://api.line.me/oauth2/v3/token`.
47+
* This method returns the response body together with the underlying `httpResponse`.
4348
* @param clientAssertion A JSON Web Token the client needs to create and sign with the private key of the Assertion Signing Key.
44-
* @returns A promise containing the {@link IssueStatelessChannelAccessTokenResponse} with HTTP info.
45-
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">Documentation</a>
49+
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
50+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
4651
*/
4752
public async issueStatelessChannelTokenByJWTAssertionWithHttpInfo(
4853
clientAssertion: string,
@@ -57,11 +62,12 @@
5762
/**
5863
* Issues a new stateless channel access token by client secret.
5964
* The newly issued token is only valid for 15 minutes but can not be revoked until it naturally expires.
60-
* This method includes HttpInfo object to return additional information.
65+
* Calls `POST https://api.line.me/oauth2/v3/token`.
66+
* This method returns the response body together with the underlying `httpResponse`.
6167
* @param clientId Channel ID.
6268
* @param clientSecret Channel secret.
63-
* @returns A promise containing the {@link IssueStatelessChannelAccessTokenResponse} with HTTP info.
64-
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">Documentation</a>
69+
* @returns A promise resolving to the response body together with the underlying `httpResponse`.
70+
* @see <a href="https://developers.line.biz/en/reference/messaging-api/#issue-stateless-channel-access-token">LINE Developers documentation</a>
6571
*/
6672
public async issueStatelessChannelTokenByClientSecretWithHttpInfo(
6773
clientId: string,

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@ export type {{classname}}{% if model.model.discriminator != null %}Base{% endif
4040
* {{ var.description }}
4141
{%- endif %}
4242
{%- if var.minimum != null %}
43-
* @minimum {{ var.minimum }}
43+
* Minimum: {{ var.minimum }}
4444
{%- endif %}
4545
{%- if var.maximum != null %}
46-
* @maximum {{ var.maximum }}
46+
* Maximum: {{ var.maximum }}
4747
{%- endif %}
4848
{%- if var.minLength != null %}
49-
* @minLength {{ var.minLength }}
49+
* Minimum length: {{ var.minLength }}
5050
{%- endif %}
5151
{%- if var.maxLength != null %}
52-
* @maxLength {{ var.maxLength }}
52+
* Maximum length: {{ var.maxLength }}
5353
{%- endif %}
5454
{%- if var.minItems != null %}
55-
* @minItems {{ var.minItems }}
55+
* Minimum items: {{ var.minItems }}
5656
{%- endif %}
5757
{%- if var.maxItems != null %}
58-
* @maxItems {{ var.maxItems }}
58+
* Maximum items: {{ var.maxItems }}
5959
{%- endif %}
6060
{%- if var.pattern != null %}
61-
* @pattern {{ var.pattern }}
61+
* Pattern: {{ var.pattern }}
6262
{%- endif %}
6363
{%- if var.defaultValue != null %}
64-
* @default {{ var.defaultValue }}
64+
* Default: {{ var.defaultValue }}
6565
{%- endif %}
6666
*/
6767
{%- endif %}

0 commit comments

Comments
 (0)