Resolvers
createResolver
createResolver builds a Resolver instance that controls file naming and path resolution for a plugin. Pass the plugin-specific fields directly as an object; this inside a method reaches sibling resolver methods.
The object must include at least { pluginName }. The built-in machinery lives under resolver.default (default.name, default.file, default.options, default.path, default.banner, default.footer), exposed as a getter that always reaches the untouched defaults. The resolver exposes name, file, and imports methods that generators call, and name and file fall back to the defaults until the object overrides them. Set name to a function for identifier casing, and file to an object whose baseName builds the base name (extension included) and whose path returns the full path. Use this to reach sibling members, so a namespace method calls this.name(...) for the plugin's identifier casing.
import { } from 'kubb/kit'
import type { , } from 'kubb/kit'
// Extend the base Resolver with plugin-specific naming namespaces.
type = & {
: {
(: { : string }): string
}
}
type = <'plugin-example', object, object, >
export const = <>({
: 'plugin-example',
() {
return `${.(0).()}${.(1)}`
},
: {
() {
return this.(.)
},
},
})Auto-injected resolver defaults
| Method | Default behavior |
|---|---|
name | Top-level identifier casing, delegates to default.name |
file | Top-level FileNode builder, delegates to default.file |
default.name | The built-in generated-identifier casing |
default.options | Applies exclude, include, and override filters |
default.path | Resolves to output.path, with optional tag/path-based subdirectories |
default.file | Constructs a full FileNode using the resolver's file.baseName casing (default toFilePath) |
default.banner | Returns output.banner or the standard "Generated by Kubb" header |
default.footer | Returns output.footer when set |
resolver.imports
resolver.imports builds one import entry per $ref in a schema tree, so a generator emits the imports for every schema the current node references. Each ref resolves through ast.resolveRefName, which prefers the node's targetName (set by the adapter for collision renames or by a rename macro) and falls back to the pointer's last segment. The resulting names and paths go through the resolver's own name and file conventions. extname defaults to .ts.
const = .({ , , })
// → [{ kind: 'Import', name: ['pet'], path: '/src/types/pet.ts' }]Pass name to override how a referenced schema name becomes the imported identifier, for example to point enum refs at a suffixed type name:
const = .({
,
,
,
: () => `${.()}Type`,
})Resolver.merge
Resolver.merge(base, patch) returns a new resolver with patch's fields layered over base's and every helper re-bound. A top-level name replaces, while file and each namespace merge per member, so overriding query.name keeps the base query.keyName. Framework code uses it to apply a setResolver partial override over a plugin's built-in resolver, and you can call it yourself when composing resolvers. Type a patch with ResolverPatch<T> to keep this and namespace shapes checked against the target resolver.
const = .(, {
() {
return `Custom${this..()}`
},
})