Skip to content

Commit

Permalink
fix: support request params {key} with no =value (#436)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-fenster authored Apr 22, 2020
1 parent 924bb89 commit bd71f7c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
7 changes: 7 additions & 0 deletions baselines/dlp/src/v2/dlp_service_client.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,13 @@ export class DlpServiceClient {
options = optionsOrCallback as gax.CallOptions;
}
options = options || {};
options.otherArgs = options.otherArgs || {};
options.otherArgs.headers = options.otherArgs.headers || {};
options.otherArgs.headers[
'x-goog-request-params'
] = gax.routingHeader.fromParams({
'location_id': request.locationId || '',
});
this.initialize();
return this.innerApiCalls.listInfoTypes(request, options, callback);
}
Expand Down
30 changes: 27 additions & 3 deletions baselines/dlp/test/gapic_dlp_service_v2.ts.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,15 @@ describe('v2.DlpServiceClient', () => {
});
client.initialize();
const request = generateSampleMessage(new protos.google.privacy.dlp.v2.ListInfoTypesRequest());
const expectedOptions = {};
request.locationId = '';
const expectedHeaderRequestParams = "location_id=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedResponse = generateSampleMessage(new protos.google.privacy.dlp.v2.ListInfoTypesResponse());
client.innerApiCalls.listInfoTypes = stubSimpleCall(expectedResponse);
const [response] = await client.listInfoTypes(request);
Expand All @@ -525,7 +533,15 @@ describe('v2.DlpServiceClient', () => {
});
client.initialize();
const request = generateSampleMessage(new protos.google.privacy.dlp.v2.ListInfoTypesRequest());
const expectedOptions = {};
request.locationId = '';
const expectedHeaderRequestParams = "location_id=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedResponse = generateSampleMessage(new protos.google.privacy.dlp.v2.ListInfoTypesResponse());
client.innerApiCalls.listInfoTypes = stubSimpleCallWithCallback(expectedResponse);
const promise = new Promise((resolve, reject) => {
Expand All @@ -552,7 +568,15 @@ describe('v2.DlpServiceClient', () => {
});
client.initialize();
const request = generateSampleMessage(new protos.google.privacy.dlp.v2.ListInfoTypesRequest());
const expectedOptions = {};
request.locationId = '';
const expectedHeaderRequestParams = "location_id=";
const expectedOptions = {
otherArgs: {
headers: {
'x-goog-request-params': expectedHeaderRequestParams,
},
},
};
const expectedError = new Error('expected');
client.innerApiCalls.listInfoTypes = stubSimpleCall(undefined, expectedError);
await assert.rejects(async () => { await client.listInfoTypes(request); }, expectedError);
Expand Down
2 changes: 1 addition & 1 deletion typescript/src/schema/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ export function getSingleHeaderParam(
const message =
rule.post || rule.delete || rule.get || rule.put || rule.patch;
if (message) {
const res = message.match(/{(.*?)=/);
const res = message.match(/{(.*?)[=}]/);
return res?.[1] ? res[1].split('.') : [];
}
return [];
Expand Down

0 comments on commit bd71f7c

Please sign in to comment.