return uninterpreted options as an array

This commit is contained in:
Christopher Fenn 2024-04-05 17:12:04 +02:00
parent 6e441a8d03
commit e6ac1a49ed
2 changed files with 15 additions and 4 deletions

View File

@ -250,7 +250,18 @@ function createSerializer(cls: Protobuf.Type): Serialize<object> {
} }
function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions { function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions {
return (options || []).reduce((obj: MethodOptions, item: Partial<MethodOptions>) => ({ ...obj, ...item }), return (options || []).reduce((obj: MethodOptions, item: Partial<MethodOptions>) => {
for (const [key, value] of Object.entries(item)) {
switch (key) {
case 'uninterpreted_option' :
obj.uninterpreted_option.push(item.uninterpreted_option as UninterpretedOption);
break;
default:
obj[key] = value
}
}
return obj
},
{ {
deprecated: false, deprecated: false,
idempotency_level: IdempotencyLevel.IDEMPOTENCY_UNKNOWN, idempotency_level: IdempotencyLevel.IDEMPOTENCY_UNKNOWN,

View File

@ -140,10 +140,10 @@ describe('Descriptor types', () => {
assert.deepStrictEqual(service.Hello.options, { assert.deepStrictEqual(service.Hello.options, {
deprecated: true, deprecated: true,
idempotency_level: 'NO_SIDE_EFFECTS', idempotency_level: 'NO_SIDE_EFFECTS',
uninterpreted_option: { uninterpreted_option: [{
name: { name: {
name_part: 'foo', name_part: 'foo',
is_extension: false, is_extension: false,
}, },
identifier_value: 'bar', identifier_value: 'bar',
positive_int_value: 9007199254740991, positive_int_value: 9007199254740991,
@ -151,7 +151,7 @@ describe('Descriptor types', () => {
double_value: 1.2345, double_value: 1.2345,
string_value: 'foobar', string_value: 'foobar',
aggregate_value: 'foobar' aggregate_value: 'foobar'
}, }],
'(google.api.http)': { '(google.api.http)': {
post: '/hello', post: '/hello',
body: '*', body: '*',