feat(openapi-ts): allow disabling generation of operation types#3870
feat(openapi-ts): allow disabling generation of operation types#3870uoyoCsharp wants to merge 1 commit into
Conversation
|
|
|
Someone is attempting to deploy a commit to the Hey API Team on Vercel. A member of the Team first needs to authorize it. |
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3870 +/- ##
==========================================
- Coverage 39.58% 39.58% -0.01%
==========================================
Files 532 532
Lines 19581 19585 +4
Branches 5835 5836 +1
==========================================
+ Hits 7751 7752 +1
- Misses 9582 9585 +3
Partials 2248 2248
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Important
Runtime behavior is correct, but this user-facing feature ships without a changeset, without docs updates, and without test coverage. Please add all three before merge.
TL;DR — Adds an enabled?: boolean toggle (with false/{ enabled: false } shorthand) to the requests, responses, and errors sub-configs of @hey-api/typescript, so users who only need model definitions can suppress the per-operation *Data/*Responses/*Response/*Errors/*Error aliases.
Key changes
- Add
FeatureToggleto three sub-configs —errors,requests, andresponsesnow intersect withFeatureToggle, matching the existingenumspattern in the same file and the Valibot/Zod precedent. - Boolean shorthand mappers —
valueToObjectgainsboolean: (enabled) => ({ enabled })for each of the three configs, soerrors: falseresolves to a complete config object with the naming defaults preserved. - Runtime guards in
operationToType— emission of thedata,errors/error, andresponses/responsesymbols is gated on the correspondingenabledflag; paired derived aliases (*Error,*Response) are correctly nested inside the parent gates, so they cannot leak when their parent is disabled.
Summary | 3 files | 1 commit | base: main ← feat/typescript-operation-types-enabled-toggle
Behavior is correct, but the surface is undocumented and untested
Before: Operation types (
*Data,*Errors,*Error,*Responses,*Response) were always emitted whenever the@hey-api/typescriptplugin ran.
After: Each family can be suppressed viarequests: false/errors: false/responses: false(or the object form), with defaults preserving today's behavior.
I traced the diff end-to-end against valueToObject's merge semantics in packages/shared/src/config/utils/config.ts and against every cross-plugin consumer of these symbols. The runtime side of the change is sound:
- The boolean mapper preserves the other naming defaults —
errors: falsestill produces{ enabled: false, case, error: '{{name}}Error', name: '{{name}}Errors' }, so any code path that readsplugin.config.errors.errorkeeps working. - All cross-plugin consumers I checked (
@hey-api/sdk,@tanstack/*,@pinia/colada,fastify,nestjs,@angular/common) usequerySymbolwith explicit fallbacks ('unknown','never',DefaultError), notreferenceSymbol. Disabling the toggles widens downstream output but does not produce dangling references or broken imports.
The actionable gaps are operational, not behavioral:
- No changeset.
.changeset/contains only the scaffolding files. This is a user-facing feature on@hey-api/openapi-tsand the repo auto-publishes via Changesets — without an entry it will not appear in the release notes. - Docs not updated.
docs/openapi-ts/plugins/typescript.mdcurrently documents only.nameand.caseforrequests/responsesand does not mentionerrorsat all. The newenabledflag should be documented for all three, ideally with the boolean-shorthand example from the PR description. - Zero test coverage for the new toggles. A repo-wide grep across
packages/openapi-ts-tests/**forenabled: false/errors: false/requests: false/responses: falsereturns no hits, and there is no__tests__/directory under the typescript plugin. The minimum credible coverage would be one snapshot scenario per toggle underpackages/openapi-ts-tests/main/test/__snapshots__/3.1.x/plugins/@hey-api/typescript/, exercising both the object form and the boolean shorthand so the new mapper code is hit.
config.ts · shared/operation.ts · types.ts
Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:
packages/openapi-ts/src/plugins/@hey-api/typescript/config.ts:88(RIGHT) — line 88 (RIGHT) is not inside a diff hunk
Claude Opus | 𝕏
| .export() | ||
| .type(dataResult?.type ?? $.type('never')); | ||
| plugin.node(dataNode); | ||
| if (plugin.config.requests.enabled) { |
There was a problem hiding this comment.
Minor: dataResult from processor.process({...}) above (the call that fills path: [...path, operation.id, 'data']) is still computed when requests.enabled === false, then discarded. The data-shape processing is the most expensive step here, so it would be cleaner to move it inside this guard alongside the symbol registration.

Description
When using
@hey-api/typescriptplugin, I only need the model/definition types (e.g.,Pet,Order,User,Category) from my OpenAPI spec(demo: https://petstore.swagger.io/v2/swagger.json ) — not the operation-related types likeAddPetData,AddPetResponse,AddPetErrors, etc.My project uses its own HTTP client (not
@hey-api/client-*), so the operation types (*Data,*Response,*Errors) are unnecessary and add noise to the generated output.Current Behavior
The
@hey-api/typescriptplugin always generates all type categories:The
requests,responses, anderrorsconfig options only control naming patterns, not whether these types are generated at all.Expected Behavior
Allow disabling generation of operation types via
falseor{ enabled: false }:This would produce a clean
types.gen.tscontaining only model definitions:Use Case
Many projects use
@hey-api/openapi-tsonly for type generation — they have their own HTTP clients (Axios wrappers, uni-app request adapters, custom fetch implementations, etc.) and only need the schema definitions for type-safe request/response typing. For example:In this scenario, the operation types are dead code that clutters the generated output.
Workaround
Currently I'm using selective re-export as a workaround:
This works but requires manual maintenance whenever the API spec adds new models.
Environment
@hey-api/openapi-ts: 0.97.1