Browse Source

add pydantic v1 support

pull/9837/head
JONEMI19 3 years ago
parent
commit
3e85d2cda2
  1. 30
      fastapi/_compat.py

30
fastapi/_compat.py

@ -331,6 +331,10 @@ else:
SHAPE_SEQUENCE, SHAPE_SEQUENCE,
SHAPE_TUPLE_ELLIPSIS, SHAPE_TUPLE_ELLIPSIS,
} }
mapping_shapes = {
SHAPE_MAPPING,
}
sequence_shape_to_type = { sequence_shape_to_type = {
SHAPE_LIST: list, SHAPE_LIST: list,
SHAPE_SET: set, SHAPE_SET: set,
@ -406,6 +410,32 @@ else:
return True return True
return False return False
def is_pv1_scalar_mapping_field(field: ModelField) -> bool:
if (field.shape in mapping_shapes) and not lenient_issubclass(
field.type_, BaseModel
):
if field.sub_fields is None:
return False
for sub_field in field.sub_fields:
if not is_scalar_field(sub_field):
return False
return True
return False
def is_pv1_scalar_sequence_mapping_field(field: ModelField) -> bool:
if (field.shape in mapping_shapes) and not lenient_issubclass(
field.type_, BaseModel
):
if field.sub_fields is None:
return False
for sub_field in field.sub_fields:
if not is_scalar_sequence_field(sub_field):
return False
return True
return False
def _normalize_errors(errors: Sequence[Any]) -> List[Dict[str, Any]]: def _normalize_errors(errors: Sequence[Any]) -> List[Dict[str, Any]]:
use_errors: List[Any] = [] use_errors: List[Any] = []
for error in errors: for error in errors:

Loading…
Cancel
Save