Customize names and paths
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:
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.
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.
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:
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.
import { pluginTs } from '@kubb/plugin-ts'
pluginTs({
resolver: {
response: {
status(node, statusCode) {
return this.name(`${node.operationId} ${statusCode} response`)
},
},
},
})