Skip to content

Commit c5d667f

Browse files
i-trytoohardclaude
andcommitted
feat(frontend): typed openapi-fetch client over the generated schema
Main already generates frontend/src/api/schema.ts from the backend OpenAPI document (#103) but ships only the types. This adds the thin runtime layer: an openapi-fetch client typed by those generated paths, so the renderer makes fully typed requests against the daemon's loopback /api/v1 surface instead of hand-writing fetch calls. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7698c24 commit c5d667f

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

frontend/package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
"typecheck": "tsc --noEmit",
1010
"start": "npm run build && electron ."
1111
},
12+
"dependencies": {
13+
"openapi-fetch": "^0.17.0"
14+
},
1215
"devDependencies": {
1316
"electron": "^33.0.0",
1417
"typescript": "^5.6.0"

frontend/src/api/client.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import createClient from "openapi-fetch";
2+
import type { paths } from "./schema";
3+
4+
// Typed client for the daemon's loopback /api/v1 surface. Request and response
5+
// types come from ./schema.ts, which is generated from the backend OpenAPI
6+
// document (`npm run api` at the repo root) — never hand-maintained.
7+
export const api = createClient<paths>({ baseUrl: "http://127.0.0.1:3001" });
8+
9+
// Re-export the generated component schemas for convenient use in the renderer,
10+
// e.g. components["schemas"]["Project"], "Session", "APIError".
11+
export type { components, paths } from "./schema";

0 commit comments

Comments
 (0)