From 456fed05fc90b2803f161f19d774ab8d1eb68ecd Mon Sep 17 00:00:00 2001 From: Alexander Fenster Date: Thu, 6 Feb 2020 15:45:08 -0800 Subject: [PATCH] fix: pass x-goog-request-params to streaming methods (#234) * fix: pass x-goog-request-params to streaming methods --- .../src/$version/$service_client.ts.njk | 20 ++++---- .../dlp/src/v2/dlp_service_client.ts.baseline | 50 +++++++++++++++++-- .../key_management_service_client.ts.baseline | 40 +++++++++++++-- ...vice_monitoring_service_client.ts.baseline | 20 +++++++- .../uptime_check_service_client.ts.baseline | 13 ++++- .../v1beta1/cloud_redis_client.ts.baseline | 10 +++- .../src/v1beta1/echo_client.ts.baseline | 16 +++--- .../translation_service_client.ts.baseline | 10 +++- 8 files changed, 148 insertions(+), 31 deletions(-) diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 339909650..e6a79e66b 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -384,7 +384,7 @@ export class {{ service.name }}Client { {{ method.name.toCamelCase() }}( options?: gax.CallOptions): gax.CancellableStream{ - options = options || {}; + {{ util.buildHeaderRequestParam(method) }} return this._innerApiCalls.{{ method.name.toCamelCase() }}(options); } {%- elif method.serverStreaming %} @@ -396,18 +396,18 @@ export class {{ service.name }}Client { options?: gax.CallOptions): gax.CancellableStream{ request = request || {}; - options = options || {}; + {{ util.buildHeaderRequestParam(method) }} return this._innerApiCalls.{{ method.name.toCamelCase() }}(request, options); } {%- elif method.clientStreaming %} {{ method.name.toCamelCase() }}( - options: gax.CallOptions, - callback: Callback< + options?: gax.CallOptions, + callback?: Callback< {{ util.toInterface(method.outputInterface) }}, {{ util.toInterface(method.inputInterface) }}|undefined, {}|undefined>): gax.CancellableStream; {{ method.name.toCamelCase() }}( - callback: Callback< + callback?: Callback< {{ util.toInterface(method.outputInterface) }}, {{ util.toInterface(method.inputInterface) }}|undefined, {}|undefined>): gax.CancellableStream; @@ -415,7 +415,7 @@ export class {{ service.name }}Client { {{- util.printComments(method, service) }} */ {{ method.name.toCamelCase() }}( - optionsOrCallback: gax.CallOptions|Callback< + optionsOrCallback?: gax.CallOptions|Callback< {{ util.toInterface(method.outputInterface) }}, {{ util.toInterface(method.inputInterface) }}|undefined, {}|undefined>, callback?: Callback< @@ -426,8 +426,9 @@ export class {{ service.name }}Client { callback = optionsOrCallback; optionsOrCallback = {}; } - optionsOrCallback = optionsOrCallback || {}; - return this._innerApiCalls.{{ method.name.toCamelCase() }}(null, optionsOrCallback, callback); + let options = optionsOrCallback as gax.CallOptions; + {{ util.buildHeaderRequestParam(method) }} + return this._innerApiCalls.{{ method.name.toCamelCase() }}(null, options, callback); } {%- endif %} {% endfor %} @@ -527,9 +528,10 @@ export class {{ service.name }}Client { */ {{ method.name.toCamelCase() }}Stream( request?: {{ util.toInterface(method.inputInterface) }}, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + {{ util.buildHeaderRequestParam(method) }} const callSettings = new gax.CallSettings(options); return this._descriptors.page.{{ method.name.toCamelCase() }}.createStream( this._innerApiCalls.{{ method.name.toCamelCase() }} as gax.GaxCall, diff --git a/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline b/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline index d61345e0b..4590b416b 100644 --- a/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline +++ b/typescript/test/testdata/dlp/src/v2/dlp_service_client.ts.baseline @@ -2225,9 +2225,17 @@ export class DlpServiceClient { */ listInspectTemplatesStream( request?: protosTypes.google.privacy.dlp.v2.IListInspectTemplatesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listInspectTemplates.createStream( this._innerApiCalls.listInspectTemplates as gax.GaxCall, @@ -2384,9 +2392,17 @@ export class DlpServiceClient { */ listDeidentifyTemplatesStream( request?: protosTypes.google.privacy.dlp.v2.IListDeidentifyTemplatesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listDeidentifyTemplates.createStream( this._innerApiCalls.listDeidentifyTemplates as gax.GaxCall, @@ -2594,9 +2610,17 @@ export class DlpServiceClient { */ listJobTriggersStream( request?: protosTypes.google.privacy.dlp.v2.IListJobTriggersRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listJobTriggers.createStream( this._innerApiCalls.listJobTriggers as gax.GaxCall, @@ -2809,9 +2833,17 @@ export class DlpServiceClient { */ listDlpJobsStream( request?: protosTypes.google.privacy.dlp.v2.IListDlpJobsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listDlpJobs.createStream( this._innerApiCalls.listDlpJobs as gax.GaxCall, @@ -2970,9 +3002,17 @@ export class DlpServiceClient { */ listStoredInfoTypesStream( request?: protosTypes.google.privacy.dlp.v2.IListStoredInfoTypesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listStoredInfoTypes.createStream( this._innerApiCalls.listStoredInfoTypes as gax.GaxCall, diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index 27b8be055..6bbcc4f2c 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -1655,9 +1655,17 @@ export class KeyManagementServiceClient { */ listKeyRingsStream( request?: protosTypes.google.cloud.kms.v1.IListKeyRingsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listKeyRings.createStream( this._innerApiCalls.listKeyRings as gax.GaxCall, @@ -1796,9 +1804,17 @@ export class KeyManagementServiceClient { */ listCryptoKeysStream( request?: protosTypes.google.cloud.kms.v1.IListCryptoKeysRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listCryptoKeys.createStream( this._innerApiCalls.listCryptoKeys as gax.GaxCall, @@ -1939,9 +1955,17 @@ export class KeyManagementServiceClient { */ listCryptoKeyVersionsStream( request?: protosTypes.google.cloud.kms.v1.IListCryptoKeyVersionsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listCryptoKeyVersions.createStream( this._innerApiCalls.listCryptoKeyVersions as gax.GaxCall, @@ -2076,9 +2100,17 @@ export class KeyManagementServiceClient { */ listImportJobsStream( request?: protosTypes.google.cloud.kms.v1.IListImportJobsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listImportJobs.createStream( this._innerApiCalls.listImportJobs as gax.GaxCall, diff --git a/typescript/test/testdata/monitoring/src/v3/service_monitoring_service_client.ts.baseline b/typescript/test/testdata/monitoring/src/v3/service_monitoring_service_client.ts.baseline index 79b7e19e8..203119e41 100644 --- a/typescript/test/testdata/monitoring/src/v3/service_monitoring_service_client.ts.baseline +++ b/typescript/test/testdata/monitoring/src/v3/service_monitoring_service_client.ts.baseline @@ -932,9 +932,17 @@ export class ServiceMonitoringServiceClient { */ listServicesStream( request?: protosTypes.google.monitoring.v3.IListServicesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listServices.createStream( this._innerApiCalls.listServices as gax.GaxCall, @@ -1071,9 +1079,17 @@ export class ServiceMonitoringServiceClient { */ listServiceLevelObjectivesStream( request?: protosTypes.google.monitoring.v3.IListServiceLevelObjectivesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listServiceLevelObjectives.createStream( this._innerApiCalls.listServiceLevelObjectives as gax.GaxCall, diff --git a/typescript/test/testdata/monitoring/src/v3/uptime_check_service_client.ts.baseline b/typescript/test/testdata/monitoring/src/v3/uptime_check_service_client.ts.baseline index 62847a240..ce46659fd 100644 --- a/typescript/test/testdata/monitoring/src/v3/uptime_check_service_client.ts.baseline +++ b/typescript/test/testdata/monitoring/src/v3/uptime_check_service_client.ts.baseline @@ -666,9 +666,17 @@ export class UptimeCheckServiceClient { */ listUptimeCheckConfigsStream( request?: protosTypes.google.monitoring.v3.IListUptimeCheckConfigsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listUptimeCheckConfigs.createStream( this._innerApiCalls.listUptimeCheckConfigs as gax.GaxCall, @@ -786,9 +794,10 @@ export class UptimeCheckServiceClient { */ listUptimeCheckIpsStream( request?: protosTypes.google.monitoring.v3.IListUptimeCheckIpsRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; const callSettings = new gax.CallSettings(options); return this._descriptors.page.listUptimeCheckIps.createStream( this._innerApiCalls.listUptimeCheckIps as gax.GaxCall, diff --git a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline index 10e432ad2..70629d638 100644 --- a/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline +++ b/typescript/test/testdata/redis/src/v1beta1/cloud_redis_client.ts.baseline @@ -945,9 +945,17 @@ export class CloudRedisClient { */ listInstancesStream( request?: protosTypes.google.cloud.redis.v1beta1.IListInstancesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listInstances.createStream( this._innerApiCalls.listInstances as gax.GaxCall, diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index ffb557af3..c3e63187c 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -350,13 +350,13 @@ export class EchoClient { } collect( - options: gax.CallOptions, - callback: Callback< + options?: gax.CallOptions, + callback?: Callback< protosTypes.google.showcase.v1beta1.IEchoResponse, protosTypes.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>): gax.CancellableStream; collect( - callback: Callback< + callback?: Callback< protosTypes.google.showcase.v1beta1.IEchoResponse, protosTypes.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>): gax.CancellableStream; @@ -371,7 +371,7 @@ export class EchoClient { * [EchoRequest]{@link google.showcase.v1beta1.EchoRequest}. */ collect( - optionsOrCallback: gax.CallOptions|Callback< + optionsOrCallback?: gax.CallOptions|Callback< protosTypes.google.showcase.v1beta1.IEchoResponse, protosTypes.google.showcase.v1beta1.IEchoRequest|undefined, {}|undefined>, callback?: Callback< @@ -382,8 +382,9 @@ export class EchoClient { callback = optionsOrCallback; optionsOrCallback = {}; } - optionsOrCallback = optionsOrCallback || {}; - return this._innerApiCalls.collect(null, optionsOrCallback, callback); + let options = optionsOrCallback as gax.CallOptions; + options = options || {}; + return this._innerApiCalls.collect(null, options, callback); } /** @@ -566,9 +567,10 @@ export class EchoClient { */ pagedExpandStream( request?: protosTypes.google.showcase.v1beta1.IPagedExpandRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; const callSettings = new gax.CallSettings(options); return this._descriptors.page.pagedExpand.createStream( this._innerApiCalls.pagedExpand as gax.GaxCall, diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index b12ae89fc..57328a1e8 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -1018,9 +1018,17 @@ export class TranslationServiceClient { */ listGlossariesStream( request?: protosTypes.google.cloud.translation.v3beta1.IListGlossariesRequest, - options?: gax.CallOptions | {}): + options?: gax.CallOptions): Transform{ request = request || {}; + options = options || {}; + options.otherArgs = options.otherArgs || {}; + options.otherArgs.headers = options.otherArgs.headers || {}; + options.otherArgs.headers[ + 'x-goog-request-params' + ] = gax.routingHeader.fromParams({ + 'parent': request.parent || '', + }); const callSettings = new gax.CallSettings(options); return this._descriptors.page.listGlossaries.createStream( this._innerApiCalls.listGlossaries as gax.GaxCall,