Browse Source

Allow for BaseModel fields to be extracted from any index of the fields list.

pull/13427/head
Jacob Padilla 1 month ago
parent
commit
d9582daffc
  1. 17
      fastapi/dependencies/utils.py

17
fastapi/dependencies/utils.py

@ -210,13 +210,16 @@ def get_flat_dependant(
def _get_flat_fields_from_params(fields: List[ModelField]) -> List[ModelField]:
if not fields:
return fields
first_field = fields[0]
if len(fields) == 1 and lenient_issubclass(first_field.type_, BaseModel):
fields_to_extract = get_cached_model_fields(first_field.type_)
return fields_to_extract
return fields
extracted_fields = []
for field in fields:
if lenient_issubclass(field.type_, BaseModel):
model_fields = get_cached_model_fields(field.type_)
extracted_fields.extend(model_fields)
else:
extracted_fields.append(field)
return extracted_fields
def get_flat_params(dependant: Dependant) -> List[ModelField]:

Loading…
Cancel
Save