Skip to content

Commit

Permalink
fix: preserve default values in x-goog-request-params header (#251)
Browse files Browse the repository at this point in the history
- [ ] Regenerate this pull request now.

PiperOrigin-RevId: 474338479

Source-Link: googleapis/googleapis@d5d35e0

Source-Link: googleapis/googleapis-gen@efcd3f9
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiZWZjZDNmOTM5NjJhMTAzZjY4ZjAwM2UyYTFlZWNkZTZmYTIxNmEyNyJ9
  • Loading branch information
gcf-owl-bot[bot] authored Sep 14, 2022
1 parent 478dc8a commit 79e6c4f
Showing 1 changed file with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ import {PassThrough} from 'stream';

import {protobuf} from 'google-gax';

// Dynamically loaded proto JSON is needed to get the type information
// to fill in default values for request objects
const root = protobuf.Root.fromJSON(
require('../protos/protos.json')
).resolveAll();

// eslint-disable-next-line @typescript-eslint/no-unused-vars
function getTypeDefaultValue(typeName: string, fields: string[]) {
let type = root.lookupType(typeName) as protobuf.Type;
for (const field of fields.slice(0, -1)) {
type = type.fields[field]?.resolvedType as protobuf.Type;
}
return type.fields[fields[fields.length - 1]]?.defaultValue;
}

function generateSampleMessage<T extends object>(instance: T) {
const filledObject = (
instance.constructor as typeof protobuf.Message
Expand Down Expand Up @@ -186,6 +201,7 @@ describe('v1beta1.SpeechTranslationServiceClient', () => {
const request = generateSampleMessage(
new protos.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechRequest()
);

const expectedResponse = generateSampleMessage(
new protos.google.cloud.mediatranslation.v1beta1.StreamingTranslateSpeechResponse()
);
Expand Down

0 comments on commit 79e6c4f

Please sign in to comment.