mirror of
https://github.com/fastapi/fastapi.git
synced 2026-03-30 20:54:03 -04:00
✨ When using Pydantic models with __root__ use the internal value in jsonable_encoder (#1524)
This commit is contained in:
@@ -76,6 +76,10 @@ class ModelWithDefault(BaseModel):
|
||||
bla: str = "bla"
|
||||
|
||||
|
||||
class ModelWithRoot(BaseModel):
|
||||
__root__: str
|
||||
|
||||
|
||||
@pytest.fixture(
|
||||
name="model_with_path", params=[PurePath, PurePosixPath, PureWindowsPath]
|
||||
)
|
||||
@@ -158,3 +162,8 @@ def test_encode_model_with_path(model_with_path):
|
||||
else:
|
||||
expected = "/foo/bar"
|
||||
assert jsonable_encoder(model_with_path) == {"path": expected}
|
||||
|
||||
|
||||
def test_encode_root():
|
||||
model = ModelWithRoot(__root__="Foo")
|
||||
assert jsonable_encoder(model) == "Foo"
|
||||
|
||||
Reference in New Issue
Block a user