Skip to content

Commit 99c7bf3

Browse files
authored
fix: do not generate stubMethodsContent if there are no methods (#889)
1 parent 4583189 commit 99c7bf3

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

generator/gapic-generator-typescript/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -438,18 +438,21 @@ export class {{ service.name }}Client {
438438
(this._protos as any).{{api.naming.protoPackage}}.{{ service.name }},
439439
this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>;
440440

441-
// Iterate over each of the methods that the service provides
442-
// and create an API call method for each.
443-
const {{ service.name.toCamelCase() }}StubMethods =
444-
[
441+
{%- set stubMethodsContent %}
445442
{%- set stubMethodsJoiner = joiner(', ') -%}
446443
{%- for method in service.method -%}
447444
{%- if not method.ignoreMapPagingMethod %}
448445
{{- stubMethodsJoiner() -}}
449446
'{{ method.name.toCamelCase(true) }}'
450447
{%- endif %}
451448
{%- endfor -%}
452-
];
449+
{% endset -%}
450+
{%- if stubMethodsContent | trim %}
451+
452+
// Iterate over each of the methods that the service provides
453+
// and create an API call method for each.
454+
const {{ service.name.toCamelCase() }}StubMethods =
455+
[{{ stubMethodsContent | safe }}];
453456
for (const methodName of {{ service.name.toCamelCase() }}StubMethods) {
454457
const callPromise = this.{{ service.name.toCamelCase() }}Stub.then(
455458
stub => (...args: Array<{}>) => {
@@ -495,6 +498,7 @@ export class {{ service.name }}Client {
495498

496499
this.innerApiCalls[methodName] = apiCall;
497500
}
501+
{%- endif -%}
498502
{%- if service.options and service.options.deprecated %}
499503
this.warn('DEP${{service.name}}', '{{service.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
500504
{%- endif %}

generator/gapic-generator-typescript/templates/esm/typescript_gapic/esm/src/$version/$service_client.ts.njk

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -449,18 +449,21 @@ export class {{ service.name }}Client {
449449
(this._protos as any).{{api.naming.protoPackage}}.{{ service.name }},
450450
this._opts, this._providedCustomServicePath) as Promise<{[method: string]: Function}>;
451451

452-
// Iterate over each of the methods that the service provides
453-
// and create an API call method for each.
454-
const {{ service.name.toCamelCase() }}StubMethods =
455-
[
452+
{%- set stubMethodsContent %}
456453
{%- set stubMethodsJoiner = joiner(', ') -%}
457454
{%- for method in service.method -%}
458455
{%- if not method.ignoreMapPagingMethod %}
459456
{{- stubMethodsJoiner() -}}
460457
'{{ method.name.toCamelCase(true) }}'
461458
{%- endif %}
462459
{%- endfor -%}
463-
];
460+
{% endset -%}
461+
{%- if stubMethodsContent | trim %}
462+
463+
// Iterate over each of the methods that the service provides
464+
// and create an API call method for each.
465+
const {{ service.name.toCamelCase() }}StubMethods =
466+
[{{ stubMethodsContent | safe }}];
464467
for (const methodName of {{ service.name.toCamelCase() }}StubMethods) {
465468
const callPromise = this.{{ service.name.toCamelCase() }}Stub.then(
466469
stub => (...args: Array<{}>) => {
@@ -506,6 +509,7 @@ export class {{ service.name }}Client {
506509

507510
this.innerApiCalls[methodName] = apiCall;
508511
}
512+
{%- endif -%}
509513
{%- if service.options and service.options.deprecated %}
510514
this.warn('DEP${{service.name}}', '{{service.name}} is deprecated and may be removed in a future version.', 'DeprecationWarning');
511515
{%- endif %}

0 commit comments

Comments
 (0)