Skip to content
How-to guides

Customize names and paths

Resolvers name every symbol and file Kubb generates. The resolver option on each code-generating plugin patches a single naming rule, so you change what things are called or where files land without forking the plugin.

Set a plugin's resolver option to change generated identifiers and file paths. Supply only the methods you need to replace. Other methods keep their defaults.

Write overrides as regular methods, not arrow functions, when they use this. See resolver overrides for the this rules and signatures.

Rename identifiers

Prefix TypeScript names while preserving the plugin's PascalCase preset:

prefix.ts
import { pluginTs, resolverTs } from '@kubb/plugin-ts'

pluginTs({
  resolver: {
    name(name) {
      return `Api${resolverTs.name(name)}`
    },
  },
})

Rename and relocate files

file.baseName builds a file's name, extension included. Here it renames every Faker file to <name>.mock.ts instead of the plugin default.

file-name.ts
import { pluginFaker } from '@kubb/plugin-faker'

pluginFaker({
  resolver: {
    file: {
      baseName({ name, extname }) {
        return `${name}.mock${extname}`
      },
    },
  },
})

file.path replaces the plugin's output.path and group layout, so the resolver owns where the file lands. Kubb resolves the returned path against the root output.path directory, and the path must stay inside that directory. This override moves every Faker file from mocks/ to fixtures/. The plugin's barrel covers its output.path folder, so the moved files get no index.ts.

file-path.ts
import { pluginFaker } from '@kubb/plugin-faker'

pluginFaker({
  resolver: {
    file: {
      path({ baseName }) {
        return `fixtures/${baseName}`
      },
    },
  },
})

Namespaced names

Override query.keyName to rename React Query keys. Use this.name to retain the active naming rule:

query-key.ts
import { pluginReactQuery } from '@kubb/plugin-react-query'

pluginReactQuery({
  resolver: {
    query: {
      keyName(node) {
        return `${this.name(node.operationId)}Key`
      },
    },
  },
})

@kubb/plugin-ts names each response type through response.status. This override rewrites the template so a 200 response reads GetPetById200Response instead of the default GetPetByIdStatus200.

response.ts
import { pluginTs } from '@kubb/plugin-ts'

pluginTs({
  resolver: {
    response: {
      status(node, statusCode) {
        return this.name(`${node.operationId} ${statusCode} response`)
      },
    },
  },
})