Skip to content

Latest commit

 

History

History
29 lines (24 loc) · 8.85 KB

codegen.md

File metadata and controls

29 lines (24 loc) · 8.85 KB

Code generation

clients generate writes clients from an OpenAPI document (--spec) or straight from an app module (--app): SDKs in TypeScript, Go, Rust, Python, C# and Java, a command-line client and an MCP server. Each target vendors its small runtime, so a generated SDK has no backend dependency. The output is formatted and deterministic, so regenerating an unchanged spec changes nothing.

Example

clients generate --spec openapi.json --target go --out ./clients/go
clients generate --app src/app.ts --target python --out ./clients/python

Reference

Value Default What it does Watch for
input spec — the OpenAPI document (file or object) → IR a non-backend spec still works via the IR seam
targets (ts, go, rust, python, csharp, java, cli, mcp) — which artifacts to emit each target is an independent emitter reading only the IR
output dir — where the generated package lands one package per target with its build manifest
formatter post-pass on gofmt for go and cli, ruff for python, rustfmt for rust, oxfmt for ts — one row per target in gen/formatters.ts; csharp and java are not formatted, their formatters working over a project rather than a stream a formatter it cannot find is named on stderr and skipped, since emitted source is valid either way; CLIENTS_REQUIRE_FORMATTERS=1 makes that fail the run instead; oxfmt alone stays quiet, being a declared optional peer; an override ($RUFF, $GOFMT, $RUSTFMT) that points at nothing is refused by name
runtime vendored glue vendored inline, depends on the ecosystem lib by version range; an SDK ships only the transports its operations use (SSE, WebSocket, realtime), so a plain HTTP API carries none of them no per-language runtime package is published
TanStack Query adapter (ts) off --ts-tanstack-query also writes <stem>.tanstack-query.gen.ts: option factories for every operation, reads split from writes by the service map's method, and the SDK's onInvalidate hook as query keys @tanstack/query-core is the consumer's own dependency, imported for types only; no flag, no file, and dropping the flag deletes it
single-flight handler (ts) off --ts-single-flight also writes <stem>.single-flight.gen.ts: singleFlightHandler and runSingleFlight run one write, then the reads its x-invalidate made stale, in one request, every part checked against the service map first a server's file the index never names; refused for a document with no write whose x-invalidate names a read; no flag, no file
Standard Webhooks verify (ts) when declared a document whose webhooks carry x-backend-webhook also gets <stem>.webhook.gen.ts: verifyWebhook(body, headers, secret) checks the signature on WebCrypto and returns a WebhookEvent typed by its type, known: false for one the document does not declare a receiver imports from that file, not the index: it carries the whole verifier and no client; the other languages follow
type extraction — extract middleware ctx/chain types from a TS backend app via the ts-morph compiler API needs ts-morph (optional peer); only for TS backend apps
naming / sanitizer — one shared, fuzzed string-escape + identifier layer across all emitters raw spec text never reaches source
determinism on stable, code-unit-ordered output across machines localeCompare is banned in emitters (host-locale drift)