-
-
Notifications
You must be signed in to change notification settings - Fork 469
Open
Labels
Bug 🐛This is something that is not working as expectedThis is something that is not working as expected
Description
Description
OpenAPI schema generator create incorrect type for fields with default_factory
.
In MCVE Foo.foo type
is str
, but in generated openapi (string | null)
, which is incorrect
URL to code causing the issue
No response
MCVE
from litestar import Litestar, get, post
from pydantic import BaseModel, Field
def foo_factory() -> str:
return 'foo'
class Foo(BaseModel):
foo: str = Field(default_factory=foo_factory)
bar: str = Field(default='bar')
spam: str
@post('/')
def create_foo(data: Foo) -> None:
pass
@get('/')
def foo() -> Foo:
return Foo(spam='spam')
app = Litestar(route_handlers=[create_foo, foo])
Steps to reproduce
uv run --with "litestar[pydantic,standard]" uvicorn mcve:app
Screenshots

Litestar Version
2.17.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