Repository navigation
feat(codegen): Hey API generator path - #138
Conversation
`generator: "hey-api"` runs @hey-api/openapi-ts 0.99.x on each major's merged spec (ADR 0027). Its output is staged into v<n>/sdk/ with the rest of the generation (ADR 0021, 0023). Open enums use $resolvers. Operation ids and export names are read back from Hey API, and codegen fails when an operation has none. meta.ts gains opIds, and core.ts/gated.ts split the operation functions. Hey API comes last in auto-detection. Files a previous generation wrote and this one does not are pruned from v<n>/. The runtime entry the generated client.ts imports (openapi-versions/hey-api) is #126; the fixture's client.ts is excluded from tsc until then. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Pass Hey API an explicit, empty config file, so an app's own openapi-ts.config.* is not merged into codegen's settings. - Prune stale files only in a v<n> dir codegen wrote before (meta.ts header), so an app's own files next to the output are kept. - Require both the sdk function and the TanStack helper for every operation, so a symbol-registry change cannot silently drop helpers. - One name for the sdk dir constant; export the generator and Hey API output types from openapi-versions/codegen. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Prune from a per-major manifest (.openapi-versions-files.json) of what the previous run wrote, instead of guessing from file names: files codegen never wrote are kept on every run, not only the first. - Unwrap Hey API's empty JobError, and report an unreadable spec instead of an ENOENT on the temp folder. - Fail codegen when two re-exported functions share a name (e.g. `GET /users` options and the sdk function of `GET /users/options`). - Map lookup in checkOperations; say that .openapi-tsrc is not isolated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Open review finding for the maintainer (not fixed): auto-detection of Hey API. The second review pass pointed out a risk. An app on Hey API that relies on auto-detection, with no ADR 0027 (accepted) says Hey API comes last in auto-detection, so I kept that. The alternative is to leave Hey API out of auto-detection and require |
What and why
Codegen half of ADR 0027:
generator: "hey-api"runs@hey-api/openapi-ts0.99.x on each major's merged spec.v<n>/sdk/, staged and renamed with the rest under the codegen lock (ADR 0021/0023). Imports are extensionless, there is no barrel, and an empty explicit config file means the app's ownopenapi-ts.config.*is not merged into our settings.$resolvers.stringand$resolvers.unionon@hey-api/typescript. Nullable ones work too, including 3.0nullable: true.delete→delete_). Codegen fails if an operation inmeta.opslacks an id, its sdk function or its TanStack helper, or if two re-exported functions share a name.meta.tsgainsopIds, andcore.ts/gated.tssplit the functions into floor operations and newer ones.client.tsexposes them as$api/$gated.v<n>keeps a manifest (.openapi-versions-files.json) of what it wrote. The next run removes exactly what it wrote before and not now, for example after ageneratorchange. Files codegen never wrote are kept.loadGenerator()now returnskind: "schema" | "sdk". The Hey API output types are exported fromopenapi-versions/codegen.Don't release before #126. The generated
client.tsimportsopenapi-versions/hey-api, which #126 adds. Until then the fixture'sclient.tsis excluded from tsc (tsconfig.json, marked to drop in #126).Not in this PR:
xxxQueryKeyhelpers are not re-exported. Hey API registers them without operation metadata, so finding them would mean re-deriving its names, which ADR 0027 rules out. I'll raise it in Runtime: operation-ID gating for Hey API SDKs #126, where the client surface is designed.Review: two
/code-review highpasses onorigin/main...HEAD. Fixed: app config leaking into Hey API, pruning that could delete the app's files (now manifest-based), the weak op/export check, emptyJobErrormessages, a misleadingENOENTon unreadable specs, duplicate re-export names, and a quadratic lookup. Left for the maintainer: see the PR comment on auto-detection.Closes #125
Checklist
mise run checkpasses (what CI runs)pnpm changesetadded for any change to the published package (.changeset/hey-api-generator.md, minor)playground/generated,test/fixtures/generated)docs/adr/if this touches a trigger inAGENTS.md: covered by ADR 0027 (docs(adr): 0027 support Hey API as a third, opt-in generator stack #133), which this implements; the new optional peer is the range it sets🤖 Generated with Claude Code