[阶段2] 路由前缀 APIRouter(prefix=...) 收口 #29

Closed
opened 2026-08-21 13:39:38 +08:00 by tao.chen · 2 comments
Owner

范围(L1 风险)

  • 每个 api/*.pyAPIRouter() 改为带 prefix
  • 所有 @router.<method>("...") 去掉前缀路径
  • main.py 不动(URL 不变)

示例

# 之前
router = APIRouter()
@router.post("/api/v1/auth/login")

# 之后
router = APIRouter(prefix="/api/v1/auth", tags=["auth"])
@router.post("/login")

验证

  • 全文 grep @router\.(get|post|put|patch|delete)\s*\(\s*["']([^"']+) 确认无遗漏
  • OpenAPI 文档路径与之前完全一致
  • curl 已有的 URL(/api/v1/auth/login 等)返回码不变

注意

  • api/internal.py 用 prefix /v1(main.py 会再外加 /internal
  • api/schedules/ 子包内的两个 router 各自带 prefix,main.py 一次性 include

Task: bfnqyaftrqrl5agb3qegzauy

## 范围(L1 风险) - 每个 `api/*.py` 的 `APIRouter()` 改为带 prefix - 所有 `@router.<method>("...")` 去掉前缀路径 - main.py 不动(URL 不变) ## 示例 ```python # 之前 router = APIRouter() @router.post("/api/v1/auth/login") # 之后 router = APIRouter(prefix="/api/v1/auth", tags=["auth"]) @router.post("/login") ``` ## 验证 - 全文 grep `@router\.(get|post|put|patch|delete)\s*\(\s*["']([^"']+)` 确认无遗漏 - OpenAPI 文档路径与之前完全一致 - curl 已有的 URL(/api/v1/auth/login 等)返回码不变 ## 注意 - `api/internal.py` 用 prefix `/v1`(main.py 会再外加 `/internal`) - `api/schedules/` 子包内的两个 router 各自带 prefix,main.py 一次性 include --- <sub>Task: bfnqyaftrqrl5agb3qegzauy</sub>
Author
Owner
[MODEL-DEVELOP-PLATFORM-52](https://kaneo.maimaicuizhiji.top/dashboard/workspace/UVjqrB68D9jAIx4sh6ucRfsPbbUCj97c/project/hna942mjy8cwyv1o77mw0cnv/task/s7s5ypie9gvstmy577a7vpu5)
tao.chen added the priority:mediumstatus:to-do labels 2026-08-21 13:39:41 +08:00
tao.chen added status:in-review and removed status:to-do labels 2026-08-21 15:09:17 +08:00
Author
Owner

tao.chen commented:

阶段2 完成。

改动

  • api/auth.py — prefix /api/v1/auth,3 个路由清理
  • api/jupyter.py — prefix /api/v1/auth,1 个路由清理(/api/v1/auth/jupyter/jupyter
  • api/admin.py — prefix /api/v1/admin(已存在)
  • api/platform.py — prefix /api/v1/platform(已存在)
  • api/resources.py — prefix /api/v1/data-resources(已存在)
  • api/scripts.py — prefix /api/v1,19 个路由清理(含 3 个 multi-line)
  • api/schedules/schedules.py — prefix /api/v1,13 个路由清理(含 3 个 multi-line)
  • api/schedules/runs.py — prefix /api/v1,6 个路由清理(含 1 个 POST /schedules/{id}/run
  • api/storage.py(原 storage_api.py)— prefix /v1(main.py 加 /internal),4 个路由清理

注意

  • main.py 未改 include 顺序;storage.py 文件名保留
  • 路径 OpenAPI 输出与之前完全一致
  • auth.pyjupyter.py 共享 prefix /api/v1/auth(不同 tags),main.py 分两次 add

验证

  • uv run python -m compileall backend/src backend/tests 零错误
  • uv run --package backend pytest backend/tests -q 114 passed
  • grep '"/api/v1/' backend/src/backend/api/ 命中仅剩 5 处 APIRouter prefix 行

遗留

  • 工作树未提交(按 CLAUDE.md "Commit or push only when the user asks")
**tao.chen** commented: > 阶段2 完成。 **改动** - `api/auth.py` — prefix `/api/v1/auth`,3 个路由清理 - `api/jupyter.py` — prefix `/api/v1/auth`,1 个路由清理(`/api/v1/auth/jupyter` → `/jupyter`) - `api/admin.py` — prefix `/api/v1/admin`(已存在) - `api/platform.py` — prefix `/api/v1/platform`(已存在) - `api/resources.py` — prefix `/api/v1/data-resources`(已存在) - `api/scripts.py` — prefix `/api/v1`,19 个路由清理(含 3 个 multi-line) - `api/schedules/schedules.py` — prefix `/api/v1`,13 个路由清理(含 3 个 multi-line) - `api/schedules/runs.py` — prefix `/api/v1`,6 个路由清理(含 1 个 POST `/schedules/{id}/run`) - `api/storage.py`(原 storage_api.py)— prefix `/v1`(main.py 加 `/internal`),4 个路由清理 **注意** - main.py 未改 include 顺序;`storage.py` 文件名保留 - 路径 OpenAPI 输出与之前完全一致 - `auth.py` 和 `jupyter.py` 共享 prefix `/api/v1/auth`(不同 tags),main.py 分两次 add **验证** - `uv run python -m compileall backend/src backend/tests` 零错误 - `uv run --package backend pytest backend/tests -q` 114 passed - `grep '"/api/v1/' backend/src/backend/api/` 命中仅剩 5 处 APIRouter prefix 行 **遗留** - 工作树未提交(按 CLAUDE.md "Commit or push only when the user asks")
tao.chen added status:done and removed status:in-review labels 2026-08-21 15:20:44 +08:00
tao.chen added the status:in-review label 2026-08-21 15:20:51 +08:00
tao.chen added status:archived and removed status:done labels 2026-08-24 10:09:09 +08:00
tao.chen reopened this issue 2026-08-24 10:09:13 +08:00
tao.chen added status:to-do and removed status:in-review labels 2026-08-24 10:09:21 +08:00
tao.chen added status:in-review and removed status:to-do labels 2026-08-24 14:21:47 +08:00
tao.chen added status:donestatus:archived and removed status:in-review labels 2026-08-24 14:25:21 +08:00
tao.chen reopened this issue 2026-08-24 14:25:36 +08:00
tao.chen added the status:to-do label 2026-08-24 14:26:11 +08:00
tao.chen removed the status:to-do label 2026-08-24 14:49:48 +08:00
tao.chen added the status:in-review label 2026-08-24 14:50:11 +08:00
tao.chen reopened this issue 2026-08-24 14:50:13 +08:00
tao.chen reopened this issue 2026-08-24 14:50:33 +08:00
tao.chen removed the status:done label 2026-08-24 14:50:49 +08:00
tao.chen reopened this issue 2026-08-24 14:50:49 +08:00
tao.chen added the status:done label 2026-08-24 14:50:59 +08:00
tao.chen added status:to-do and removed status:done labels 2026-08-24 14:51:27 +08:00
tao.chen reopened this issue 2026-08-24 14:51:33 +08:00
tao.chen added status:done and removed status:to-do labels 2026-08-24 14:54:45 +08:00
tao.chen removed the status:done label 2026-08-24 14:55:03 +08:00
tao.chen reopened this issue 2026-08-24 14:55:14 +08:00
tao.chen added status:to-do and removed status:in-review labels 2026-08-24 14:55:23 +08:00
tao.chen added status:in-review and removed status:to-do labels 2026-08-25 19:16:56 +08:00
tao.chen added status:done and removed status:in-review labels 2026-08-27 18:54:05 +08:00
Sign in to join this conversation.