-
Notifications
You must be signed in to change notification settings - Fork 469
feat(openapi): add support for micro Lambda pattern #7920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
|
2 similar comments
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #7920 +/- ##
===========================================
- Coverage 96.72% 96.70% -0.02%
===========================================
Files 275 277 +2
Lines 13214 13411 +197
Branches 1006 1054 +48
===========================================
+ Hits 12781 12969 +188
- Misses 325 327 +2
- Partials 108 115 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hey @dreamorosi and @svozza I'd like a review here. Pls read the PR body before the review. I'm still fixing some coverage issues. |
|
|
yes, this is so overdue!!!! Thank you! |
dreamorosi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree with the approach suggested of having a runtime implementation over a CLI or similar.
I'll leave the technical review of the PR to Stefano - if you want a second pair of eyes you can also involve @sdangol since he's been working on Event Handler as well.
| # THEN it should return merged schema | ||
| body = json.loads(response["body"]) | ||
| assert body["info"]["title"] == "Swagger Merge API" | ||
| assert "/users" in body["paths"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this validation sufficient? Don't these paths have other properties we might want to validate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, but this is already tested in a bunch of other places, like here and in other methods that uses the swagger.
I think we are safe testing only these props.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, sorry I missed that bit below!



Issue number: closes #7919
Original Disucssion: #5914
Documentation will come in a separate PR. I'm refactoring the OpenAPI docs.
Summary
This PR adds support for generating unified OpenAPI schemas from multiple Lambda handlers.
This is an old desire from customers that don't use Fat Lambda architecture. When you have micro-functions (one Lambda per route), each Lambda has its own resolver and generates its own OpenAPI spec. This feature allows merging all specs into a single unified schema.
Implementation and security concerns
Some customers suggested a CLI approach, but that could introduce security concerns with arbitrary code execution.
This is pure Python with the customer in control of paths, patterns, and exclusions. Discovery uses AST analysis to detect resolver instances - no code is executed during discovery, just static analysis. The actual schema generation only happens when the customer explicitly calls
get_openapi_schema().Changes
New
OpenAPIMergeclass andconfigure_openapi_merge()method to discover and merge OpenAPI schemas from multiple Lambda function handlers into a single specification.1.
OpenAPIMergeclass - Standalone class to generate the schema file via Python code. Write a simple script, run it, get youropenapi.json.2.
configure_openapi_merge()method - For customers who want a dedicated Lambda to serve the OpenAPI spec and Swagger UI. This Lambda only serves the merged schema - it won't execute the actual route handlers since each route lives in its own Lambda function. The routes in the schema point to API Gateway, which routes to the correct Lambda.Conflict handling
When the same path+method exists in multiple handlers, use
on_conflict:warn(default): logs warning, keeps firsterror: raises OpenAPIMergeErrorfirst: silently keeps firstlast: uses last (override)Files are sorted alphabetically, so precedence is deterministic.
Supported resolvers
All of them: APIGatewayRestResolver, APIGatewayHttpResolver, ALBResolver, LambdaFunctionUrlResolver, VPCLatticeResolver, VPCLatticeV2Resolver, BedrockAgentResolver.
User experience
Standalone
Via resolver (runtime, Swagger UI)
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.