Skip to content

Bug: Can not use examples element in reponse of post or get method #7543

@nashthaiphung

Description

@nashthaiphung

Expected Behaviour

After run get_openapi_json_schema() which will auto generate examples in response of 404.

Image Image

Current Behaviour

In Amazon Bedrock Agents, I want to create multiple example JSON for a HTTP response. But when I add examples element in Post or Get method, it is renamed to "example" (non suffix 's') in JSON Schema

@app.post(
    "/check_data",
    responses={
        404: {
            "description": "Data not found or don't match ",
            "content": {
                "application/json": {
                    "schema": ResErrorBody.model_json_schema(), 
                    "examples": {
                        "PolicyNotFoundCase1": {
                            "summary": "error case 1",
                            "description": "404 case 1.",
                            "value": {
                                  "error-code": "ERROR-404-NOT-FOUND",
                                  "message": "01",
                              }
                        },
                       "PolicyNotFoundCase2": {
                            "summary": "error case 2",
                            "description": "404 case 2.",
                            "value": {
                                  "error-code": "ERROR-404-NOT-FOUND",
                                  "message": "01",
                                  "tool-name": "test"
                              }
                        }
                    }
                }
            }
        },
        422: {
            "description": "Validation Error"
            # ... 
        }
    }
)

Code snippet

@app.post(
    "/check_data",
    responses={
        404: {
            "description": "Data not found or don't match ",
            "content": {
                "application/json": {
                    "schema": ResErrorBody.model_json_schema(), 
                    "examples": {
                        "PolicyNotFoundCase1": {
                            "summary": "error case 1",
                            "description": "404 case 1.",
                            "value": {
                                  "error-code": "ERROR-404-NOT-FOUND",
                                  "message": "01",
                              }
                        },
                       "PolicyNotFoundCase2": {
                            "summary": "error case 2",
                            "description": "404 case 2.",
                            "value": {
                                  "error-code": "ERROR-404-NOT-FOUND",
                                  "message": "01",
                                  "tool-name": "test"
                              }
                        }
                    }
                }
            }
        }
    }
)

Possible Solution

No response

Steps to Reproduce

In Amazon Bedrock Agents, white code to create a OpenAPI-based Actions with POST or GET method

Powertools for AWS Lambda (Python) version

3.20.0

AWS Lambda function runtime

3.9

Packaging format used

Lambda Layers

Debugging logs

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

Status

Coming soon

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions