Skip to content

Commit

Permalink
fix(@whook/aws-lambda): fix query parameters parsing when AWS sets it…
Browse files Browse the repository at this point in the history
… to null
  • Loading branch information
nfroidure committed Nov 6, 2020
1 parent d8318ad commit 89ebc66
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/whook-aws-lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"dependencies": {
"@whook/cli": "^5.1.6",
"@whook/http-router": "^5.1.6",
"@whook/http-transaction": "^5.1.4",
"@whook/whook": "^5.1.6",
"ajv": "^6.12.6",
"bytes": "^3.1.0",
Expand Down
11 changes: 6 additions & 5 deletions packages/whook-aws-lambda/src/wrappers/awsHTTPLambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
extractOperationSecurityParameters,
castParameters,
} from '@whook/http-router';
import { reuseSpecialProps, alsoInject, HandlerInitializer } from 'knifecycle';
import { reuseSpecialProps, alsoInject } from 'knifecycle';
import Ajv from 'ajv';
import bytes from 'bytes';
import HTTPError from 'yhttperror';
Expand All @@ -30,7 +30,7 @@ import {
import stream from 'stream';
import qs from 'qs';
import { noop, compose } from '@whook/whook';
import type { ServiceInitializer } from 'knifecycle';
import type { ServiceInitializer, HandlerInitializer } from 'knifecycle';
import type {
WhookRequest,
WhookResponse,
Expand All @@ -42,6 +42,7 @@ import type {
} from '@whook/whook';
import type { TimeService, LogService } from 'common-services';
import type { OpenAPIV3 } from 'openapi-types';
import type { DereferencedParameterObject } from '@whook/http-transaction';

type HTTPWrapperDependencies = {
NODE_ENV: string;
Expand Down Expand Up @@ -269,7 +270,7 @@ async function handleForAWSHTTPLambda(
...(event.pathParameters || {}),
...filterQueryParameters(
operationParameters,
event.multiValueQueryStringParameters,
event.multiValueQueryStringParameters || {},
),
...filterHeaders(operationParameters, request.headers),
};
Expand Down Expand Up @@ -555,14 +556,14 @@ function obfuscateEventBody(obfuscator, rawBody) {
}

function filterQueryParameters(
parameters: OpenAPIV3.ParameterObject[],
parameters: DereferencedParameterObject[],
queryParameters: { [name: string]: string[] },
): { [name: string]: string } {
return (parameters || [])
.filter((parameter) => 'query' === parameter.in)
.reduce((filteredHeaders, parameter) => {
if (queryParameters[parameter.name]) {
if ((parameter.schema as OpenAPIV3.SchemaObject).type === 'array') {
if (parameter.schema.type === 'array') {
filteredHeaders[parameter.name] = queryParameters[parameter.name];
} else {
filteredHeaders[parameter.name] = queryParameters[parameter.name][0];
Expand Down

0 comments on commit 89ebc66

Please sign in to comment.