by_alias=by_alias,
skip_defaults=bool(exclude_unset or skip_defaults),
)
+ if "__root__" in obj_dict:
+ obj_dict = obj_dict["__root__"]
return jsonable_encoder(
obj_dict,
exclude_none=exclude_none,
bla: str = "bla"
+class ModelWithRoot(BaseModel):
+ __root__: str
+
+
@pytest.fixture(
name="model_with_path", params=[PurePath, PurePosixPath, PureWindowsPath]
)
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"