Beta You're reading the docs for Kubb v5, which is currently in beta. View the stable v4 docs
Skip to content

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 and file methods that generators call, and both 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.

resolver.ts
typescript
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.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.

merge.ts
typescript
const  = .(, {
  () {
    return `Custom${this..()}`
  },
})