diff --git a/baselines/pubsub-api-dump/api.json.baseline b/baselines/pubsub-api-dump/api.json.baseline index 5d1dfa408..a51902427 100644 --- a/baselines/pubsub-api-dump/api.json.baseline +++ b/baselines/pubsub-api-dump/api.json.baseline @@ -239,6 +239,7 @@ { "pagingFieldName": "topics", "pagingResponseType": ".google.pubsub.v1.Topic", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicsRequest", "outputInterface": ".google.pubsub.v1.ListTopicsResponse", "comments": [ @@ -295,6 +296,7 @@ { "pagingFieldName": "subscriptions", "pagingResponseType": ".google.protobuf.FieldDescriptorProto.Type.TYPE_STRING", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicSubscriptionsRequest", "outputInterface": ".google.pubsub.v1.ListTopicSubscriptionsResponse", "comments": [ @@ -351,6 +353,7 @@ { "pagingFieldName": "snapshots", "pagingResponseType": ".google.protobuf.FieldDescriptorProto.Type.TYPE_STRING", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicSnapshotsRequest", "outputInterface": ".google.pubsub.v1.ListTopicSnapshotsResponse", "comments": [ @@ -4099,6 +4102,7 @@ { "pagingFieldName": "topics", "pagingResponseType": ".google.pubsub.v1.Topic", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicsRequest", "outputInterface": ".google.pubsub.v1.ListTopicsResponse", "comments": [ @@ -4155,6 +4159,7 @@ { "pagingFieldName": "subscriptions", "pagingResponseType": ".google.protobuf.FieldDescriptorProto.Type.TYPE_STRING", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicSubscriptionsRequest", "outputInterface": ".google.pubsub.v1.ListTopicSubscriptionsResponse", "comments": [ @@ -4211,6 +4216,7 @@ { "pagingFieldName": "snapshots", "pagingResponseType": ".google.protobuf.FieldDescriptorProto.Type.TYPE_STRING", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListTopicSnapshotsRequest", "outputInterface": ".google.pubsub.v1.ListTopicSnapshotsResponse", "comments": [ @@ -4450,6 +4456,7 @@ { "pagingFieldName": "schemas", "pagingResponseType": ".google.pubsub.v1.Schema", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSchemasRequest", "outputInterface": ".google.pubsub.v1.ListSchemasResponse", "comments": [ @@ -8232,6 +8239,7 @@ { "pagingFieldName": "schemas", "pagingResponseType": ".google.pubsub.v1.Schema", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSchemasRequest", "outputInterface": ".google.pubsub.v1.ListSchemasResponse", "comments": [ @@ -8651,6 +8659,7 @@ { "pagingFieldName": "subscriptions", "pagingResponseType": ".google.pubsub.v1.Subscription", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSubscriptionsRequest", "outputInterface": ".google.pubsub.v1.ListSubscriptionsResponse", "comments": [ @@ -9164,6 +9173,7 @@ { "pagingFieldName": "snapshots", "pagingResponseType": ".google.pubsub.v1.Snapshot", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSnapshotsRequest", "outputInterface": ".google.pubsub.v1.ListSnapshotsResponse", "comments": [ @@ -13895,6 +13905,7 @@ { "pagingFieldName": "subscriptions", "pagingResponseType": ".google.pubsub.v1.Subscription", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSubscriptionsRequest", "outputInterface": ".google.pubsub.v1.ListSubscriptionsResponse", "comments": [ @@ -13951,6 +13962,7 @@ { "pagingFieldName": "snapshots", "pagingResponseType": ".google.pubsub.v1.Snapshot", + "ignoreMapPagingMethod": false, "inputInterface": ".google.pubsub.v1.ListSnapshotsRequest", "outputInterface": ".google.pubsub.v1.ListSnapshotsResponse", "comments": [ diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index cfbab5cc4..a8c780884 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -243,9 +243,11 @@ export class {{ service.name }}Client { this.descriptors.page = { {%- set pagingJoiner = joiner() %} {%- for method in service.paging %} + {%- if not method.ignoreMapPagingMethod %} {{- pagingJoiner() }} {{ method.name.toCamelCase() }}: new this._gaxModule.PageDescriptor('pageToken', 'nextPageToken', '{{ method.pagingFieldName.toCamelCase() }}') + {%- endif %} {%- endfor %} }; {%- endif %} @@ -383,8 +385,10 @@ export class {{ service.name }}Client { [ {%- set stubMethodsJoiner = joiner(', ') -%} {%- for method in service.method -%} + {%- if not method.ignoreMapPagingMethod %} {{- stubMethodsJoiner() -}} '{{ method.name.toCamelCase() }}' + {%- endif %} {%- endfor -%} ]; for (const methodName of {{ service.name.toCamelCase() }}StubMethods) { @@ -740,6 +744,7 @@ export class {{ service.name }}Client { } {%- endfor %} {%- for method in service.paging %} +{%- if not method.ignoreMapPagingMethod %} {%- if not method.pagingMapResponseType %} /** {{- util.printComments(method, service, id.get(method.name.toCamelCase() + "Async")) }} @@ -860,6 +865,7 @@ export class {{ service.name }}Client { ) as AsyncIterable<{{ util.toInterface(method.pagingResponseType) }}>; {%- endif %} } +{%- endif %} {%- endfor %} {%- if service.IAMPolicyMixin > 0 %} {{ iam.iamServiceMethods()}} diff --git a/templates/typescript_gapic/test/gapic_$service_$version.ts.njk b/templates/typescript_gapic/test/gapic_$service_$version.ts.njk index 8eb3c577a..f09962d13 100644 --- a/templates/typescript_gapic/test/gapic_$service_$version.ts.njk +++ b/templates/typescript_gapic/test/gapic_$service_$version.ts.njk @@ -651,7 +651,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { }); {%- endfor %} {%- for method in service.paging %} - +{% if not method.ignoreMapPagingMethod %} describe('{{ method.name.toCamelCase() }}', () => { {%- if not method.pagingMapResponseType %} it('invokes {{ method.name.toCamelCase() }} without error', async () => { @@ -888,6 +888,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => { {%- endif %} }); }); +{%- endif %} {%- endfor %} {%- if (service.IAMPolicyMixin) > 0 %} {%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %} diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index 14eef3133..e188d6c77 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -46,6 +46,7 @@ interface MethodDescriptorProto pagingFieldName: string | undefined; pagingResponseType?: string; pagingMapResponseType?: string; + ignoreMapPagingMethod?: boolean | undefined; inputInterface: string; outputInterface: string; comments: string[]; @@ -316,6 +317,28 @@ function pagingResponseType( return '.google.protobuf.FieldDescriptorProto.Type.' + type; } +// Ignore non-diregapic pagation method where its response type contains a map. +function ignoreMapPagingMethod( + messages: MessagesMap, + method: MethodDescriptorProto, + diregapic?: boolean +) { + const pagingfield = pagingField(messages, method, undefined, diregapic); + const outputType = messages[method.outputType!]; + if (!pagingfield?.type || !outputType.nestedType) { + return undefined; + } + if (diregapic) { + return false; + } + for (const desProto of outputType.nestedType) { + if (desProto.options && desProto.options.mapEntry) { + return true; + } + } + return false; +} + // Support DIREGAPIC google-discovery API pagination response with map field. function pagingMapResponseType( messages: MessagesMap, @@ -431,6 +454,11 @@ function augmentMethod( method, parameters.diregapic ), + ignoreMapPagingMethod: ignoreMapPagingMethod( + parameters.allMessages, + method, + parameters.diregapic + ), inputInterface: method.inputType!, outputInterface: method.outputType!, comments: parameters.service.commentsMap.getMethodComments(