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 @@ -280,7 +280,7 @@ export class EchoClient {
// Put together the default options sent with requests.
this._defaults = this._gaxGrpc.constructSettings(
'google.showcase.v1beta1.Echo', gapicConfig as gax.ClientConfig,
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')});
opts.clientConfig || {}, {'x-goog-api-client': clientHeader.join(' ')}, {'x-goog-api-version': 'v1_20240408'});

// 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 Expand Up @@ -320,7 +320,7 @@ export class EchoClient {
// Iterate over each of the methods that the service provides
// and create an API call method for each.
const echoStubMethods =
['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'pagedExpandLegacy', 'wait', 'block'];
['echo', 'echoErrorDetails', 'expand', 'collect', 'chat', 'pagedExpand', 'pagedExpandLegacy', 'wait', 'block'];
for (const methodName of echoStubMethods) {
const callPromise = this.echoStub.then(
stub => (...args: Array<{}>) => {
Expand Down Expand Up @@ -436,8 +436,6 @@ export class EchoClient {
* The request object that will be sent.
* @param {string} request.content
* The content to be echoed by the server.
* @param {string} request.requestId
* A random request_id to test autopopulation
* @param {google.rpc.Status} request.error
* The error to be thrown by the server.
* @param {google.showcase.v1beta1.Severity} request.severity
Expand All @@ -446,6 +444,10 @@ export class EchoClient {
* Optional. This field can be set to test the routing annotation on the Echo method.
* @param {string} request.otherHeader
* Optional. This field can be set to test the routing annotation on the Echo method.
* @param {string} request.requestId
* To facilitate testing of https://google.aip.dev/client-libraries/4235
* @param {string} request.otherRequestId
* To facilitate testing of https://google.aip.dev/client-libraries/4235
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
Expand Down Expand Up @@ -590,6 +592,80 @@ export class EchoClient {
this.initialize();
return this.innerApiCalls.echo(request, options, callback);
}
/**
* This method returns error details in a repeated "google.protobuf.Any"
* field. This method showcases handling errors thus encoded, particularly
* over REST transport. Note that GAPICs only allow the type
* "google.protobuf.Any" for field paths ending in "error.details", and, at
* run-time, the actual types for these fields must be one of the types in
* google/rpc/error_details.proto.
*
* @param {Object} request
* The request object that will be sent.
* @param {string} request.singleDetailText
* Content to return in a singular `*.error.details` field of type
* `google.protobuf.Any`
* @param {string[]} request.multiDetailText
* Content to return in a repeated `*.error.details` field of type
* `google.protobuf.Any`
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Promise} - The promise which resolves to an array.
* The first element of the array is an object representing {@link protos.google.showcase.v1beta1.EchoErrorDetailsResponse|EchoErrorDetailsResponse}.
* Please see the {@link https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods | documentation }
* for more details and examples.
* @example <caption>include:samples/generated/v1beta1/echo.echo_error_details.js</caption>
* region_tag:localhost_v1beta1_generated_Echo_EchoErrorDetails_async
*/
echoErrorDetails(
request?: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
options?: CallOptions):
Promise<[
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|undefined, {}|undefined
]>;
echoErrorDetails(
request: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
options: CallOptions,
callback: Callback<
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
{}|null|undefined>): void;
echoErrorDetails(
request: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
callback: Callback<
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
{}|null|undefined>): void;
echoErrorDetails(
request?: protos.google.showcase.v1beta1.IEchoErrorDetailsRequest,
optionsOrCallback?: CallOptions|Callback<
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
{}|null|undefined>,
callback?: Callback<
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|null|undefined,
{}|null|undefined>):
Promise<[
protos.google.showcase.v1beta1.IEchoErrorDetailsResponse,
protos.google.showcase.v1beta1.IEchoErrorDetailsRequest|undefined, {}|undefined
]>|void {
request = request || {};
let options: CallOptions;
if (typeof optionsOrCallback === 'function' && callback === undefined) {
callback = optionsOrCallback;
options = {};
}
else {
options = optionsOrCallback as CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
this.initialize();
return this.innerApiCalls.echoErrorDetails(request, options, callback);
}
/**
* This is similar to the PagedExpand except that it uses
* max_results instead of page_size, as some legacy APIs still
Expand Down Expand Up @@ -746,6 +822,8 @@ export class EchoClient {
* The content that will be split into words and returned on the stream.
* @param {google.rpc.Status} request.error
* The error that is thrown after all words are sent on the stream.
* @param {google.protobuf.Duration} request.streamWaitTime
* The wait time between each server streaming messages
* @param {object} [options]
* Call options. See {@link https://googleapis.dev/nodejs/google-gax/latest/interfaces/CallOptions.html|CallOptions} for more details.
* @returns {Stream}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
},
"EchoErrorDetails": {
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
},
"Expand": {
"retry_codes_name": "non_idempotent",
"retry_params_name": "default"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,81 @@ describe('v1beta1.EchoClient', () => {
});
});

describe('echoErrorDetails', () => {
it('invokes echoErrorDetails without error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
);
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsResponse()
);
client.innerApiCalls.echoErrorDetails = stubSimpleCall(expectedResponse);
const [response] = await client.echoErrorDetails(request);
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes echoErrorDetails without error using callback', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
);
const expectedResponse = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsResponse()
);
client.innerApiCalls.echoErrorDetails = stubSimpleCallWithCallback(expectedResponse);
const promise = new Promise((resolve, reject) => {
client.echoErrorDetails(
request,
(err?: Error|null, result?: protos.google.showcase.v1beta1.IEchoErrorDetailsResponse|null) => {
if (err) {
reject(err);
} else {
resolve(result);
}
});
});
const response = await promise;
assert.deepStrictEqual(response, expectedResponse);
});

it('invokes echoErrorDetails with error', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
);
const expectedError = new Error('expected');
client.innerApiCalls.echoErrorDetails = stubSimpleCall(undefined, expectedError);
await assert.rejects(client.echoErrorDetails(request), expectedError);
});

it('invokes echoErrorDetails with closed client', async () => {
const client = new echoModule.v1beta1.EchoClient({
credentials: {client_email: 'bogus', private_key: 'bogus'},
projectId: 'bogus',
});
client.initialize();
const request = generateSampleMessage(
new protos.google.showcase.v1beta1.EchoErrorDetailsRequest()
);
const expectedError = new Error('The client has already been closed.');
client.close();
await assert.rejects(client.echoErrorDetails(request), expectedError);
});
});

describe('pagedExpandLegacy', () => {
it('invokes pagedExpandLegacy without error', async () => {
const client = new echoModule.v1beta1.EchoClient({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import "google/api/field_behavior.proto";
import "google/api/field_info.proto";
import "google/api/routing.proto";
import "google/longrunning/operations.proto";
import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/timestamp.proto";
import "google/rpc/status.proto";
Expand All @@ -35,13 +36,15 @@ option ruby_package = "Google::Showcase::V1beta1";
// side streaming, client side streaming, and bidirectional streaming. This
// service also exposes methods that explicitly implement server delay, and
// paginated calls. Set the 'showcase-trailer' metadata key on any method
// to have the values echoed in the response trailers. Set the
// to have the values echoed in the response trailers. Set the
// 'x-goog-request-params' metadata key on any method to have the values
// echoed in the response headers.
service Echo {
// This service is meant to only run locally on the port 7469 (keypad digits
// for "show").
option (google.api.default_host) = "localhost:7469";
// See https://github.com/aip-dev/google.aip.dev/pull/1331
option (google.api.api_version) = "v1_20240408";

// This method simply echoes the request. This method showcases unary RPCs.
rpc Echo(EchoRequest) returns (EchoResponse) {
Expand Down Expand Up @@ -84,6 +87,19 @@ service Echo {
};
}

// This method returns error details in a repeated "google.protobuf.Any"
// field. This method showcases handling errors thus encoded, particularly
// over REST transport. Note that GAPICs only allow the type
// "google.protobuf.Any" for field paths ending in "error.details", and, at
// run-time, the actual types for these fields must be one of the types in
// google/rpc/error_details.proto.
rpc EchoErrorDetails(EchoErrorDetailsRequest) returns (EchoErrorDetailsResponse) {
option (google.api.http) = {
post: "/v1beta1/echo:error-details"
body: "*"
};
}

// This method splits the given content into words and will pass each word back
// through the stream. This method showcases server-side streaming RPCs.
rpc Expand(ExpandRequest) returns (stream EchoResponse) {
Expand Down Expand Up @@ -184,21 +200,28 @@ message EchoRequest {
// The content to be echoed by the server.
string content = 1;

// A random request_id to test autopopulation
string request_id = 2 [(google.api.field_info).format = UUID4];

// The error to be thrown by the server.
google.rpc.Status error = 3;
google.rpc.Status error = 2;
}

// The severity to be echoed by the server.
Severity severity = 4;
Severity severity = 3;

// Optional. This field can be set to test the routing annotation on the Echo method.
string header = 5;
string header = 4;

// Optional. This field can be set to test the routing annotation on the Echo method.
string other_header = 6;
string other_header = 5;

// To facilitate testing of https://google.aip.dev/client-libraries/4235
string request_id = 7 [
(google.api.field_info).format = UUID4
];

// To facilitate testing of https://google.aip.dev/client-libraries/4235
optional string other_request_id = 8 [
(google.api.field_info).format = UUID4
];
}

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

// The severity specified in the request.
Severity severity = 2;

// The request ID specified or autopopulated in the request.
string request_id = 3;

// The other request ID specified or autopopulated in the request.
string other_request_id = 4;
}

// The request message used for the EchoErrorDetails method.
message EchoErrorDetailsRequest {
// Content to return in a singular `*.error.details` field of type
// `google.protobuf.Any`
string single_detail_text = 1;

// Content to return in a repeated `*.error.details` field of type
// `google.protobuf.Any`
repeated string multi_detail_text = 2;
}

// The response message used for the EchoErrorDetails method.
message EchoErrorDetailsResponse {

message SingleDetail {
ErrorWithSingleDetail error = 1;
}

message MultipleDetails {
ErrorWithMultipleDetails error = 1;
}

SingleDetail single_detail = 1;
MultipleDetails multiple_details = 2;
}

message ErrorWithSingleDetail {
google.protobuf.Any details = 1;
}

message ErrorWithMultipleDetails {
repeated google.protobuf.Any details = 1;
}

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

// The error that is thrown after all words are sent on the stream.
google.rpc.Status error = 2;

//The wait time between each server streaming messages
google.protobuf.Duration stream_wait_time = 3;
}

// The request for the PagedExpand method.
Expand Down Expand Up @@ -323,4 +389,4 @@ message BlockResponse {
// This content can contain anything, the server will not depend on a value
// here.
string content = 1;
}
}
Loading
Loading