Skip to content

chore: remove unused buildKeys module - #205

Merged
7nohe merged 1 commit into
mainfrom
claude/awesome-napier-4a3b74
Aug 11, 2026
Merged

chore: remove unused buildKeys module#205
7nohe merged 1 commit into
mainfrom
claude/awesome-napier-4a3b74

Conversation

@7nohe

@7nohe 7nohe commented Aug 11, 2026

Copy link
Copy Markdown
Owner

What

Deletes src/tsmorph/buildKeys.mts and tests/tsmorph/buildKeys.test.ts, and adds two tests to tests/parseOperations.test.ts.

Why

buildKeys.mts has been dead code since the ts-morph migration (606ec44). Nothing under src/ imports it and it is not re-exported from src/tsmorph/index.mts, so it was unreachable through any declared package export — package.json maps the package root only to dist/generate.mjs. (It was still compiled and published, since files: ["dist"] ships the whole output directory.) Its only consumer was its own test file.

More importantly it is actively misleading. It emits a naming scheme the generator does not produce:

buildKeys.mts (deleted) actual generated output
query key findPetsQueryKey useFindPetsKey
key fn FindPetsQueryKeyFn UseFindPetsKeyFn
infinite queries not supported UseFindPaginatedPetsInfiniteKeyFn

Query keys are really built by buildQueryKeyConst, buildMutationKeyConst, buildQueryKeyFn, buildMutationKeyFn, buildInfiniteQueryKeyConst and buildInfiniteQueryKeyFn in src/tsmorph/buildCommon.mts, called from generateFiles.mts. Anyone reading buildKeys.mts to understand key generation is led to the wrong conclusion.

Why the added tests

The deleted module was at 100% coverage (18 lines / 8 functions / 8 branches), so removing it takes well-covered lines out of the denominator and lowers the aggregate:

metric before delete only this PR threshold
lines 99.05% 99.02% 99.22% 95
statements 98.36% 98.30% 98.49% 95
functions 99.29% 99.24% 99.24% 95
branches 90.07% 89.75% 90.57% 90

Rather than lower the threshold, this covers two genuinely untested paths in buildGenerationContext — the missing-service-file throw and the missing-models-file [] fallback. parseOperations.mts branch coverage goes from 76% to 80%.

The missing-models fallback matters downstream: empty modelNames suppresses the types.gen import in every generated file (src/tsmorph/projectFactory.mts:103). It is also unreachable through real hey-api output — types.gen is always emitted, with per-operation Data/Response types, even for a spec that declares no components.schemas — so a hand-built project is the only way to reach it.

Verification

  • tsc -p tsconfig.json clean; biome clean
  • 182 tests pass (194 → 182: −14 deleted buildKeys tests, +2 added)
  • Generated output is byte-identical: snapshotted examples/react-app/openapi (26 files) built from the pre-deletion dist, regenerated with the post-deletion dist, diff -r shows no difference

Notes for the reviewer

Two follow-ups found while doing this, deliberately left out of scope:

  • src/tsmorph/generateFiles.mts:48-76 is a verbatim private copy of the exported, already-tested buildCommonFileImports / buildHookFileImports in projectFactory.mts:143-171, and three if (hook) guards there are unreachable (the call sites pre-filter on isPaginatable, and the builders return null only when !isPaginatable). Fixing both would raise that file's 68.75% branch coverage by removing branches rather than adding tests — and would unblock switching to coverage.thresholds.perFile, which a global aggregate can't safely express today.
  • tests/inputs/no-models.yaml is orphaned and broken: its only consumer was deleted in 606ec44, and it was already test.skipped before that due to an upstream @hey-api/openapi-ts error.

`src/tsmorph/buildKeys.mts` has been dead code since the ts-morph
migration (606ec44). Nothing under `src/` imports it and it is not
re-exported from `src/tsmorph/index.mts`, so it was unreachable through
any declared package export — `package.json` maps the package root only
to `dist/generate.mjs`. (It was still compiled and published, since
`files: ["dist"]` ships the whole output directory.) Its only consumer
was its own test file.

Worse, it is actively misleading: it emits a different naming scheme
than the generator actually produces (`findPetsQueryKey` /
`FindPetsQueryKeyFn` vs. the real `useFindPetsKey` / `UseFindPetsKeyFn`)
and has no infinite-query support at all. Query keys are really built by
`buildQueryKeyConst`, `buildMutationKeyConst`, `buildQueryKeyFn`,
`buildMutationKeyFn`, `buildInfiniteQueryKeyConst` and
`buildInfiniteQueryKeyFn` in `src/tsmorph/buildCommon.mts`, called from
`generateFiles.mts`, so anyone reading `buildKeys.mts` to understand key
generation is led to the wrong conclusion.

Because the deleted module was at 100% coverage, dropping it lowers the
aggregate branch coverage from 90.07% to 89.75%, under the 90%
threshold. Two tests are added for the previously untested error and
fallback paths in `buildGenerationContext` (missing service file,
missing models file), which brings branches to 90.57% and raises
`parseOperations.mts` branch coverage from 76% to 80%. The missing-models
fallback is unreachable through real hey-api output — it always emits
`types.gen` — so a hand-built project is the only way to cover it.

Verified: `tsc -p tsconfig.json` clean, biome clean, 182 tests pass, and
the generated example output is byte-identical before and after.
@vercel

vercel Bot commented Aug 11, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openapi-react-query-codegen Ready Ready Preview Aug 11, 2026 10:31am

@7nohe
7nohe merged commit 53a2eef into main Aug 11, 2026
2 of 5 checks passed
@7nohe
7nohe deleted the claude/awesome-napier-4a3b74 branch August 11, 2026 10:32
@github-actions

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 99.22% (🎯 95%) 509 / 513
🟢 Statements 98.49% (🎯 95%) 524 / 532
🟢 Functions 99.24% (🎯 95%) 132 / 133
🟢 Branches 90.57% (🎯 90%) 221 / 244
File CoverageNo changed files found.
Generated in workflow #438 for commit b7ffa32 by the Vitest Coverage Report Action

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.

1 participant