Skip to content

Commit f1e4ce2

Browse files
authored
Merge branch 'main' into release-please--branches--main--components--gapic-generator
2 parents 21e4adf + 13854a4 commit f1e4ce2

File tree

3 files changed

+28
-4
lines changed

3 files changed

+28
-4
lines changed

typescript/src/schema/api.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export class API {
5050
return (
5151
fd.package === 'google.longrunning' ||
5252
fd.package === 'google.cloud' ||
53-
fd.package === 'google.cloud.location' ||
5453
fd.package === 'google.protobuf' ||
5554
fd.package === 'google.type' ||
5655
fd.package === 'google.rpc' ||
@@ -63,7 +62,8 @@ export class API {
6362
fds: protos.google.protobuf.IFileDescriptorProto[]
6463
) {
6564
let filteredProtos = fds.filter(fd => !API.isIgnoredService(fd));
66-
// Special case: google.iam.v1 can be either a separate service to generate,
65+
// Special cases: google.iam.v1 or google.cloud.location
66+
// can be either a separate service to generate,
6767
// or a dependency that should be ignored here
6868
const packages = filteredProtos.reduce((set, fd) => {
6969
set.add(fd.package!);
@@ -74,6 +74,11 @@ export class API {
7474
p => p.package !== 'google.iam.v1'
7575
);
7676
}
77+
if (packages.size > 1 && packages.has('google.cloud.location')) {
78+
filteredProtos = filteredProtos.filter(
79+
p => p.package !== 'google.cloud.location'
80+
);
81+
}
7782
return filteredProtos;
7883
}
7984

typescript/src/schema/naming.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ export class Naming {
7575
const versionIndex = segments.findIndex(segment =>
7676
segment.match(versionPattern)
7777
);
78-
if (versionIndex === -1) {
78+
// Special exception for location, which does not have a version
79+
if (versionIndex === -1 && rootPackage !== 'google.cloud.location') {
7980
throw new Error(
8081
`ERROR: Cannot parse package name ${rootPackage}: version does not match ${versionPattern}.`
8182
);
@@ -88,7 +89,8 @@ export class Naming {
8889
`ERROR: Cannot parse package name ${rootPackage}: version ${version} is the first segment in the name.`
8990
);
9091
}
91-
const name = segments[versionIndex - 1];
92+
// If there is no version (in the case of location), just grab the last segment
93+
const name = segments[versionIndex - 1] || segments[segments.length - 1];
9294

9395
// everything before the name is namespace
9496
const namespaces = segments.slice(0, versionIndex - 1).join('.');

typescript/test/unit/api.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@ describe('src/schema/api.ts', () => {
9191
]);
9292
});
9393

94+
it('should be able to generate google.cloud.location alone', () => {
95+
const fd = {} as protos.google.protobuf.FileDescriptorProto;
96+
fd.name = 'google/cloud/location/location.proto';
97+
fd.package = 'google.cloud.location';
98+
fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto];
99+
fd.service[0].name = 'IAMPolicy';
100+
fd.service[0].options = {
101+
'.google.api.defaultHost': 'cloud.googleapis.com',
102+
};
103+
const api = new API([fd], 'google.cloud.location', {
104+
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
105+
});
106+
assert.deepStrictEqual(api.filesToGenerate, [
107+
'google/cloud/location/location.proto',
108+
]);
109+
});
110+
94111
it('should not return common protos in the proto list', () => {
95112
const fd1 = {} as protos.google.protobuf.FileDescriptorProto;
96113
fd1.name = 'google/cloud/test/v1/test.proto';

0 commit comments

Comments
 (0)