-
-
Notifications
You must be signed in to change notification settings - Fork 491
Open
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected
Description
Description
When using the body reserved keyword parameter in the route definition, no requestBody is generated in the OpenAPI spec.
Related: https://github.com/orgs/litestar-org/discussions/3038
Root Cause
litestar/litestar/_openapi/path_item.py
Lines 64 to 68 in bcea856
| request_body = None | |
| if data_field := signature_fields.get("data"): | |
| request_body = create_request_body( | |
| self.context, route_handler.handler_id, route_handler.data_dto, data_field | |
| ) |
The code above only checks data.
Please let me know whether not checking for body is intentional; if it isn't, I'm happy to submit a PR with a fix.
URL to code causing the issue
No response
MCVE
from litestar import Litestar, post
from litestar.response import Response
from litestar.status_codes import HTTP_201_CREATED
@post(
path="/upload/",
operation_id="upload_binary",
status_code=HTTP_201_CREATED,
)
async def upload_binary(
body: bytes,
# body: bytes = Body(media_type="application/octet-stream"), # <-- does not work as well
) -> Response[dict[str, str]]:
return Response(
content={
"message": "Data uploaded successfully",
"size": len(body),
},
status_code=HTTP_201_CREATED,
)
app = Litestar(route_handlers=[upload_binary])Steps to reproduce
- Create the above file and save to
app.py litestar runcurl -O http://localhost:8000/schema/openapi.yamlcat openapi.yaml
components:
schemas: {}
info:
title: Litestar API
version: 1.0.0
openapi: 3.1.0
paths:
/upload:
post:
deprecated: false
operationId: upload_binary
responses:
'201':
content:
application/json:
schema:
additionalProperties:
type: string
type: object
description: Document created, URL follows
headers: {}
summary: UploadBinary
servers:
- url: /I believe the output should look like this:
paths:
/upload:
post:
operationId: upload_binary
requestBody: # ← Should be present
required: true
content:
application/octet-stream:
schema:
type: string
format: binaryNaturally, this results in incorrect OpenAPI client generation.
Screenshots
No response
Logs
Litestar Version
2.18.0
Platform
- Linux
- Mac
- Windows
- Other (Please specify in the description above)
Metadata
Metadata
Assignees
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected