openapi-sync¶
In plain terms
Keeps the front-end's data types in sync with the back-end automatically, so the two don't drift apart.
What this skill does
Regenerate frontend TypeScript types from the backend OpenAPI schema to keep types in sync.
Stack flavor: fastapi only.
[!IMPORTANT] Run this after ANY backend schema change (new model, changed field, new route). Skipping this causes type drift between frontend and backend.
⚠️ Trigger Conditions¶
- Files: Changes to
backend/app/models/*.pyorbackend/app/schemas/*.py. - After running
/db-migrationor/feature-scaffold. - Keywords: "Update types", "Sync types", "Regenerate API types".
1. Export OpenAPI Schema¶
Ensure the FastAPI backend is running (or use the export command):
cd backend && python -c "
import json
from app.main import app
print(json.dumps(app.openapi(), indent=2))
" > openapi.json
curl http://localhost:8000/openapi.json -o backend/openapi.json
2. Generate Frontend Types¶
From the openapi.json, regenerate the TypeScript types:
cd frontend && npx openapi-typescript ../backend/openapi.json -o src/types/api.ts
[!NOTE] The exact command depends on the generator configured in
frontend/package.json. Check for agenerate:typesoropenapiscript first.
3. Verify¶
- [ ] No regressions: Check that existing usages of
@/types/apistill compile:cd frontend && npm run type-check. - [ ] New types present: Confirm new models/schemas appear in
frontend/src/types/api.ts. - [ ] No manual edits:
frontend/src/types/api.tsis a generated file — never manually edit it.
4. Commit¶
- [ ] Commit both
backend/openapi.jsonandfrontend/src/types/api.tstogether so the repo always stays in sync.