Agent skill
type-generation
Regenerate TypeScript types from the OpenAPI spec to keep the frontend in sync with the backend. Use after API changes.
Install this agent skill to your Project
npx add-skill https://github.com/majiayu000/claude-skill-registry/tree/main/skills/other/other/type-generation
Metadata
Additional technical details for this skill
- author
- traceway
- version
- 1.0.0
SKILL.md
Type Generation Workflow
Use this skill when the API shape has changed and the frontend needs updated types, or when the user asks to sync types between backend and frontend.
Overview
The type flow is:
- Backend (Encore.ts or Rust daemon) defines API endpoints
- OpenAPI spec is generated from the running API
openapi-typescriptconverts the spec to TypeScript types- Frontend imports types from
ui/src/lib/api-types.ts
Option A: Generate from existing openapi.json file
If openapi.json at the repo root is already up to date:
cd ui && npm run generate-types:file
This reads ../openapi.json and writes src/lib/api-types.ts.
Option B: Generate from running daemon
If the Rust daemon is running locally (port 3000):
cd ui && npm run generate-types
This fetches from http://localhost:3000/api/openapi.json.
Option C: Full sync (daemon → openapi.json → types)
If you need to update both the spec file and types:
./scripts/sync-openapi.sh
This script:
- Detects a running daemon or starts one temporarily
- Fetches the live OpenAPI spec
- Normalizes JSON for stable diffs
- Writes
openapi.jsonat repo root - Runs
openapi-typescriptto generateui/src/lib/api-types.ts
After generating types
- Check for new types to re-export in
ui/src/lib/api.ts:
// In ui/src/lib/api.ts — add re-exports for new schema types
export type NewEntity = Schemas['NewEntity'];
export type NewEntityResponse = Schemas['NewEntityResponse'];
- Add fetch helpers if needed:
export async function getNewEntities(): Promise<NewEntity[]> {
const res = await fetch(`${API_BASE}/internal/new-entities?org_id=${getOrgId()}&project_id=${getProjectId()}`);
if (!res.ok) throw new Error(res.statusText);
const data = await res.json();
return data.items;
}
- Run svelte-check:
cd ui && npm run check
Makefile shortcuts
make sync-openapi # Full sync (Option C)
make generate-types # From file (Option A)
When to regenerate
- After adding/modifying Encore.ts API endpoints
- After changing Rust daemon API routes or response types
- After modifying request/response interfaces in
backend/app/*/types.ts - Before starting UI work that consumes new API endpoints
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
agent-ops-spec
Manage specification documents in .agent/specs/. Use when user provides requirements, acceptance criteria, or feature descriptions that need to be tracked and validated against implementation.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-testing
Test strategy, execution, and coverage analysis. Use when designing tests, running test suites, or analyzing test results beyond baseline checks.
agent-ops-state
Maintain .agent state files. Use at session start, after meaningful steps, and before concluding: read/update constitution/memory/focus/issues/baseline consistently.
Didn't find tool you were looking for?