Feature: auto-generate a typed TypeScript SDK into packages/shared from the OpenAPI spec

Aperta
#16 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
go, openapi, react, typescript

Direzione di ricerca

Start by reading the existing grit generate resource and grit sync command implementations to see where packages/shared types and Zod schemas are emitted. Then inspect packages/shared/types/api.ts and the OpenAPI output mounted at /docs/openapi.json to map the {data, meta, error} envelope. The work is done when grit sync-sdk emits a typed namespaced client at packages/shared/client.ts, existing React Query hooks delegate to it, and generated hooks lose their any payloads.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Context

Grit already emits OpenAPI via gindocs mounted at /docs (great!). And grit generate resource produces TS types + Zod schemas in packages/shared. But the bridge is missing: the frontend still has to hand-write fetch('/api/invoices') and cast the response.

Proposal

Add grit sync-sdk (or extend the existing grit sync) to generate a typed client into packages/shared/client.ts:

import { createClient } from \"@rental-manager/shared\";

const api = createClient({ baseURL: \"http://localhost:8080\", token });

// Fully typed:
const { data: invoices, meta } = await api.invoices.list({
  tenant_id: tenantId,
  status: \"overdue\",
  page: 1,
  page_size: 20,
});

const inv = await api.invoices.get(invoiceId);
const created = await api.invoices.create({
  tenant_id, items: [...], issue_date, due_date
});

Under the hood: fetch + error envelope matching Grit's existing {data, meta, error} shape + React Query integration (Grit already emits useList, useCreate, etc. hooks — let those delegate to this client).

Why this is a multiplier

  • One source of truth: the Go model + gin binding tags already define the contract. OpenAPI already exports it. TS types + Zod already mirror it. A single generator closes the loop.
  • Frontend error surface shrinks dramatically — no more as Invoice[] casts, no stale mocks in tests, compile-time breakage when a backend field renames.
  • React Query hooks that Grit already scaffolds can inherit proper types — currently they appear to take generic any payloads in the samples I generated.
  • Matches competitors — trpc, Payload, Hono RPC, Encore all do this today; it's becoming table stakes for full-stack TS-adjacent frameworks.

Implementation notes

  • openapi-typescript or orval can do the heavy lifting; Grit just has to invoke it against the live /docs/openapi.json or an on-disk snapshot.
  • Keep the client runtime tiny (no axios dependency); mirror the ApiResponse/PaginatedResponse types already in packages/shared/types/api.ts.
  • Emit per-resource namespaces (api.invoices.*, api.tenants.*) to match the URL hierarchy.

Bonus

This would play nicely with the pagination helper (issue #14) — every List hook gets { data, total, page, page_size, pages } typed once and reused everywhere.

Lingua principale
Go
Stelle
152
Fork
20
Merge medio
1g 49m
PR unite (30g)
5

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MUKE-coder/grit

Tutte le issue di MUKE-coder/grit

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.