diff --git a/typescript/src/schema/api.ts b/typescript/src/schema/api.ts index de917753b..5d6b5f4be 100644 --- a/typescript/src/schema/api.ts +++ b/typescript/src/schema/api.ts @@ -1,8 +1,12 @@ import * as plugin from '../../../pbjs-genfiles/plugin'; +import * as fs from 'fs'; +import * as path from 'path'; import { Naming } from './naming'; import { Proto, MessagesMap, ResourceDescriptor, ResourceMap } from './proto'; -import { fstat } from 'fs-extra'; + +const googleGaxLocation = path.dirname(require.resolve('google-gax')); +const gaxProtosLocation = path.join(googleGaxLocation, '..', '..', 'protos'); export interface ProtosMap { [filename: string]: Proto; @@ -31,6 +35,7 @@ export class API { // parse resource map to Proto constructor this.protos = fileDescriptors .filter(fd => fd.name) + .filter(fd => !fs.existsSync(path.join(gaxProtosLocation, fd.name!))) .reduce( (map, fd) => { map[fd.name!] = new Proto( diff --git a/typescript/test/unit/api.ts b/typescript/test/unit/api.ts new file mode 100644 index 000000000..81a55eb0c --- /dev/null +++ b/typescript/test/unit/api.ts @@ -0,0 +1,39 @@ +import { API } from '../../src/schema/api'; +import * as plugin from '../../../pbjs-genfiles/plugin'; +import * as assert from 'assert'; + +describe('schema/api.ts', () => { + it('should construct an API object and return list of protos', () => { + const fd = new plugin.google.protobuf.FileDescriptorProto(); + fd.name = 'google/cloud/test/v1/test.proto'; + fd.package = 'google.cloud.test.v1'; + fd.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + const api = new API( + [fd], + 'google.cloud.test.v1', + new plugin.grpc.service_config.ServiceConfig() + ); + assert.deepStrictEqual(api.filesToGenerate, [ + 'google/cloud/test/v1/test.proto', + ]); + }); + + it('should not return common protos in the list of protos', () => { + const fd1 = new plugin.google.protobuf.FileDescriptorProto(); + fd1.name = 'google/cloud/test/v1/test.proto'; + fd1.package = 'google.cloud.test.v1'; + fd1.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + const fd2 = new plugin.google.protobuf.FileDescriptorProto(); + fd2.name = 'google/longrunning/operation.proto'; + fd2.package = 'google.longrunning'; + fd2.service = [new plugin.google.protobuf.ServiceDescriptorProto()]; + const api = new API( + [fd1, fd2], + 'google.cloud.test.v1', + new plugin.grpc.service_config.ServiceConfig() + ); + assert.deepStrictEqual(api.filesToGenerate, [ + 'google/cloud/test/v1/test.proto', + ]); + }); +});