Skip to content

Commit 7ce5b3c

Browse files
blytheaw1482568
and
1482568
authored
fix(parser): set APIGatewayProxyEventSchema body and query string keys to be nullable (#2465)
Co-authored-by: 1482568 <[email protected]>
1 parent 1f6cc41 commit 7ce5b3c

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

Diff for: packages/parser/src/schemas/apigw.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ const APIGatewayProxyEventSchema = z.object({
9797
'OPTIONS',
9898
]),
9999
headers: z.record(z.string()).optional(),
100-
queryStringParameters: z.record(z.string()).optional(),
100+
queryStringParameters: z.record(z.string()).nullable(),
101101
multiValueHeaders: z.record(z.array(z.string())).optional(),
102-
multiValueQueryStringParameters: z.record(z.array(z.string())).optional(),
102+
multiValueQueryStringParameters: z.record(z.array(z.string())).nullable(),
103103
requestContext: APIGatewayEventRequestContext,
104104
pathParameters: z.record(z.string()).optional().nullish(),
105105
stageVariables: z.record(z.string()).optional().nullish(),
106106
isBase64Encoded: z.boolean().optional(),
107-
body: z.string().optional(),
107+
body: z.string().nullable(),
108108
});
109109

110110
export { APIGatewayProxyEventSchema, APIGatewayCert };

Diff for: packages/parser/tests/events/apiGatewayAuthorizerRequestEvent.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
"queryStringParameters": {
2121
"QueryString1": "queryValue1"
2222
},
23+
"multiValueQueryStringParameters": {
24+
"QueryString1": ["queryValue1"]
25+
},
2326
"pathParameters": {},
2427
"stageVariables": {
2528
"StageVar1": "stageValue1"
@@ -64,5 +67,6 @@
6467
"resourceId": "ANY /request",
6568
"resourcePath": "/request",
6669
"stage": "test"
67-
}
70+
},
71+
"body": null
6872
}

Diff for: packages/parser/tests/unit/envelopes/apigwt.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ describe('ApigwEnvelope ', () => {
2424

2525
it('should throw no body provided', () => {
2626
const testEvent = TestEvents.apiGatewayProxyEvent as APIGatewayProxyEvent;
27-
testEvent.body = undefined;
27+
testEvent.body = null;
2828

2929
expect(() => ApiGatewayEnvelope.parse(testEvent, TestSchema)).toThrow(
3030
ParseError
@@ -56,7 +56,7 @@ describe('ApigwEnvelope ', () => {
5656

5757
it('should return success false with original body if no body provided', () => {
5858
const testEvent = TestEvents.apiGatewayProxyEvent as APIGatewayProxyEvent;
59-
testEvent.body = undefined;
59+
testEvent.body = null;
6060

6161
const resp = ApiGatewayEnvelope.safeParse(testEvent, TestSchema);
6262
expect(resp).toEqual({

0 commit comments

Comments
 (0)