MCPcopy
hub / github.com/fastapi/fastapi / _should_embed_body_fields

Function _should_embed_body_fields

fastapi/dependencies/utils.py:892–913  ·  view source on GitHub ↗
(fields: list[ModelField])

Source from the content-addressed store, hash-verified

890
891
892def _should_embed_body_fields(fields: list[ModelField]) -> bool:
893 if not fields:
894 return False
895 # More than one dependency could have the same field, it would show up as multiple
896 # fields but it's the same one, so count them by name
897 body_param_names_set = {field.name for field in fields}
898 # A top level field has to be a single field, not multiple
899 if len(body_param_names_set) > 1:
900 return True
901 first_field = fields[0]
902 # If it explicitly specifies it is embedded, it has to be embedded
903 if getattr(first_field.field_info, "embed", None):
904 return True
905 # If it's a Form (or File) field, it has to be a BaseModel (or a union of BaseModels) to be top level
906 # otherwise it has to be embedded, so that the key value pair can be extracted
907 if (
908 isinstance(first_field.field_info, params.Form)
909 and not lenient_issubclass(first_field.field_info.annotation, BaseModel)
910 and not is_union_of_base_models(first_field.field_info.annotation)
911 ):
912 return True
913 return False
914
915
916async def _extract_form_body(

Calls 2

lenient_issubclassFunction · 0.90
is_union_of_base_modelsFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…