Skip to content

feat(codegen): Hey API generator path - #138

Merged
NoZiL merged 3 commits into
mainfrom
feat/125-hey-api-codegen
Nov 13, 2026
Merged

NoZiL merged 3 commits into
mainfrom
feat/125-hey-api-codegen

Conversation

@NoZiL

@NoZiL NoZiL commented Nov 13, 2026

Copy link
Copy Markdown
Owner

What and why

Codegen half of ADR 0027: generator: "hey-api" runs @hey-api/openapi-ts 0.99.x on each major's merged spec.

  • Output: Hey API's files go in 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 own openapi-ts.config.* is not merged into our settings.
  • Open enums: $resolvers.string and $resolvers.union on @hey-api/typescript. Nullable ones work too, including 3.0 nullable: true.
  • Gating data: operation ids and export names are read back from Hey API's IR and symbol registry, never re-derived (e.g. delete → delete_). Codegen fails if an operation in meta.ops lacks an id, its sdk function or its TanStack helper, or if two re-exported functions share a name. meta.ts gains opIds, and core.ts / gated.ts split the functions into floor operations and newer ones. client.ts exposes them as $api / $gated.
  • Auto-detection: Hey API is tried last (decided in ADR 0027).
  • Pruning: each 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 a generator change. Files codegen never wrote are kept.
  • loadGenerator() now returns kind: "schema" | "sdk". The Hey API output types are exported from openapi-versions/codegen.

Don't release before #126. The generated client.ts imports openapi-versions/hey-api, which #126 adds. Until then the fixture's client.ts is excluded from tsc (tsconfig.json, marked to drop in #126).

Not in this PR:

Review: two /code-review high passes on origin/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, empty JobError messages, a misleading ENOENT on 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 check passes (what CI runs)
  • pnpm changeset added for any change to the published package (.changeset/hey-api-generator.md, minor)
  • Generated output was not edited by hand (playground/generated, test/fixtures/generated)
  • ADR added or superseded in docs/adr/ if this touches a trigger in AGENTS.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

NoZiL and others added 3 commits November 13, 2026 17:55
`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]>
@NoZiL

NoZiL commented Nov 13, 2026

Copy link
Copy Markdown
Owner Author

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 generator key, switches stacks silently if openapi-typescript or openapi-typesafe later shows up in node_modules, for example hoisted by another dependency. The next codegen then writes schema.d.ts and an openapi-fetch client.ts, and the manifest prunes sdk/, core.ts and gated.ts. Every $api.xxxOptions import breaks at compile time. It's loud, not silent at runtime, but confusing.

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 generator: "hey-api" explicitly, since its calling style is different anyway. That would amend ADR 0027. Your call: say so and I'll do it in a follow-up with a small amending ADR.

@NoZiL
NoZiL merged commit 63d0d6c into main Nov 13, 2026
1 check passed
@NoZiL
NoZiL deleted the feat/125-hey-api-codegen branch November 13, 2026 22:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Codegen: add a Hey API generator path

1 participant