ADR-0007 Phase 0: OpenAPI → TypeScript 型生成の基盤導入#289
Conversation
|
Warning Review limit reached
More reviews will be available in 40 minutes and 13 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThis PR implements an OpenAPI type-generation pipeline that extracts the backend FastAPI schema and auto-generates TypeScript type definitions for the frontend, with CI enforcement to prevent schema-generated-types drift. Backend endpoints are updated to use structured response schemas, enabling accurate OpenAPI export and downstream type generation. ChangesOpenAPI Type Code-Generation Pipeline
🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
backend/app/schemas/__init__.py (1)
38-38: ⚡ Quick win
TaskAcceptedResponseis not re-exported here.
TaskStatusResponse(andGitHubLoginUrlResponse) are exported through this package, but the newTaskAcceptedResponseis omitted from both the.sharedimport and__all__.github_link.pyimports it directly from..schemas.sharedso nothing breaks today, but this is inconsistent with the sibling schemas and the PR's stated intent to export new schemas.♻️ Proposed fix
-from .shared import TaskStatusResponse +from .shared import TaskAcceptedResponse, TaskStatusResponseAdd to
__all__:+ "TaskAcceptedResponse", "TaskStatusResponse",🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@backend/app/schemas/__init__.py` at line 38, Add the new TaskAcceptedResponse to the package re-exports so it is consistently available like TaskStatusResponse and GitHubLoginUrlResponse: update the import line in __init__.py to include TaskAcceptedResponse (from .shared import TaskStatusResponse, TaskAcceptedResponse, GitHubLoginUrlResponse) and add "TaskAcceptedResponse" to the module's __all__ list so callers can import it from the package rather than from ..schemas.shared.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.github/workflows/ci.yml:
- Around line 225-229: The new CI job "codegen-drift" must be made a hard
prerequisite for all deployment jobs so failed drift checks block deploys;
locate any jobs whose purpose is deployment (job IDs like deploy,
deploy-staging, deploy-prod or any job that currently needs: detect-changes) and
add "codegen-drift" to their needs array (so needs: [detect-changes,
codegen-drift] or include it alongside other upstreams), ensuring the deploy
jobs' if conditions still reference needs.detect-changes.outputs as needed and
that the job id "codegen-drift" matches exactly.
- Around line 232-257: Replace the floating action tags with pinned commit SHAs
and disable credential persistence on checkout: change uses: actions/checkout@v4
to uses: actions/checkout@<commit-sha> and add persist-credentials: false,
replace uses: astral-sh/setup-uv@v4 and uses: actions/setup-node@v4 with their
respective commit SHAs (e.g. astral-sh/setup-uv@<commit-sha>,
actions/setup-node@<commit-sha>) so the workflow references fixed revisions and
does not expose repository tokens.
---
Nitpick comments:
In `@backend/app/schemas/__init__.py`:
- Line 38: Add the new TaskAcceptedResponse to the package re-exports so it is
consistently available like TaskStatusResponse and GitHubLoginUrlResponse:
update the import line in __init__.py to include TaskAcceptedResponse (from
.shared import TaskStatusResponse, TaskAcceptedResponse, GitHubLoginUrlResponse)
and add "TaskAcceptedResponse" to the module's __all__ list so callers can
import it from the package rather than from ..schemas.shared.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: c67345d0-ebdf-4eba-b47b-2edd843b323c
⛔ Files ignored due to path filters (1)
frontend/package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (14)
.github/workflows/ci.yml.gitignoreMakefilebackend/app/routers/auth/endpoints.pybackend/app/routers/github_link.pybackend/app/schemas/__init__.pybackend/app/schemas/auth.pybackend/app/schemas/shared.pybackend/scripts/export_openapi.pyfrontend/.prettierignorefrontend/eslint.config.jsfrontend/package.jsonfrontend/scripts/gen-types.mjsfrontend/src/api/generated.ts
|
まとめ CI 失敗の原因と修正:
検証:
|
概要
ADR-0007(OpenAPI → TypeScript 型コード生成の導入・完全移行) の Phase 0(前提・基盤) を実装する。
backend(Pydantic schema)と frontend(手書き TypeScript 型)の DTO 二重定義は、これまで目視同期に依存しており、機械的なドリフト検知の仕組みが無かった(jscpd は
.py/.tsを別トークナイザで扱うため cross-realm clone を検出できない)。この PR では型移行そのものは行わず、OpenAPI から TypeScript 型を自動生成するパイプラインと CI ドリフト検知を整備する。あわせて、完全移行の前提となる
response_model未設定エンドポイントの schema 化を行う。背景
app/schemas/**で定義する DTO を、frontend がtypes.ts/api/*.tsに手書きで再定義しており、フィールド構造を人手で同期している。undefinedを踏むまで気づけない。Record<ErrorCodeKey, ...>の型縛りでビルド時に漏れを検知できている。DTO にも同等の「漏れたらビルドで落ちる」仕組みを与えたい。response_model付きエンドポイントのみ(ADR 起票時の実測 40 中 26)。完全移行の前提として、DTO を持つのにresponse_model未設定のエンドポイントを Phase 0 で schema 化・付与する。変更内容
1. パイプライン構築
backend/scripts/export_openapi.py(新規)app.openapi()をbackend/openapi.jsonにダンプ。ENVIRONMENT未設定時は local 扱いとし import 時の設定チェックを回避。diff 安定化のためsort_keys=Trueで出力。frontend/scripts/gen-types.mjs(新規)backend/openapi.json→frontend/src/api/generated.tsをopenapi-typescriptで生成。冒頭に「手編集禁止」バナーを付与。Makefilemake codegen-typesを追加(Nix devshell 経由で export → 型生成を一括実行)。frontend/package.jsonopenapi-typescript@^7.13.0を devDependency に追加。frontend/src/api/generated.ts(新規・生成物)2. 生成物の lint / format 除外
frontend/eslint.config.js:src/api/generated.tsを ESLint 対象から除外(生成スタイルとの衝突回避)。frontend/.prettierignore(新規): 同ファイルを Prettier 対象外に。.gitignore: 中間生成物backend/openapi.jsonを除外(コミット対象はgenerated.tsのみ)。3.
response_model未設定エンドポイントの整備(完全移行の前提)匿名
dictを返していたエンドポイントに schema を付与し、OpenAPI に型が出るようにする。GET /auth/github/login-urlGitHubLoginUrlResponse(authorization_url/state)を追加しresponse_model付与。dict[str, str]の返却をやめる。POST /github/runPOST /github/run/retryTaskAcceptedResponse(status)に集約して DRY 化。{"status": ...}の dict 返却をやめる。新規 schema:
backend/app/schemas/auth.pyのGitHubLoginUrlResponse、backend/app/schemas/shared.pyのTaskAcceptedResponse。backend/app/schemas/__init__.pyでエクスポート。4. CI ドリフト検知
.github/workflows/ci.ymlにcodegen-driftジョブを追加。app変更時に走り、make codegen-types相当(OpenAPI export → 型生成)を実行後、git diff --exit-code frontend/src/api/generated.tsで差分があれば fail。「backend schema を変えたのに型を再生成していない」状態をビルドで落とす。移行しないもの(この PR の対象外)
api/client.tsの 401/CSRF/Cookie 認証ロジックapi/paths.tsのPATHS(API パス SSoT として維持)constants/errorCodes.ts/errorMessages.ts(別系統の型縛り)動作確認
ADR への影響
ADR-0007 のステータスは引き続き
Proposed。Phase 0 + Phase 1 パイロットがmake cigreen を満たし、CI ドリフト検知が機能する(backend schema をわざと変えると CI が落ちる)ことを確認できた時点でAcceptedに昇格する。🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
New Features
CI/CD