From d9582daffc4462ad6c3871ce07b5428ed188e32c Mon Sep 17 00:00:00 2001 From: Jacob Padilla Date: Thu, 27 Feb 2025 08:14:19 -0500 Subject: [PATCH] Allow for BaseModel fields to be extracted from any index of the fields list. --- fastapi/dependencies/utils.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fastapi/dependencies/utils.py b/fastapi/dependencies/utils.py index e2866b488..5a136db08 100644 --- a/fastapi/dependencies/utils.py +++ b/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]: