Skip to content

Commit

Permalink
return uninterpreted options as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
n0v1 committed Apr 5, 2024
1 parent 6e441a8 commit e6ac1a4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion packages/proto-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,18 @@ function createSerializer(cls: Protobuf.Type): Serialize<object> {
}

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,
idempotency_level: IdempotencyLevel.IDEMPOTENCY_UNKNOWN,
Expand Down
6 changes: 3 additions & 3 deletions packages/proto-loader/test/descriptor_type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,18 +140,18 @@ describe('Descriptor types', () => {
assert.deepStrictEqual(service.Hello.options, {
deprecated: true,
idempotency_level: 'NO_SIDE_EFFECTS',
uninterpreted_option: {
uninterpreted_option: [{
name: {
name_part: 'foo',
is_extension: false,
is_extension: false,
},
identifier_value: 'bar',
positive_int_value: 9007199254740991,
negative_int_value: -9007199254740991,
double_value: 1.2345,
string_value: 'foobar',
aggregate_value: 'foobar'
},
}],
'(google.api.http)': {
post: '/hello',
body: '*',
Expand Down

0 comments on commit e6ac1a4

Please sign in to comment.