Skip to content

Commit

Permalink
fix: ignore generating non-diregapic pagination with map response (#1076
Browse files Browse the repository at this point in the history
)

* fix: ignore generating non-diregapic pagination with map response

* clean debug log

* rename the method

* remove extra line
  • Loading branch information
summer-ji-eng authored Jan 4, 2022
1 parent 767d763 commit b7dc09f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 1 deletion.
12 changes: 12 additions & 0 deletions baselines/pubsub-api-dump/api.json.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@
{
"pagingFieldName": "topics",
"pagingResponseType": ".google.pubsub.v1.Topic",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListTopicsRequest",
"outputInterface": ".google.pubsub.v1.ListTopicsResponse",
"comments": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -4099,6 +4102,7 @@
{
"pagingFieldName": "topics",
"pagingResponseType": ".google.pubsub.v1.Topic",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListTopicsRequest",
"outputInterface": ".google.pubsub.v1.ListTopicsResponse",
"comments": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -4450,6 +4456,7 @@
{
"pagingFieldName": "schemas",
"pagingResponseType": ".google.pubsub.v1.Schema",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSchemasRequest",
"outputInterface": ".google.pubsub.v1.ListSchemasResponse",
"comments": [
Expand Down Expand Up @@ -8232,6 +8239,7 @@
{
"pagingFieldName": "schemas",
"pagingResponseType": ".google.pubsub.v1.Schema",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSchemasRequest",
"outputInterface": ".google.pubsub.v1.ListSchemasResponse",
"comments": [
Expand Down Expand Up @@ -8651,6 +8659,7 @@
{
"pagingFieldName": "subscriptions",
"pagingResponseType": ".google.pubsub.v1.Subscription",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSubscriptionsRequest",
"outputInterface": ".google.pubsub.v1.ListSubscriptionsResponse",
"comments": [
Expand Down Expand Up @@ -9164,6 +9173,7 @@
{
"pagingFieldName": "snapshots",
"pagingResponseType": ".google.pubsub.v1.Snapshot",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSnapshotsRequest",
"outputInterface": ".google.pubsub.v1.ListSnapshotsResponse",
"comments": [
Expand Down Expand Up @@ -13895,6 +13905,7 @@
{
"pagingFieldName": "subscriptions",
"pagingResponseType": ".google.pubsub.v1.Subscription",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSubscriptionsRequest",
"outputInterface": ".google.pubsub.v1.ListSubscriptionsResponse",
"comments": [
Expand Down Expand Up @@ -13951,6 +13962,7 @@
{
"pagingFieldName": "snapshots",
"pagingResponseType": ".google.pubsub.v1.Snapshot",
"ignoreMapPagingMethod": false,
"inputInterface": ".google.pubsub.v1.ListSnapshotsRequest",
"outputInterface": ".google.pubsub.v1.ListSnapshotsResponse",
"comments": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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")) }}
Expand Down Expand Up @@ -860,6 +865,7 @@ export class {{ service.name }}Client {
) as AsyncIterable<{{ util.toInterface(method.pagingResponseType) }}>;
{%- endif %}
}
{%- endif %}
{%- endfor %}
{%- if service.IAMPolicyMixin > 0 %}
{{ iam.iamServiceMethods()}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -888,6 +888,7 @@ describe('{{ api.naming.version }}.{{ service.name }}Client', () => {
{%- endif %}
});
});
{%- endif %}
{%- endfor %}
{%- if (service.IAMPolicyMixin) > 0 %}
{%- set IAMmethods = ['getIamPolicy', 'setIamPolicy', 'testIamPermissions'] %}
Expand Down
28 changes: 28 additions & 0 deletions typescript/src/schema/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ interface MethodDescriptorProto
pagingFieldName: string | undefined;
pagingResponseType?: string;
pagingMapResponseType?: string;
ignoreMapPagingMethod?: boolean | undefined;
inputInterface: string;
outputInterface: string;
comments: string[];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit b7dc09f

Please sign in to comment.