mirror of https://github.com/tiangolo/fastapi.git
🐛 Fix extracting attributes for old Pydantic versions
This commit is contained in:
parent
1643b0b6f5
commit
f75daed0a0
|
|
@ -78,10 +78,15 @@ _Attrs = {
|
||||||
|
|
||||||
# TODO: remove when dropping support for Pydantic < v2.12.3
|
# TODO: remove when dropping support for Pydantic < v2.12.3
|
||||||
def asdict(field_info: FieldInfo) -> Dict[str, Any]:
|
def asdict(field_info: FieldInfo) -> Dict[str, Any]:
|
||||||
|
attributes = {}
|
||||||
|
for attr in _Attrs:
|
||||||
|
value = getattr(field_info, attr, Undefined)
|
||||||
|
if value is not Undefined:
|
||||||
|
attributes[attr] = value
|
||||||
return {
|
return {
|
||||||
"annotation": field_info.annotation,
|
"annotation": field_info.annotation,
|
||||||
"metadata": field_info.metadata,
|
"metadata": field_info.metadata,
|
||||||
"attributes": {attr: getattr(field_info, attr) for attr in _Attrs},
|
"attributes": attributes,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue