Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not try to generate code for common protos #82

Merged
merged 2 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion typescript/src/schema/api.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down
39 changes: 39 additions & 0 deletions typescript/test/unit/api.ts
Original file line number Diff line number Diff line change
@@ -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',
]);
});
});