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?
No response
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
},
No response
No response
No response
2.8.2
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too