diff --git a/typescript/src/schema/proto.ts b/typescript/src/schema/proto.ts index 5bf3ed0ed..97e7d60f6 100644 --- a/typescript/src/schema/proto.ts +++ b/typescript/src/schema/proto.ts @@ -150,7 +150,26 @@ function streaming(method: MethodDescriptorProto) { return undefined; } -function pagingField(messages: MessagesMap, method: MethodDescriptorProto) { +function pagingField( + messages: MessagesMap, + method: MethodDescriptorProto, + service?: ServiceDescriptorProto +) { + // TODO: remove this once the next version of the Talent API is published. + // + // This is a workaround to disable auto-pagination for specifc RPCs in + // Talent v4beta1. The API team will make their API non-conforming in the + // next version. + // + // This should not be done for any other API. + const serviceName = + service && service.packageName === 'google.cloud.talent.v4beta1'; + const methodName = + method.name === 'SearchProfiles' || method.name === 'SearchJobs'; + if (serviceName && methodName) { + return undefined; + } + const inputType = messages[method.inputType!]; const outputType = messages[method.outputType!]; const hasPageToken = @@ -201,8 +220,12 @@ function pagingField(messages: MessagesMap, method: MethodDescriptorProto) { return repeatedFields[0]; } -function pagingFieldName(messages: MessagesMap, method: MethodDescriptorProto) { - const field = pagingField(messages, method); +function pagingFieldName( + messages: MessagesMap, + method: MethodDescriptorProto, + service?: ServiceDescriptorProto +) { + const field = pagingField(messages, method, service); return field?.name; } @@ -277,7 +300,7 @@ function augmentMethod( method ), streaming: streaming(method), - pagingFieldName: pagingFieldName(messages, method), + pagingFieldName: pagingFieldName(messages, method, service), pagingResponseType: pagingResponseType(messages, method), inputInterface: method.inputType!, outputInterface: method.outputType!, diff --git a/typescript/test/unit/proto.ts b/typescript/test/unit/proto.ts index a32d5342e..b153068eb 100644 --- a/typescript/test/unit/proto.ts +++ b/typescript/test/unit/proto.ts @@ -16,6 +16,8 @@ import * as assert from 'assert'; import { describe, it } from 'mocha'; import * as plugin from '../../../pbjs-genfiles/plugin'; import { getHeaderRequestParams } from '../../src/schema/proto'; +import { Proto } from '../../src/schema/proto'; +import { ResourceDatabase } from '../../src/schema/resource-database'; describe('src/schema/proto.ts', () => { describe('should get header parameters from http rule', () => { @@ -92,4 +94,67 @@ describe('src/schema/proto.ts', () => { ); }); }); + describe('special work around for talent API', () => { + it('The pagingFieldName should be undefined for SearchJobs & SearchProfiles rpc', () => { + const fd = new plugin.google.protobuf.FileDescriptorProto(); + fd.name = 'google/cloud/talent/v4beta1/service.proto'; + fd.package = 'google.cloud.talent.v4beta1'; + fd.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + fd.service[0].name = 'service'; + fd.service[0].method = [ + new plugin.google.protobuf.MethodDescriptorProto(), + ]; + fd.service[0].method[0] = new plugin.google.protobuf.MethodDescriptorProto(); + fd.service[0].method[0].name = 'SearchJobs'; + fd.service[0].method[1] = new plugin.google.protobuf.MethodDescriptorProto(); + fd.service[0].method[1].name = 'SearchProfiles'; + fd.service[0].method[2] = new plugin.google.protobuf.MethodDescriptorProto(); + fd.service[0].method[2].name = 'ListJobs'; + fd.service[0].method[2].outputType = + '.google.cloud.talent.v4beta1.ListJobsOutput'; + fd.service[0].method[2].inputType = + '.google.cloud.talent.v4beta1.ListJobsInput'; + + fd.messageType = [new plugin.google.protobuf.DescriptorProto()]; + fd.messageType[0] = new plugin.google.protobuf.DescriptorProto(); + fd.messageType[1] = new plugin.google.protobuf.DescriptorProto(); + + fd.messageType[0].name = 'ListJobsOutput'; + fd.messageType[1].name = 'ListJobsInput'; + + fd.messageType[0].field = [ + new plugin.google.protobuf.FieldDescriptorProto(), + ]; + fd.messageType[0].field[0] = new plugin.google.protobuf.FieldDescriptorProto(); + fd.messageType[0].field[0].name = 'next_page_token'; + fd.messageType[0].field[0].label = + plugin.google.protobuf.FieldDescriptorProto.Label.LABEL_REPEATED; + fd.messageType[1].field = [ + new plugin.google.protobuf.FieldDescriptorProto(), + ]; + fd.messageType[1].field[0] = new plugin.google.protobuf.FieldDescriptorProto(); + fd.messageType[1].field[0].name = 'page_size'; + fd.messageType[1].field[1] = new plugin.google.protobuf.FieldDescriptorProto(); + fd.messageType[1].field[1].name = 'page_token'; + const proto = new Proto( + fd, + 'google.cloud.talent.v4beta1', + new plugin.grpc.service_config.ServiceConfig(), + new ResourceDatabase(), + new ResourceDatabase() + ); + assert.deepStrictEqual( + proto.services['service'].method[0].pagingFieldName, + undefined + ); + assert.deepStrictEqual( + proto.services['service'].method[1].pagingFieldName, + undefined + ); + assert.deepStrictEqual( + proto.services['service'].method[2].pagingFieldName, + 'next_page_token' + ); + }); + }); });