When an external schema file (e.g. RecordKeeper.yaml) is first encountered as the items of an array response, kubb generates the wrong name for that schema: itemsSchema instead of recordKeeperSchema. Any subsequent $ref to the same file (e.g. as a request body property) imports from "./itemsSchema.ts" — a file that is never generated — causing a build failure with UNRESOLVED_IMPORT.
@kubb/oas 4.27.3 switched the bundler from @redocly/openapi-core to @readme/openapi-parser. The new bundler inlines external schemas at the first JSON Pointer path where they appear rather than always registering them at #/components/schemas/<Name>.
In this reproduction:
GET /record-keepersis declared first, withRecordKeeper.yamlas arrayitems.- The bundler inlines the schema at:
#/paths/~1record-keepers/get/responses/200/content/application~1json/schema/items POST /proposalsreferences the same file; the bundler resolves it to the already-inlined path ending in/items.- kubb extracts the last path segment:
"items"→resolveName("items", "function")→"itemsSchema". createProposalMutationRequestSchema.tsimports{ itemsSchema } from "./itemsSchema.ts", butitemsSchema.tsis never written.
pnpm install
pnpm generate:brokenThen inspect the generated file:
cat src/gen/zod/createProposalSchema.tsimport { recordKeeperSchema } from "./recordKeeperSchema.ts";import { itemsSchema } from "./itemsSchema.ts";src/gen/zod/itemsSchema.ts does not exist. Any bundler (or Node's native ESM loader) will fail:
Error: UNRESOLVED_IMPORT: ./itemsSchema.ts
- 4.27.3 and above — introduced
@readme/openapi-parseras the bundler
- 4.27.2 and below — used
@redocly/openapi-core, which always assigned canonical#/components/schemas/<Name>refs to named external files
To verify with a working version:
pnpm add -D @kubb/cli@4.27.2 @kubb/core@4.27.2 @kubb/plugin-oas@4.27.2 @kubb/plugin-zod@4.27.2
pnpm generate:broken # now generates correctly
cat src/gen/zod/createProposalMutationRequestSchema.ts
# → imports { recordKeeperSchema } from "./recordKeeperSchema.ts"Register shared schemas explicitly in the root OpenAPI file's components.schemas section so the bundler assigns them canonical #/components/schemas/<Name> refs:
# openapi.yaml
components:
schemas:
RecordKeeper:
$ref: ./components/schemas/RecordKeeper.yamlWith this in place, the bundler inlines the schema at #/components/schemas/RecordKeeper and kubb correctly derives the name recordKeeperSchema.