OpenAPI schema generation fails if it encounters a "nested" object with a type which is not available at runtime but could be resolved using signature types/namespaces
.
No response
main.py
from litestar import Litestar, get
from external_module import Item
from schemas import ItemContainer
@get(sync_to_thread=False, signature_namespace={"Item": Item})
def handler() -> ItemContainer:
return ItemContainer(items=[])
app = Litestar(
route_handlers=[handler],
signature_types=(Item,),
debug=True,
)
schemas.py
from __future__ import annotations
from dataclasses import dataclass
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from external_module import Item
@dataclass
class ItemContainer:
items: list[Item]
external_module.py
from dataclasses import dataclass
@dataclass
class Item:
foo: str = "bar"
1. Run the above code
2. See error at `http://127.0.0.1:8000/schema` (`name 'Item' is not defined`)
3. `http://127.0.0.1:8000` still works.
No response
No response
2.10.0
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