Skip to content

feat(event_handler): adding status_code OpenAPI field#8130

Merged
leandrodamascena merged 4 commits intodevelopfrom
feat/7496-custom-status-code-openapi
Apr 8, 2026
Merged

feat(event_handler): adding status_code OpenAPI field#8130
leandrodamascena merged 4 commits intodevelopfrom
feat/7496-custom-status-code-openapi

Conversation

@leandrodamascena
Copy link
Copy Markdown
Contributor

Issue number: closes #7496

Summary

Adding status_code field.

Changes

Please provide a summary of what's being changed

User experience

import requests

from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.typing import LambdaContext

app = APIGatewayRestResolver(enable_validation=True)


@app.get(
    "/todos/<todo_id>",
    summary="Retrieves a todo item",
    description="Loads a todo item identified by the `todo_id`",
    response_description="The todo object",
    responses={
        200: {"description": "Todo item found"},
        404: {
            "description": "Item not found",
        },
    },
    tags=["Todos"],
)
def get_todo_title(todo_id: int) -> str:
    todo = requests.get(f"https://jsonplaceholder.typicode.com/todos/{todo_id}")
    todo.raise_for_status()

    return todo.json()["title"]


@app.post(
    "/todos",
    summary="Creates a new todo item",
    description="Creates a new todo item and returns it",
    response_description="The created todo object",
    status_code=201,
    tags=["Todos"],
)
def create_todo(title: str) -> dict:
    return {"id": 1, "title": title}


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

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 as a code owner April 8, 2026 07:11
@boring-cyborg boring-cyborg bot added documentation Improvements or additions to documentation event_handlers tests labels Apr 8, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 8, 2026
@leandrodamascena leandrodamascena requested a review from svozza April 8, 2026 07:14
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.68%. Comparing base (4cb9997) to head (e322e5d).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8130   +/-   ##
========================================
  Coverage    96.68%   96.68%           
========================================
  Files          285      285           
  Lines        14187    14190    +3     
  Branches      1175     1175           
========================================
+ Hits         13717    13720    +3     
  Misses         341      341           
  Partials       129      129           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leandrodamascena
Copy link
Copy Markdown
Contributor Author

Hey @svozza can I have a review here?

@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 8, 2026
@leandrodamascena leandrodamascena requested a review from svozza April 8, 2026 15:13
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 8, 2026
@powertools-for-aws-oss-automation powertools-for-aws-oss-automation bot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 8, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@leandrodamascena leandrodamascena merged commit 45d25e9 into develop Apr 8, 2026
8 checks passed
@leandrodamascena leandrodamascena deleted the feat/7496-custom-status-code-openapi branch April 8, 2026 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation event_handlers 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.

Feature request: Support custom status codes of fine-grained responses for OpenAPI spec generation

2 participants