Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aws_lambda_powertools/event_handler/api_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ def _openapi_operation_request_body(
if required:
request_body_oai["required"] = required

if field_info.description:
request_body_oai["description"] = field_info.description

# Generate the request body media type
request_media_content: Dict[str, Any] = {"schema": body_schema}
request_body_oai["content"] = {request_media_type: request_media_content}
Expand Down
24 changes: 24 additions & 0 deletions tests/functional/event_handler/test_openapi_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,30 @@ def handler(user: Annotated[User, Body(embed=True)]):
assert body_post_handler_schema.properties["user"].ref == "#/components/schemas/User"


def test_openapi_with_body_description():
app = APIGatewayRestResolver()

class User(BaseModel):
name: str

@app.post("/users")
def handler(user: Annotated[User, Body(description="This is a user")]):
print(user)

schema = app.get_openapi_schema()
assert len(schema.paths.keys()) == 1

post = schema.paths["/users"].post
assert post.parameters is None
assert post.requestBody is not None

request_body = post.requestBody

# Description should appear in two places: on the request body and on the schema
assert request_body.description == "This is a user"
assert request_body.content[JSON_CONTENT_TYPE].schema_.description == "This is a user"


def test_openapi_with_excluded_operations():
app = APIGatewayRestResolver()

Expand Down