request_body_to_args
Converts a received request body into a dictionary of validated arguments and a list of validation errors based on the provided model fields. It handles form data extraction, embedded field logic, and validates each field against its corresponding model definition.
def request_body_to_args(
body_fields: list[ModelField],
received_body: dict[str, Any] | FormData | bytes | None,
embed_body_fields: bool
) - > tuple[dict[str, Any], list[dict[str, Any]]]
Maps and validates raw request body data into a dictionary of arguments based on defined model fields. This function handles the extraction logic for both single-field and multi-field bodies, including special processing for form data and embedded field configurations.
Parameters
| Name | Type | Description |
|---|---|---|
| body_fields | list[ModelField] | A list of Pydantic model fields representing the expected structure and validation rules for the request body. |
| received_body | `dict[str, Any] | FormData |
| embed_body_fields | bool | A flag indicating whether multiple body fields should be expected as a nested JSON object or treated as top-level keys. |
Returns
| Type | Description |
|---|---|
tuple[dict[str, Any], list[dict[str, Any]]] | A tuple containing a dictionary of validated field values and a list of any validation errors encountered during processing. |