Skip to content

feat: add apiVersion to x-goog headers #1576

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 13 commits into from
Apr 30, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,10 @@ export class {{ service.name }}Client {
// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings(
'{{ api.naming.protoPackage }}.{{ service.name }}', gapicConfig as gax.ClientConfig,
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')});
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')
{%- if service.apiVersion -%}
, 'x-goog-api-version': '{{ service.apiVersion }}'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like this change is not covered by baselines, so if it stops working for whatever reason, we won't be able to catch it. Should we add the corresponding annotation to at least one baseline service?

{%- endif -%}});

// Set up a dictionary of "inner API calls"; the core implementation
// of calling the API is handled in `google-gax`, with this code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ export class {{ service.name }}Client {
// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings(
'{{ api.naming.protoPackage }}.{{ service.name }}', gapicConfig as gax.ClientConfig,
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')});
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}
{%- if service.apiVersion -%}
, {'x-goog-api-version': {{ service.apiVersion }}}
{%- endif %});

// Set up a dictionary of "inner API calls"; the core implementation
// of calling the API is handled in `google-gax`, with this code
Expand Down
5 changes: 5 additions & 0 deletions typescript/src/schema/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export interface MethodDescriptorProto

export interface ServiceDescriptorProto
extends protos.google.protobuf.IServiceDescriptorProto {
apiVersion: string;
packageName: string;
method: MethodDescriptorProto[];
simpleMethods: MethodDescriptorProto[];
Expand Down Expand Up @@ -908,6 +909,10 @@ function augmentService(parameters: AugmentServiceParameters) {
augmentedService.oauthScopes =
augmentedService.options['.google.api.oauthScopes'].split(',');
}
if (augmentedService.options?.['.google.api.apiVersion']) {
augmentedService.apiVersion =
augmentedService.options['.google.api.apiVersion'];
}

// Build a list of resources referenced by this service

Expand Down
29 changes: 29 additions & 0 deletions typescript/test/unit/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,35 @@
});
assert.strictEqual(proto.services[fd.service[0].name].protoFile, fd.name);
});

it('should return api version if it exists', () => {
const fd = {} as protos.google.protobuf.FileDescriptorProto;
fd.name = 'google/cloud/showcase/v1beta1/test.proto';
fd.package = 'google.cloud.showcase.v1beta1';
fd.service = [{} as protos.google.protobuf.ServiceDescriptorProto];
fd.service[0].name = 'TestService';
fd.service[0].options = {
'.google.api.apiVersion': 'v1_20240408',
};
const options: Options = {
grpcServiceConfig: {} as protos.grpc.service_config.ServiceConfig,
};
const allMessages: MessagesMap = {};
const commentsMap = new CommentsMap([fd]);
const proto = new Proto({
fd,
packageName: 'google.cloud.showcase.v1beta1',
allMessages,
allResourceDatabase: new ResourceDatabase(),
resourceDatabase: new ResourceDatabase(),
options,
commentsMap,
});
assert.strictEqual(
proto.services['TestService'].apiVersion,
'v1_20240408'
);
});
});

describe('special work around for talent API', () => {
Expand Down Expand Up @@ -708,18 +737,18 @@
},
} as unknown as Comments;
},
getServiceComment: function (serviceName: string): string[] {

Check warning on line 740 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'serviceName' is defined but never used
return ['not needed'];
},
getMethodComments: function (
serviceName: string,

Check warning on line 744 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'serviceName' is defined but never used
methodName: string

Check warning on line 745 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'methodName' is defined but never used
): string[] {
return ['not needed'];
},
getParamComments: function (
messageName: string,

Check warning on line 750 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'messageName' is defined but never used
fieldName: string

Check warning on line 751 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'fieldName' is defined but never used
): Comment {
return {
paramName: 'request_id',
Expand Down Expand Up @@ -792,18 +821,18 @@
},
} as unknown as Comments;
},
getServiceComment: function (serviceName: string): string[] {

Check warning on line 824 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'serviceName' is defined but never used
return ['not needed'];
},
getMethodComments: function (
serviceName: string,

Check warning on line 828 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'serviceName' is defined but never used
methodName: string

Check warning on line 829 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'methodName' is defined but never used
): string[] {
return ['not needed'];
},
getParamComments: function (
messageName: string,

Check warning on line 834 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'messageName' is defined but never used
fieldName: string

Check warning on line 835 in typescript/test/unit/proto.ts

View workflow job for this annotation

GitHub Actions / lint

'fieldName' is defined but never used
): Comment {
return {
paramName: 'request_id',
Expand Down
Loading
Loading