Skip to content
This repository was archived by the owner on Mar 19, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as yaml from 'js-yaml';
import * as serializer from 'proto3-json-serializer';
import protobuf from 'protobufjs';
import type * as protos from '../../protos/index.js';
import protoJson from '../../protos/protos.json' assert {type: 'json'};
import protoJson from '../../protos/protos.json' with {type: 'json'};
import * as url from 'url';
import {API} from './schema/api.js';
import {processTemplates} from './templater.js';
Expand Down Expand Up @@ -163,13 +163,30 @@ export class Generator {
const content = fs.readFileSync(filename, 'utf8');
const info = yaml.load(content) as ServiceYaml;
this.serviceYaml = info;
const serviceMixins = [];
let serviceMixins: string[] = [];
for (let i = 0; i < info.apis?.length || 0; i++) {
const api = info.apis[i];
for (const [, value] of Object.entries(api)) {
serviceMixins.push(value);
}
}
if (serviceMixins.includes('google.iam.v1.IAMPolicy')) {
// Check if any of the services in the protos have SetIamPolicy, GetIamPolicy, or TestIamPermissions methods.
// If so, then remove the IAMPolicy mixin from the service yaml file to avoid duplicates.
const methods = API.getServiceMethods(
Comment thread
shivanee-p marked this conversation as resolved.
Outdated
this.request.protoFile,
this.request.fileToGenerate,
);
if (
methods.has('SetIamPolicy') ||
Comment thread
shivanee-p marked this conversation as resolved.
Outdated
methods.has('GetIamPolicy') ||
methods.has('TestIamPermissions')
) {
serviceMixins = serviceMixins.filter(
m => m !== 'google.iam.v1.IAMPolicy',
);
}
}
this.serviceYaml.apis = serviceMixins;
}
// override if needed
Expand Down
22 changes: 22 additions & 0 deletions generator/gapic-generator-typescript/typescript/src/schema/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
handwrittenLayer?: boolean;
legacyProtoLoad: boolean;
restNumericEnums: boolean;
documentationUri: any;

Check warning on line 46 in generator/gapic-generator-typescript/typescript/src/schema/api.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
newIssueUri: string;
title?: string;

Expand Down Expand Up @@ -87,6 +87,28 @@
return filteredProtos;
}

static getServiceMethods(
fds: protos.google.protobuf.IFileDescriptorProto[],
filesToGenerate: string[],
) {
const methods = new Set<string>();
const filesToGenerateSet = new Set(filesToGenerate);
for (const fd of fds) {
if (filesToGenerateSet.has(fd.name!) && fd.service) {
for (const service of fd.service) {
if (service.method) {
for (const method of service.method) {
if (method.name) {
methods.add(method.name);
}
}
}
}
}
}
return methods;
}

constructor(
fileDescriptors: protos.google.protobuf.IFileDescriptorProto[],
packageName: string,
Expand Down
Loading