diff --git a/src/adapters/helpers/lambdaEvent.ts b/src/adapters/helpers/lambdaEvent.ts index d659fd6..c973567 100644 --- a/src/adapters/helpers/lambdaEvent.ts +++ b/src/adapters/helpers/lambdaEvent.ts @@ -13,16 +13,18 @@ export const lambdaEvent = (config: AlphaOptions, relativeUrl?: string) => { 'http://fake', querystringWithArraySupport, ); - const params = Object.assign({}, parts.query, config.params); - const multiValueQueryStringParameters: Record = { ...params }; + const params: Record = Object.assign({}, parts.query, config.params); + let multiValueParams: Record | null = null; - Object.keys(multiValueQueryStringParameters).forEach((key) => { - if (!Array.isArray(multiValueQueryStringParameters[key])) { - delete multiValueQueryStringParameters[key]; - } else { - delete params[key]; - } - }); + const hasMultiValueParams = Object.values(params).some((value) => Array.isArray(value)); + + if (hasMultiValueParams) { + Object.entries(params).forEach(([key, value]) => { + multiValueParams = multiValueParams || {}; + multiValueParams[key] = Array.isArray(value) ? value : [value]; + params[key] = Array.isArray(value) ? value.join(',') : value; + }); + } const httpMethod = (config.method as string).toUpperCase(); const requestTime = new Date(); @@ -73,10 +75,7 @@ export const lambdaEvent = (config: AlphaOptions, relativeUrl?: string) => { userArn: null, }, }, - multiValueQueryStringParameters: - Object.keys(multiValueQueryStringParameters).length > 0 - ? multiValueQueryStringParameters - : null, + multiValueQueryStringParameters: multiValueParams, }; if (Buffer.isBuffer(event.body)) { diff --git a/test/lambda-event.test.ts b/test/lambda-event.test.ts index bbf9431..658d706 100644 --- a/test/lambda-event.test.ts +++ b/test/lambda-event.test.ts @@ -31,6 +31,7 @@ test('Can parse URLs with duplicate parameters', () => { httpMethod: 'GET', path: '/lifeomic/dstu3/Questionnaire', queryStringParameters: { + _tag: 'http://lifeomic.com/fhir/questionnaire-type|survey-form,http://lifeomic.com/fhir/dataset|0bb18fef-4e2d-4b91-a623-09527265a8b3,http://lifeomic.com/fhir/primary|0343bfcf-4e2d-4b91-a623-095272783bf3', pageSize: '25', }, multiValueQueryStringParameters: { @@ -39,6 +40,7 @@ test('Can parse URLs with duplicate parameters', () => { 'http://lifeomic.com/fhir/dataset|0bb18fef-4e2d-4b91-a623-09527265a8b3', 'http://lifeomic.com/fhir/primary|0343bfcf-4e2d-4b91-a623-095272783bf3', ], + pageSize: ['25'], }, })); assertRequestId(result);