# FastAPI错误：响应字段的参数无效

- **ID:** `python/fastapi-multiple-body-params-error`
- **领域:** python
- **类别:** config_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

在没有Pydantic模型的情况下定义多个主体参数，导致FastAPI误解请求体，引发验证问题。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 3.x | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Combine parameters into a single Pydantic model: class Item(BaseModel):\n    name: str\n    price: float\nThen use item: Item as the body parameter.
   ```
2. **** (90% 成功率)
   ```
   If multiple bodies are needed, embed them in a parent model: class RequestModel(BaseModel):\n    item: Item\n    user: User
   ```

## 无效尝试

- **** — Using dict as a body parameter type can cause serialization issues and unexpected validation errors. (70% 失败率)
- **** — Adding Body() to each parameter but not using a single model still confuses FastAPI. (60% 失败率)
