# fastapi.exceptions.FastAPIError: 响应字段参数无效！提示：检查 typing.Union[str, NoneType] 是否为有效的 Pydantic 字段类型。

- **ID:** `python/fastapi-openapi-schema-generation-error`
- **领域:** python
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

返回注解使用了 FastAPI 无法转换为 Pydantic 字段的结构（如无校验的自定义类或不受支持的泛型）。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 0.100+ | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   class Out(BaseModel):
    name: str
@app.get('/x', response_model=Out)
def x(): ...
   ```
2. **** (85% 成功率)
   ```
   from typing import Any
@app.get('/x')
def x() -> Any: ...
   ```

## 无效尝试

- **** — Loses schema and docs; underlying type issue remains. (70% 失败率)
- **** — Bypasses OpenAPI generation but not validation. (85% 失败率)
