Skip to content
Playwright logo

Playwright

Communityv0.1.0

kubb-plugin-playwright

kubb add ericlm/kubb-plugin-playwright

Options

Pass these options to pluginPlaywright(). All of them are optional, and shared options link to Shared plugin options.

Options overview

OptionPurposeDefault
outputWhere files are written: path, mode, barrel, banner, footer.{ path: 'playwright', barrel: { type: 'named' } }
groupSplit output by tag or path: type, name.None
baseURLURL prefix written into every generated request.None
includeKeep only operations that match.All supported operations
excludeSkip operations that match. Exclusion wins over include.[]
overrideApply different options per pattern.[]
resolverCustomize generated names and file paths.resolverPlaywright
macrosRewrite operation nodes before printing, in order.[]

A custom output replaces the default object, so add barrel: { type: 'named' } to keep named exports. When an override sets output, also set output.mode, because Kubb does not infer it again.

Options, PluginPlaywright, and ResolverPlaywright are exported by kubb-plugin-playwright. The shared option types come from @kubb/kit.

Option details

baseURL

Prepends a URL to each operation path. Trailing slashes are removed before joining.

Typestring
Requiredfalse
kubb.config.ts
import { pluginPlaywright } from 'kubb-plugin-playwright'

pluginPlaywright({ baseURL: 'https://api.example.com/v1' })

The URL for /pets/{petId} becomes https://api.example.com/v1/pets/ followed by the encoded ID. The URL is part of the generated code.

When omitted, helpers use the relative operation path, and Playwright resolves it against the request context baseURL. OpenAPI servers are ignored. Leave baseURL unset to pick the environment when you create the context.

resolver

The default resolver prefixes helper names and file names with pw, starting from the operation ID. For getPetById, the function and its export are pwGetPetById, in pwGetPetById.ts.

TypeResolverPatch<ResolverPlaywright>
Requiredfalse

Override name and file.baseName together to change the prefix of both functions and files. This example reuses the default casing and produces apiGetPetById in apiGetPetById.ts:

kubb.config.ts
import { pluginPlaywright, resolverPlaywright } from 'kubb-plugin-playwright'

function resolveName(operationId: string) {
  return resolverPlaywright.name(operationId).replace(/^pw/, 'api')
}

pluginPlaywright({
  resolver: {
    name: resolveName,
    file: {
      baseName: ({ name, extname }) => `${resolveName(name)}${extname}`,
    },
  },
})

Overriding only name renames the function and its export but keeps the default file name. Methods you leave out keep their defaults. Type names and their imports still come from the @kubb/plugin-ts resolver.

Per-request Playwright options do not belong here. Pass them in the helper's options argument, described in Native options and responses.