Skip to content

Commit 048d9fc

Browse files
feat(openapi): auto-generate spec from Drizzle schema with CI drift check (#203)
The hand-written public/openapi.json (last touched 2026-04-23) had drifted badly from reality — e.g. Utility documented 14 fields while the DB table and API returned all 43. Multiple endpoint families shipped since then (substations, transmission-lines, power-plants/substations, pricing-nodes/versions, programs/versions, territories/lookup, changelog) weren't in the spec at all. Before vs after field counts (public schema objects): Utility 14 → 37 PowerPlant 9 → 31 EvStation 11 → 26 Program 7 → 31 PricingNode 5 → 17 BalancingAuthority 4 → 17 Iso 5 → 14 Rto 4 → 14 Region 4 → 14 Substation — → 22 TransmissionLine — → 18 Territory 5 → 9 Approach: - scripts/generate-openapi.ts walks every Drizzle table via getTableColumns and maps PG column types → OpenAPI 3.1 schemas. Internal fields (submittedBy, reviewedAt, reviewedBy, lockedStatus, searchVector, notionPageId, geography/geometry) are stripped by default. jsonb columns with known shape get per-field overrides. - scripts/openapi/endpoints.ts is the canonical per-endpoint registry. Query params mirror the actual Zod schemas / URL parsing in app/api/v1/**. Auth-required/internal endpoints (mod/*, developer/*, contributions, discussions, follows, notifications, me, editable-fields, webhooks, revalidate, health, tiles) are intentionally excluded. - scripts/openapi/base.ts preserves the previous info/servers/tags and shared components (ErrorResponse, PaginatedMeta, SearchResults) plus adds ChangelogResponse, EntityVersion, GeoJsonFeature. New endpoints now documented: /substations, /substations/{slug}, /substations/{slug}/transmission-lines /power-plants/{slug}/substations /pricing-nodes/{slug}/versions, /programs/{slug}/versions /territories/lookup /changelog npm scripts: npm run openapi # regenerate public/openapi.json npm run openapi:check # exit 1 on drift, used by CI CI: new 'openapi' job runs openapi:check on every PR; drift fails the build. Fixes ALL-728 Co-authored-by: texture-coding-agent <[email protected]>
1 parent cbc4fea commit 048d9fc

9 files changed

Lines changed: 5671 additions & 399 deletions

File tree

.github/workflows/ci.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ jobs:
2828
- run: npm install
2929
- run: npm test
3030

31+
openapi:
32+
runs-on: ubuntu-latest
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: actions/setup-node@v4
36+
with:
37+
node-version: 20
38+
cache: npm
39+
- run: npm install
40+
- run: npm run openapi:check
41+
3142
build:
3243
runs-on: ubuntu-latest
3344
needs: [lint, test]

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
"sync:pricing-nodes": "tsx scripts/sync-pricing-nodes.ts",
2020
"sync:substations": "tsx scripts/sync-substations.ts",
2121
"generate:changelog": "npx tsx scripts/generate-changelog.ts",
22+
"openapi": "tsx scripts/generate-openapi.ts",
23+
"openapi:check": "tsx scripts/generate-openapi.ts --check",
2224
"sync:all": "npx tsx scripts/sync-all.ts",
2325
"seed": "tsx scripts/seed-database.ts",
2426
"test:api": "tsx scripts/test-api-endpoints.ts"

0 commit comments

Comments
 (0)