Skip to content

fix: update generator to generate location mixin separately #1598

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

Merged
merged 2 commits into from
May 29, 2024
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
9 changes: 7 additions & 2 deletions typescript/src/schema/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export class API {
return (
fd.package === 'google.longrunning' ||
fd.package === 'google.cloud' ||
fd.package === 'google.cloud.location' ||
fd.package === 'google.protobuf' ||
fd.package === 'google.type' ||
fd.package === 'google.rpc' ||
Expand All @@ -63,7 +62,8 @@ export class API {
fds: protos.google.protobuf.IFileDescriptorProto[]
) {
let filteredProtos = fds.filter(fd => !API.isIgnoredService(fd));
// Special case: google.iam.v1 can be either a separate service to generate,
// Special cases: google.iam.v1 or google.cloud.location
// can be either a separate service to generate,
// or a dependency that should be ignored here
const packages = filteredProtos.reduce((set, fd) => {
set.add(fd.package!);
Expand All @@ -74,6 +74,11 @@ export class API {
p => p.package !== 'google.iam.v1'
);
}
if (packages.size > 1 && packages.has('google.cloud.location')) {
filteredProtos = filteredProtos.filter(
p => p.package !== 'google.cloud.location'
);
}
return filteredProtos;
}

Expand Down
6 changes: 4 additions & 2 deletions typescript/src/schema/naming.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ export class Naming {
const versionIndex = segments.findIndex(segment =>
segment.match(versionPattern)
);
if (versionIndex === -1) {
// Special exception for location, which does not have a version
if (versionIndex === -1 && rootPackage !== 'google.cloud.location') {
throw new Error(
`ERROR: Cannot parse package name ${rootPackage}: version does not match ${versionPattern}.`
);
Expand All @@ -88,7 +89,8 @@ export class Naming {
`ERROR: Cannot parse package name ${rootPackage}: version ${version} is the first segment in the name.`
);
}
const name = segments[versionIndex - 1];
// If there is no version (in the case of location), just grab the last segment
const name = segments[versionIndex - 1] || segments[segments.length - 1];

// everything before the name is namespace
const namespaces = segments.slice(0, versionIndex - 1).join('.');
Expand Down
17 changes: 17 additions & 0 deletions typescript/test/unit/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,23 @@ describe('src/schema/api.ts', () => {
]);
});

it('should be able to generate google.cloud.location alone', () => {
const fd = {} as protos.google.protobuf.FileDescriptorProto;
fd.name = 'google/cloud/location/location.proto';
fd.package = 'google.cloud.location';
fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto];
fd.service[0].name = 'IAMPolicy';
fd.service[0].options = {
'.google.api.defaultHost': 'cloud.googleapis.com',
};
const api = new API([fd], 'google.cloud.location', {
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
});
assert.deepStrictEqual(api.filesToGenerate, [
'google/cloud/location/location.proto',
]);
});

it('should not return common protos in the proto list', () => {
const fd1 = {} as protos.google.protobuf.FileDescriptorProto;
fd1.name = 'google/cloud/test/v1/test.proto';
Expand Down
Loading