Skip to content

RFC: Support OpenAPI generation for micro functions via CLI/script #3704

Closed
@ran-isenberg

Description

@ran-isenberg

Is this related to an existing feature request or issue?

No response

Which Powertools for AWS Lambda (Python) utility does this relate to?

Event Handler - REST API

Summary

Hi,
I'd like to use event handler with event validation turned on for my micro functions service. At the moment, the /swagger generation is done via one endpoint and unless that handler defines all routes in the app, there's no way to generate all the routes for the OpenAPI.

Use case

I have a service with multiple micro function, I'm not a fan of mono lambda for large service.
In addition, I'm more interested in generating the OpenAPI doc offline and saving it to my service repository where it can be later published to various location, and not necessarily served via the rest endpoint.

Proposal

Create a CLI that I can run locally on my service in the shell that generates the OpenAPI doc. It will need to init the event handler and it's all uses in the different lambda handlers and then generate the document and save it to a destination folder in a JSON format.
I have created a CLI that works with the current implementation - it accesses the deployed API GW at the /swagger?format=json and saves the output. Now, this is obviously not the solution, but it's an example of a possible interface (replace stack output input with the lambda handlers folder patch and it might be enough.

Here's the current CLI:
https://github.com/ran-isenberg/aws-lambda-handler-cookbook/blob/main/generate_openapi.py

Out of scope

I have added this script as a makefile command of my AWS Lambda handler cookbook and now it's part of my CI/CD pipeline where I can fail PRs if developers added/changed the REST API but forgot to update the documentation. Expect a blog post about it very soon :)

Potential challenges

Thanks @leandrodamascena for this section:

    • OS compatibility: It's a CLI, we'll make sure it works on at least Windows, Linux and Mac.
    • Security: what are the possible problems when we provide a CLI (even if it is pure python code) to install on someone' computer?
      3 - Performance: do we need to worry about any performance issues? - i dont think so, it runs locally,. can be several seconds at max.

Please note that it can even be just a script that i can run from powertools library.

Dependencies and Integrations

No response

Alternative solutions

No response

Acknowledgment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions