fix: openapi-ts#7
Conversation
|
All contributors have signed the CLA ✍️ ✅ |
|
I have read the CLA Document and I hereby sign the CLA |
There was a problem hiding this comment.
Pull request overview
Adds an OpenAPI-driven code generation flow so the FastAPI schema can be exported and the Next.js frontend can generate API client/types from that schema.
Changes:
- Add
apps/api/export_schema.pyto write FastAPI’s OpenAPI todocs/schema/openapi.json. - Add
@hey-api/openapi-tsconfig + webcodegenscript and ignore generated output underapps/web/src/api. - Update CI (web job) to export the schema and run codegen before lint/build.
Reviewed changes
Copilot reviewed 8 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Updates root codegen script to use npm in apps/web. |
| docs/schema/openapi.json | Adds exported OpenAPI schema artifact (initial content includes /health). |
| apps/web/package.json | Adds codegen script and hey-api devDependencies for OpenAPI TS generation. |
| apps/web/package-lock.json | Locks new hey-api dependencies introduced for codegen. |
| apps/web/openapi-ts.config.ts | Configures openapi-ts input (docs/schema/openapi.json) and output (src/api). |
| apps/web/.gitignore | Ignores generated API client directory src/api. |
| apps/api/export_schema.py | Adds script to export schema from FastAPI app to docs/schema/openapi.json. |
| .github/workflows/ci.yml | Runs schema export + web codegen before lint/build in the web CI job. |
Files not reviewed (1)
- apps/web/package-lock.json: Language not supported
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "scripts": { | ||
| "codegen": "cd apps/web && pnpm run codegen" | ||
| "codegen": "cd apps/web && npm run codegen" | ||
| } |
There was a problem hiding this comment.
npm run codegen only runs the web codegen step; it doesn't regenerate docs/schema/openapi.json first. That means local codegen can easily run against a stale schema (CI updates the schema, but this script won’t). Consider chaining the schema export step here (e.g., run the API export script first) so codegen is reproducible locally.
| "dev": "next dev", | ||
| "build": "next build", | ||
| "start": "next start", | ||
| "lint": "eslint" | ||
| "lint": "eslint", | ||
| "codegen": "openapi-ts" | ||
| }, |
There was a problem hiding this comment.
The generated client is written to src/api (and is gitignored), but npm run build doesn’t run codegen. If/when the app starts importing the generated client, Docker/local builds that only run npm run build will fail unless codegen is run beforehand. Consider adding a prebuild step or folding codegen into the build pipeline to ensure src/api exists whenever building.
| "react-dom": "19.2.4" | ||
| }, | ||
| "devDependencies": { | ||
| "@hey-api/client-fetch": "^0.13.1", |
There was a problem hiding this comment.
@hey-api/client-fetch is marked deprecated in the lockfile (bundled into @hey-api/openapi-ts as of v0.73.0). Unless you specifically need it as a separate dependency, consider removing it to avoid deprecation warnings and reduce dependencies.
| "@hey-api/client-fetch": "^0.13.1", |
| "description": "Successful Response", | ||
| "content": { | ||
| "application/json": { | ||
| "schema": {} |
There was a problem hiding this comment.
The /health 200 response schema is {} in the exported OpenAPI spec, which will cause generated TypeScript types for this endpoint to be effectively untyped. If the goal is strongly typed clients, consider adding a response_model (or explicit response schema) on the FastAPI route so the exported OpenAPI contains the object shape.
| "schema": {} | |
| "schema": { | |
| "type": "object", | |
| "properties": { | |
| "status": { | |
| "type": "string", | |
| "example": "ok" | |
| } | |
| }, | |
| "required": [ | |
| "status" | |
| ] | |
| } |
What changed
Added codegen support so frontend types and docs/schema are auto generated from openapi of fastapi.
Checklist
docker compose upworks locallyschema.dbmlupdated if schema changed