Skip to content

Conversation

leandrodamascena
Copy link
Contributor

Issue number: #5587

Summary

Changes

This feature enhances API documentation by introducing a new openapi_examples field for parameters defined in the function, allowing developers to provide concrete examples directly in schema objects.

User experience

from typing import Annotated

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.typing import LambdaContext
from aws_lambda_powertools.event_handler.openapi.params import Query
from aws_lambda_powertools.event_handler.openapi.models import Example

app = APIGatewayRestResolver(enable_validation=True)
app.enable_swagger(path="/swagger")  # (1)!

example1 = Example(summary="Example1", description="Example1", value="b")

@app.get("/todos")
def create_todo(todo: Annotated[int, Query(
            openapi_examples={
                    "first_example": example1,
                }
            )]) -> int:  

    return 1


def lambda_handler(event: dict, context: LambdaContext) -> dict:
    return app.resolve(event, context)

image

Checklist

If your change doesn't seem to apply, please leave them unchecked.

Is this a breaking change?

RFC issue number:

Checklist:

  • Migration process documented
  • Implement warnings (if it can live side by side)

Acknowledgment

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.

@leandrodamascena leandrodamascena requested a review from a team February 12, 2025 18:33
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation event_handlers tests labels Feb 12, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 12, 2025
@leandrodamascena leandrodamascena self-assigned this Feb 12, 2025
@github-actions github-actions bot added feature New feature or functionality and removed documentation Improvements or additions to documentation labels Feb 12, 2025
@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Feb 12, 2025
@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Feb 12, 2025
@codecov
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.26%. Comparing base (df75e42) to head (e4cff52).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #6086   +/-   ##
========================================
  Coverage    96.26%   96.26%           
========================================
  Files          234      234           
  Lines        11160    11165    +5     
  Branches       828      830    +2     
========================================
+ Hits         10743    10748    +5     
  Misses         327      327           
  Partials        90       90           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@boring-cyborg boring-cyborg bot added the documentation Improvements or additions to documentation label Feb 17, 2025
Copy link
Contributor

@anafalcao anafalcao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED!

@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Feb 17, 2025
@sonarqubecloud
Copy link

@leandrodamascena leandrodamascena merged commit af5e6be into develop Feb 17, 2025
13 checks passed
@leandrodamascena leandrodamascena deleted the feature/openapi_examples branch February 17, 2025 13:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

event_handlers feature New feature or functionality size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Examples should serialize under parameters when using Path parameters

2 participants