aws-powertools/powertools-lambda-python

Feature request: Support Form object in APIGatewayRestResolver

oyiz-michael opened this issue · 5 comments

Use case

I’m building a multi-region AWS Lambda API that accepts:

Custom headers for client identification (e.g., X-Customer-Id)
Multipart/form-data uploads (CSV files up to 5 MB)

Today Powertools’ APIGatewayRestResolver generates an OpenAPI spec that omits header parameters and file/form bodies, so our consumers cannot rely on the spec for validation or client generation. We end up hand-editing the JSON, which breaks the “single-source-of-truth” goal of Powertools.

Solution/User Experience

Extend OpenAPIConverter so that when a handler parameter is typed as File or bytes (or annotated with content_type="multipart/form-data"), it generates the correct OpenAPI 3.0 schema:

requestBody:
  content:
    multipart/form-data:
      schema:
        type: object
        properties:
          file:
            type: string
            format: binary

Add header-parameter support
parameters:
- in: header
  name: X-Customer-Id
  schema:
    type: string
  required: true

### Alternative solutions

```markdown
Alternative solutions(third text-area lower down)

markdown
We can manually patch the generated OpenAPI JSON or maintain a separate spec file, but that loses all the benefits of automatic generation and risks drift between code and documentation.

Acknowledgment

Thanks for opening your first issue here! We'll come back to you as soon as we can.
In the meantime, check out the #python channel on our Powertools for AWS Lambda Discord: Invite link

Happy to implement—let me know if any changes needed.

Hey @oyiz-michael thanks a lot for opening this issue! Actually we support headers (https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#validating-headers) but we don't support form/files in the OpenAPI spec yet. I'd love to have your contribution here!

We already have an issue open for this and I can link it here.

Please let me know if you need any help when implementing it. Feel free to submit a PR even you think the code is not complete, we can work together to get it merged.

Warning

This issue is now closed. Please be mindful that future comments are hard for our team to see.
If you need more assistance, please either reopen the issue, or open a new issue referencing this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

This is now released under 3.18.0 version!