(fields: list[ModelField])
| 890 | |
| 891 | |
| 892 | def _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 | |
| 916 | async def _extract_form_body( |
no test coverage detected
searching dependent graphs…