Repository navigation
fix(parser): add a schema for each API Gateway WebSocket event - #6002
Manishram-ai wants to merge 2 commits into
Conversation
The WebSocket schema required the REQUEST authorizer fields and the route fields together, so no event API Gateway sends matched it. Add one schema per event, for $connect, messages and $disconnect, and rebuild APIGatewayProxyWebsocketEventSchema as a union of the three.
dreamorosi
left a comment
There was a problem hiding this comment.
Thanks for this @Manishram-ai, and sorry for changing direction after you've done the work.
Reviewing the union showed us that it doesn't keep existing code working the way we hoped. Code that calls .extend(), .omit() or .pick() on APIGatewayProxyWebsocketEventSchema stops compiling, because those methods don't exist on a union. The inferred type also changes, and TypeScript can't narrow the union from the nested requestContext.eventType. Python doesn't have a catch-all model either.
So let's keep the three new schemas and drop the union:
- Restore
APIGatewayProxyWebsocketEventSchemaand itsAPIGatewayProxyWebsocketEventtype exactly as they are onmain, and mark both@deprecated. Point to the three new schemas and say it will be removed in the next major version.BatchProcessorSynchas the wording we use. - Remove the union tests. Keep one test that parses
connectEvent.jsonwith the deprecated schema, so it stays covered until we remove it. - In
docs/features/parser.md, mark theAPIGatewayProxyWebsocketEventSchemarow as deprecated instead of describing it as covering every WebSocket event. - Update the PR description to match.
The rest looks good. The per-event schemas, the test events and the tests are what we asked for.
|
No problem, that makes sense. The union is gone in e37727d. |
Summary
APIGatewayProxyWebsocketEventSchemarequired the REQUEST authorizer fields and the route fields together, so no event API Gateway sends to a WebSocket route matched it. As discussed in #6000, this adds one schema per event, like the Python models, and keeps the old schema as it is, marked as deprecated.Changes
APIGatewayWebSocketConnectEventSchema,APIGatewayWebSocketMessageEventSchemaandAPIGatewayWebSocketDisconnectEventSchema, each with a literaleventTypeand, for$connectand$disconnect, a literalrouteKey. Message events now havemessageId, disconnect events havedisconnectStatusCodeanddisconnectReason, and connect events keep the optional query string fields.APIGatewayWebSocketConnectEvent,APIGatewayWebSocketMessageEventandAPIGatewayWebSocketDisconnectEventtypes.APIGatewayProxyWebsocketEventSchemaand itsAPIGatewayProxyWebsocketEventtype are unchanged frommainand marked@deprecated, pointing to the three new schemas and saying they will be removed in the next major version.connect.json,message.jsonanddisconnect.jsontest events, based on the WebSocket test events in Powertools for AWS Lambda (Python). The deprecated schema rejects all three.messageIdand a disconnect event withoutdisconnectStatusCodeare rejected. One test still parsesconnectEvent.jsonwith the deprecated schema.docs/features/parser.mdlists the new schemas and marksAPIGatewayProxyWebsocketEventSchemaas deprecated.$connectauthorizer event is left out, as you suggested.npm run test:unit:coverage(coverage stays at 100%),npm run lint,npm run build:testsandnpm run test:unit:typespass inpackages/parser, and markdownlint passes on the docs page.Issue number: closes #6000
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.