adjust implementation to always return default options

This commit is contained in:
Christopher Fenn 2024-04-05 16:23:29 +02:00
parent 99e8a060f6
commit 27d608763b
2 changed files with 12 additions and 5 deletions

View File

@ -249,10 +249,13 @@ function createSerializer(cls: Protobuf.Type): Serialize<object> {
};
}
function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions | undefined {
return Array.isArray(options) ?
options.reduce((obj: MethodOptions, item: Partial<MethodOptions>) => ({ ...obj, ...item }), {}) :
undefined;
function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions {
return (options || []).reduce((obj: MethodOptions, item: Partial<MethodOptions>) => ({ ...obj, ...item }),
{
deprecated: false,
idempotency_level: IdempotencyLevel.IDEMPOTENCY_UNKNOWN,
uninterpreted_option: []
});
}
function createMethodDefinition(

View File

@ -160,6 +160,10 @@ describe('Descriptor types', () => {
},
'(google.api.method_signature)': 'bar'
})
assert(service.HelloWithoutOptions.options === undefined)
assert.deepStrictEqual(service.HelloWithoutOptions.options, {
deprecated: false,
idempotency_level: 'IDEMPOTENCY_UNKNOWN',
uninterpreted_option: []
})
})
});