Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug: Body openapi_examples should be included in openapi schema #7860

Open
Labels
bugSomething isn't working triagePending triage from maintainers
@facu-01

Description

Expected Behaviour

The openapi_examples from Body, should be included in the openapi schema, under examples.

@app.post("/todos")
def create_todo(todo: Annotated[Todo, Body(
 openapi_examples={
 "example1": {
 "summary": "A simple todo example",
 "description": "A simple todo example with title and completed status",
 "value": {
 "title": "Buy groceries",
 "completed": False
 }
 },
 "example2": {
 "summary": "A tagged todo example",
 "description": "A todo example with a tag",
 "value": {
 "title": "Read a book",
 "completed": True,
 "tag": "leisure"
 }}
 })]
 ) -> str: 
 
 return "test" 

openapi schema:

 "requestBody": {
 "content": {
 "application/json": {
 "schema": {
 "$ref": "#/components/schemas/Todo"
 },
 "examples": {
 "example1": {
 "summary": "A simple todo example",
 "description": "A simple todo example with title and completed status",
 "value": {
 "title": "Buy groceries",
 "completed": false
 }
 },
 "example2": {
 "summary": "A tagged todo example",
 "description": "A todo example with a tag",
 "value": {
 "title": "Read a book",
 "completed": true,
 "tag": "leisure"
 }
 }
 }
 }
 },
 "required": true
 },

Current Behaviour

The openapi_examples gets ignored,

Code snippet

from typing import Optional, Annotated
from pydantic import BaseModel
from aws_lambda_powertools.event_handler.openapi.params import Body
from aws_lambda_powertools.event_handler import APIGatewayRestResolver
from aws_lambda_powertools.utilities.typing import LambdaContext
app = APIGatewayRestResolver(enable_validation=True) 
class Todo(BaseModel): 
 title: str
 completed: bool
 tag: Optional[str] = None
@app.post("/todos")
def create_todo(todo: Annotated[Todo, Body(
 openapi_examples={
 "example1": {
 "summary": "A simple todo example",
 "description": "A simple todo example with title and completed status",
 "value": {
 "title": "Buy groceries",
 "completed": False
 }
 },
 "example2": {
 "summary": "A tagged todo example",
 "description": "A todo example with a tag",
 "value": {
 "title": "Read a book",
 "completed": True,
 "tag": "leisure"
 }}
 })]
 ) -> str: 
 
 return "test" 
def lambda_handler(event: dict, context: LambdaContext) -> dict:
 return app.resolve(event, context)
if __name__ == "__main__":
 # generate openapi.json
 openapi_schema = app.get_openapi_json_schema()
 with open("openapi.json", "w") as f:
 f.write(openapi_schema)

Possible Solution

Modify the Body class and Route class to handle the openapi_examples.

Steps to Reproduce

Run python.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.13

Packaging format used

PyPi

Debugging logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working triagePending triage from maintainers

    Type

    No type

    Projects

    Status

    Triage

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /