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 returns the file's full path and bypasses the output.path and group layout, so the resolver owns where the file lands. This override moves every Faker file into a mocks/ folder. The returned path may not escape the project root.
import { pluginFaker } from '@kubb/plugin-faker'
pluginFaker({
resolver: {
file: {
path({ baseName, output }) {
return `${output.path}/mocks/${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`)
},
},
},
})