Skip to content

Commit 2ed5cbb

Browse files
authored
feat: add apiVersion to x-goog headers (#1576)
* feat: add apiVersion to x-goog headers
1 parent 7cfda61 commit 2ed5cbb

File tree

44 files changed

+2103
-262
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2103
-262
lines changed

baselines/disable-packing-test-esm/esm/src/v1beta1/echo_client.ts.baseline

Lines changed: 82 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ export class EchoClient {
280280
// Put together the default options sent with requests.
281281
this._defaults = this._gaxGrpc.constructSettings(
282282
'google.showcase.v1beta1.Echo', gapicConfig as gax.ClientConfig,
283-
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')});
283+
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' '), 'x-goog-api-version': 'v1_20240408'});
284284

285285
// Set up a dictionary of "inner API calls"; the core implementation
286286
// of calling the API is handled in `google-gax`, with this code
@@ -320,7 +320,7 @@ export class EchoClient {
320320
// Iterate over each of the methods that the service provides
321321
// and create an API call method for each.
322322
const echoStubMethods =
323-
['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'pagedExpandLegacy', 'wait', 'block'];
323+
['echo', 'echoErrorDetails', 'expand', 'collect', 'chat', 'pagedExpand', 'pagedExpandLegacy', 'wait', 'block'];
324324
for (const methodName of echoStubMethods) {
325325
const callPromise = this.echoStub.then(
326326
stub => (...args: Array<{}>) => {
@@ -436,8 +436,6 @@ export class EchoClient {
436436
* The request object that will be sent.
437437
* @param {string} request.content
438438
* The content to be echoed by the server.
439-
* @param {string} request.requestId
440-
* A random request_id to test autopopulation
441439
* @param {google.rpc.Status} request.error
442440
* The error to be thrown by the server.
443441
* @param {google.showcase.v1beta1.Severity} request.severity
@@ -446,6 +444,10 @@ export class EchoClient {
446444
* Optional. This field can be set to test the routing annotation on the Echo method.
447445
* @param {string} request.otherHeader
448446
* Optional. This field can be set to test the routing annotation on the Echo method.
447+
* @param {string} request.requestId
448+
* To facilitate testing of https://google.aip.dev/client-libraries/4235
449+
* @param {string} request.otherRequestId
450+
* To facilitate testing of https://google.aip.dev/client-libraries/4235
449451
* @param {object} [options]
450452
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
451453
* @returns {Promise} - The promise which resolves to an array.
@@ -590,6 +592,80 @@ export class EchoClient {
590592
this.initialize();
591593
return this.innerApiCalls.echo(request, options, callback);
592594
}
595+
/**
596+
* This method returns error details in a repeated "google.protobuf.Any"
597+
* field. This method showcases handling errors thus encoded, particularly
598+
* over REST transport. Note that GAPICs only allow the type
599+
* "google.protobuf.Any" for field paths ending in "error.details", and, at
600+
* run-time, the actual types for these fields must be one of the types in
601+
* google/rpc/error_details.proto.
602+
*
603+
* @param {Object} request
604+
* The request object that will be sent.
605+
* @param {string} request.singleDetailText
606+
* Content to return in a singular `*.error.details` field of type
607+
* `google.protobuf.Any`
608+
* @param {string[]} request.multiDetailText
609+
* Content to return in a repeated `*.error.details` field of type
610+
* `google.protobuf.Any`
611+
* @param {object} [options]
612+
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
613+
* @returns {Promise} - The promise which resolves to an array.
614+
* The first element of the array is an object representing {@link protos.google.showcase.v1beta1.EchoErrorDetailsResponse|EchoErrorDetailsResponse}.
615+
* Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation }
616+
* for more details and examples.
617+
* @example <caption>include:samples/generated/v1beta1/echo.echo_error_details.js</caption>
618+
* region_tag:localhost_v1beta1_generated_Echo_EchoErrorDetails_async
619+
*/
620+
echoErrorDetails(
621+
request?: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
622+
options?: CallOptions):
623+
Promise<[
624+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
625+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|undefined, {}|undefined
626+
]>;
627+
echoErrorDetails(
628+
request: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
629+
options: CallOptions,
630+
callback: Callback<
631+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
632+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
633+
{}|null|undefined>): void;
634+
echoErrorDetails(
635+
request: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
636+
callback: Callback<
637+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
638+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
639+
{}|null|undefined>): void;
640+
echoErrorDetails(
641+
request?: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
642+
optionsOrCallback?: CallOptions|Callback<
643+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
644+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
645+
{}|null|undefined>,
646+
callback?: Callback<
647+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
648+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
649+
{}|null|undefined>):
650+
Promise<[
651+
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
652+
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|undefined, {}|undefined
653+
]>|void {
654+
request = request || {};
655+
let options: CallOptions;
656+
if (typeof optionsOrCallback === 'function' && callback === undefined) {
657+
callback = optionsOrCallback;
658+
options = {};
659+
}
660+
else {
661+
options = optionsOrCallback as CallOptions;
662+
}
663+
options = options || {};
664+
options.otherArgs = options.otherArgs || {};
665+
options.otherArgs.headers = options.otherArgs.headers || {};
666+
this.initialize();
667+
return this.innerApiCalls.echoErrorDetails(request, options, callback);
668+
}
593669
/**
594670
* This is similar to the PagedExpand except that it uses
595671
* max_results instead of page_size, as some legacy APIs still
@@ -746,6 +822,8 @@ export class EchoClient {
746822
* The content that will be split into words and returned on the stream.
747823
* @param {google.rpc.Status} request.error
748824
* The error that is thrown after all words are sent on the stream.
825+
* @param {google.protobuf.Duration} request.streamWaitTime
826+
* The wait time between each server streaming messages
749827
* @param {object} [options]
750828
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
751829
* @returns {Stream}

baselines/disable-packing-test-esm/esm/src/v1beta1/echo_client_config.json.baseline

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
"retry_codes_name": "non_idempotent",
2525
"retry_params_name": "default"
2626
},
27+
"EchoErrorDetails": {
28+
"retry_codes_name": "non_idempotent",
29+
"retry_params_name": "default"
30+
},
2731
"Expand": {
2832
"retry_codes_name": "non_idempotent",
2933
"retry_params_name": "default"

baselines/disable-packing-test-esm/esm/test/gapic_echo_v1beta1.ts.baseline

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,81 @@ describe('v1beta1.EchoClient', () => {
380380
});
381381
});
382382

383+
describe('echoErrorDetails', () => {
384+
it('invokes echoErrorDetails without error', async () => {
385+
const client = new echoModule.v1beta1.EchoClient({
386+
credentials: {client_email: 'bogus', private_key: 'bogus'},
387+
projectId: 'bogus',
388+
});
389+
client.initialize();
390+
const request = generateSampleMessage(
391+
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
392+
);
393+
const expectedResponse = generateSampleMessage(
394+
new protos.google.showcase.v1beta1.EchoErrorDetailsResponse()
395+
);
396+
client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse);
397+
const [response] = await client.echoErrorDetails(request);
398+
assert.deepStrictEqual(response, expectedResponse);
399+
});
400+
401+
it('invokes echoErrorDetails without error using callback', async () => {
402+
const client = new echoModule.v1beta1.EchoClient({
403+
credentials: {client_email: 'bogus', private_key: 'bogus'},
404+
projectId: 'bogus',
405+
});
406+
client.initialize();
407+
const request = generateSampleMessage(
408+
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
409+
);
410+
const expectedResponse = generateSampleMessage(
411+
new protos.google.showcase.v1beta1.EchoErrorDetailsResponse()
412+
);
413+
client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse);
414+
const promise = new Promise((resolve, reject) => {
415+
client.echoErrorDetails(
416+
request,
417+
(err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => {
418+
if (err) {
419+
reject(err);
420+
} else {
421+
resolve(result);
422+
}
423+
});
424+
});
425+
const response = await promise;
426+
assert.deepStrictEqual(response, expectedResponse);
427+
});
428+
429+
it('invokes echoErrorDetails with error', async () => {
430+
const client = new echoModule.v1beta1.EchoClient({
431+
credentials: {client_email: 'bogus', private_key: 'bogus'},
432+
projectId: 'bogus',
433+
});
434+
client.initialize();
435+
const request = generateSampleMessage(
436+
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
437+
);
438+
const expectedError = new Error('expected');
439+
client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError);
440+
await assert.rejects(client.echoErrorDetails(request), expectedError);
441+
});
442+
443+
it('invokes echoErrorDetails with closed client', async () => {
444+
const client = new echoModule.v1beta1.EchoClient({
445+
credentials: {client_email: 'bogus', private_key: 'bogus'},
446+
projectId: 'bogus',
447+
});
448+
client.initialize();
449+
const request = generateSampleMessage(
450+
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
451+
);
452+
const expectedError = new Error('The client has already been closed.');
453+
client.close();
454+
await assert.rejects(client.echoErrorDetails(request), expectedError);
455+
});
456+
});
457+
383458
describe('pagedExpandLegacy', () => {
384459
it('invokes pagedExpandLegacy without error', async () => {
385460
const client = new echoModule.v1beta1.EchoClient({

baselines/disable-packing-test-esm/protos/google/showcase/v1beta1/echo.proto.baseline

Lines changed: 75 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import "google/api/field_behavior.proto";
2020
import "google/api/field_info.proto";
2121
import "google/api/routing.proto";
2222
import "google/longrunning/operations.proto";
23+
import "google/protobuf/any.proto";
2324
import "google/protobuf/duration.proto";
2425
import "google/protobuf/timestamp.proto";
2526
import "google/rpc/status.proto";
@@ -35,13 +36,15 @@ option ruby_package = "Google::Showcase::V1beta1";
3536
// side streaming, client side streaming, and bidirectional streaming. This
3637
// service also exposes methods that explicitly implement server delay, and
3738
// paginated calls. Set the 'showcase-trailer' metadata key on any method
38-
// to have the values echoed in the response trailers. Set the
39+
// to have the values echoed in the response trailers. Set the
3940
// 'x-goog-request-params' metadata key on any method to have the values
4041
// echoed in the response headers.
4142
service Echo {
4243
// This service is meant to only run locally on the port 7469 (keypad digits
4344
// for "show").
4445
option (google.api.default_host) = "localhost:7469";
46+
// See https://github.com/aip-dev/google.aip.dev/pull/1331
47+
option (google.api.api_version) = "v1_20240408";
4548

4649
// This method simply echoes the request. This method showcases unary RPCs.
4750
rpc Echo(EchoRequest) returns (EchoResponse) {
@@ -84,6 +87,19 @@ service Echo {
8487
};
8588
}
8689

90+
// This method returns error details in a repeated "google.protobuf.Any"
91+
// field. This method showcases handling errors thus encoded, particularly
92+
// over REST transport. Note that GAPICs only allow the type
93+
// "google.protobuf.Any" for field paths ending in "error.details", and, at
94+
// run-time, the actual types for these fields must be one of the types in
95+
// google/rpc/error_details.proto.
96+
rpc EchoErrorDetails(EchoErrorDetailsRequest) returns (EchoErrorDetailsResponse) {
97+
option (google.api.http) = {
98+
post: "/v1beta1/echo:error-details"
99+
body: "*"
100+
};
101+
}
102+
87103
// This method splits the given content into words and will pass each word back
88104
// through the stream. This method showcases server-side streaming RPCs.
89105
rpc Expand(ExpandRequest) returns (stream EchoResponse) {
@@ -184,21 +200,28 @@ message EchoRequest {
184200
// The content to be echoed by the server.
185201
string content = 1;
186202

187-
// A random request_id to test autopopulation
188-
string request_id = 2 [(google.api.field_info).format = UUID4];
189-
190203
// The error to be thrown by the server.
191-
google.rpc.Status error = 3;
204+
google.rpc.Status error = 2;
192205
}
193206

194207
// The severity to be echoed by the server.
195-
Severity severity = 4;
208+
Severity severity = 3;
196209

197210
// Optional. This field can be set to test the routing annotation on the Echo method.
198-
string header = 5;
211+
string header = 4;
199212

200213
// Optional. This field can be set to test the routing annotation on the Echo method.
201-
string other_header = 6;
214+
string other_header = 5;
215+
216+
// To facilitate testing of https://google.aip.dev/client-libraries/4235
217+
string request_id = 7 [
218+
(google.api.field_info).format = UUID4
219+
];
220+
221+
// To facilitate testing of https://google.aip.dev/client-libraries/4235
222+
optional string other_request_id = 8 [
223+
(google.api.field_info).format = UUID4
224+
];
202225
}
203226

204227
// The response message for the Echo methods.
@@ -208,6 +231,46 @@ message EchoResponse {
208231

209232
// The severity specified in the request.
210233
Severity severity = 2;
234+
235+
// The request ID specified or autopopulated in the request.
236+
string request_id = 3;
237+
238+
// The other request ID specified or autopopulated in the request.
239+
string other_request_id = 4;
240+
}
241+
242+
// The request message used for the EchoErrorDetails method.
243+
message EchoErrorDetailsRequest {
244+
// Content to return in a singular `*.error.details` field of type
245+
// `google.protobuf.Any`
246+
string single_detail_text = 1;
247+
248+
// Content to return in a repeated `*.error.details` field of type
249+
// `google.protobuf.Any`
250+
repeated string multi_detail_text = 2;
251+
}
252+
253+
// The response message used for the EchoErrorDetails method.
254+
message EchoErrorDetailsResponse {
255+
256+
message SingleDetail {
257+
ErrorWithSingleDetail error = 1;
258+
}
259+
260+
message MultipleDetails {
261+
ErrorWithMultipleDetails error = 1;
262+
}
263+
264+
SingleDetail single_detail = 1;
265+
MultipleDetails multiple_details = 2;
266+
}
267+
268+
message ErrorWithSingleDetail {
269+
google.protobuf.Any details = 1;
270+
}
271+
272+
message ErrorWithMultipleDetails {
273+
repeated google.protobuf.Any details = 1;
211274
}
212275

213276
// The request message for the Expand method.
@@ -217,6 +280,9 @@ message ExpandRequest {
217280

218281
// The error that is thrown after all words are sent on the stream.
219282
google.rpc.Status error = 2;
283+
284+
//The wait time between each server streaming messages
285+
google.protobuf.Duration stream_wait_time = 3;
220286
}
221287

222288
// The request for the PagedExpand method.
@@ -323,4 +389,4 @@ message BlockResponse {
323389
// This content can contain anything, the server will not depend on a value
324390
// here.
325391
string content = 1;
326-
}
392+
}

0 commit comments

Comments
 (0)