Skip to content

Bug: OpenAPI spec blank response schema when using Response object #3888

@pavdwest

Description

@pavdwest

Description

See example below - using the Scalar docs the schema for the get_items endpoint is blank (just says "No Body"). Ideally the schema would be populated exactly as if the response wasn't wrapped in a "Response" object, i.e. it should just use the type hinting info List[Item].

URL to code causing the issue

http://127.0.0.1:8000/schema

MCVE

from dataclasses import dataclass
from typing import List

from litestar import Litestar, get, Response
from litestar.openapi import OpenAPIConfig
from litestar.openapi.plugins import ScalarRenderPlugin
from litestar.dto import DataclassDTO, DTOConfig


@dataclass
class Item:
    id: int
    name: str
    secret: str


class ItemReadDTO(DataclassDTO[Item]):
    config = DTOConfig(exclude=["secret"])


@get("/get_items", return_dto=ItemReadDTO)
async def get_items() -> Response[List[Item]]:
    return Response(
        headers={"X-SomeParam": "SomeValue"},
        content=[
            Item(id=1, name="Item 1", secret='123'),
            Item(id=2, name="Item 2", secret='456'),
        ]
    )


@get("/get_items_raw", return_dto=ItemReadDTO)
async def get_items_raw() -> List[Item]:
    return [
        Item(id=1, name="Item 1", secret='123'),
        Item(id=2, name="Item 2", secret='456'),
    ]


app = Litestar(
    route_handlers=[get_items, get_items_raw],
    openapi_config=OpenAPIConfig(
        title="Scalar Issue",
        version="0.1.0",
        render_plugins=[ScalarRenderPlugin()],
    ),
    debug=True,
)

Steps to reproduce

run uvicorn main:app

Screenshots

"![SCREENSHOT_DESCRIPTION](SCREENSHOT_LINK.png)"

Logs

No response

Litestar Version

2.13.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 expected

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions