-
-
Notifications
You must be signed in to change notification settings - Fork 449
Open
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected
Description
Description
Hi,
when creating the Openapi schema there is a different behavior for generating the schema names.
When I create a route with a dataclass, the Openapi schema is generated with the dataclass name.
However, if I use a DTO wrapper, a completely different name is generated.
Is there a way to specify the name for a DTO class individually?
URL to code causing the issue
No response
MCVE
from litestar.dto import DataclassDTO
@dataclass
class App:
id: int
name: str
description: str
@dataclass
class AppCreate:
name: str
description: str
class AppCreateDto(DataclassDTO[AppCreate]):
pass
...
class AppController(Controller):
"""Handles the interactions within the App objects."""
tags = ["Apps"]
# Variant 1 with dto:
@post(
path="/app",
operation_id="create_app",
name="apps:create",
summary="Create App",
dto=AppCreateDto,
)
async def create_app(
self,
data: DTOData[AppCreate]
) -> App:
# Do something and return App
...
# Variant 2 without dto:
@post(
path="/app",
operation_id="create_app",
name="apps:create",
summary="Create App",
)
async def create_app(
self,
data: AppCreate
) -> App:
# Do something and return App
...
....
```json
with dto:
"paths": {
"/app_dto": {
"post": {
"tags": [
"Apps"
],
"summary": "Create App",
"description": "Create a new app.",
"operationId": "create_app",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CreateAppCreateRequstBody"
}
}
},
"required": true
},
without dto:
"paths": {
"/app_dto": {
"post": {
"tags": [
"Apps"
],
"summary": "Create App",
"description": "Create a new app.",
"operationId": "create_app",
"requestBody": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/AppCreate"
}
}
},
"required": true
},
Steps to reproduce
No response
Screenshots
No response
Logs
No response
Litestar Version
2.8.2
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