python
config_error
ai_generated
true
AssertionError: Duplicated path operation: GET /items
ID: python/fastapi-path-operation-duplicate
80%Fix Rate
86%Confidence
0Evidence
2025-04-20First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 3.9 | active | — | — | — |
| 3.10 | active | — | — | — |
Root Cause
FastAPI 中为同一个路径和方法定义了多个路径操作函数
generic中文
FastAPI 中为同一个路径和方法定义了多个路径操作函数
Workarounds
-
95% success 合并重复的路径操作
def get_items(): # 合并逻辑 pass @app.get('/items') @app.get('/items/') # 使用路径别名 -
90% success 使用不同的路径
@app.get('/items') @app.get('/products') # 改为不同路径
Dead Ends
Common approaches that don't work:
-
删除其中一个函数但保留逻辑
70% fail
功能丢失
-
使用不同的 HTTP 方法
60% fail
可能不符合 RESTful 设计