feat(frontend): auto-generate TypeScript types from backend OpenAPI schema
Replace manually maintained types in src/lib/types.ts with auto-generated types from FastAPI's OpenAPI schema using @hey-api/openapi-ts. The bridge file re-exports generated types with renames, Require<> augmentations for fields that are optional in the schema but always present in responses, and manually added relationship fields excluded from OpenAPI. - Add openapi-ts.config.ts and generate:api npm script - Generate types into src/lib/api/generated/types.gen.ts - Rewrite src/lib/types.ts as bridge with re-exports and augmentations - Fix null vs undefined mismatches in consumer components - Remove unused manual type definitions from api.ts - Update AGENTS.md docs with type generation workflow
This commit is contained in:
parent
470d49b061
commit
e29d62f949
16 changed files with 13745 additions and 2298 deletions
|
|
@ -51,7 +51,7 @@ When editing frontend code, follow `docs/frontend-design-cookbook.md` and update
|
|||
| Add LLM validator | `backend/innercontext/validators/` | Extend `BaseValidator`, return `ValidationResult` |
|
||||
| Add i18n strings | `frontend/messages/{en,pl}.json` | Auto-generates to `src/lib/paraglide/` |
|
||||
| Modify design system | `frontend/src/app.css` + `docs/frontend-design-cookbook.md` | Update both in same change |
|
||||
| Modify types | `frontend/src/lib/types.ts` + `backend/innercontext/models/` | Manual sync, no codegen |
|
||||
| Modify types | `backend/innercontext/models/` → `pnpm generate:api` → `frontend/src/lib/types.ts` | Auto-generated from OpenAPI; bridge file may need augmentation |
|
||||
|
||||
## Commands
|
||||
|
||||
|
|
@ -69,6 +69,7 @@ cd frontend && pnpm check # Type check + Svelte validation
|
|||
cd frontend && pnpm lint # ESLint
|
||||
cd frontend && pnpm format # Prettier
|
||||
cd frontend && pnpm build # Production build → build/
|
||||
cd frontend && pnpm generate:api # Regenerate types from backend OpenAPI
|
||||
```
|
||||
|
||||
## Commit Guidelines
|
||||
|
|
@ -83,7 +84,7 @@ Conventional Commits: `feat(api): ...`, `fix(frontend): ...`, `test(models): ...
|
|||
|
||||
### Cross-Cutting Patterns
|
||||
|
||||
- **Type sharing**: Manual sync between `frontend/src/lib/types.ts` and `backend/innercontext/models/`. No code generation.
|
||||
- **Type sharing**: Auto-generated from backend OpenAPI schema via `@hey-api/openapi-ts`. Run `cd frontend && pnpm generate:api` after backend model changes. `src/lib/types.ts` is a bridge file with re-exports, renames, and `Require<>` augmentations. See `frontend/AGENTS.md` § Type Generation.
|
||||
- **API proxy**: Frontend server-side uses `PUBLIC_API_BASE` (http://localhost:8000). Browser uses `/api` (nginx strips prefix → backend).
|
||||
- **Auth**: None. Single-user personal system.
|
||||
- **Error flow**: Backend `HTTPException(detail=...)` → Frontend catches `.detail` field → `FlashMessages` or `StructuredErrorDisplay`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue