plugins: [pluginPlaywright()]Playwright
kubb-plugin-playwright
Generates a typed Playwright request helper per OpenAPI operation that returns the native APIResponse with a typed json().
- GitHub stars0Ericlm/kubb-plugin-playwright
- Unpacked size85.6kBv0.1.0 on npm
- Latest release5h agov0.1.0 · Oct 31, 2026
The Playwright plugin generates a typed request helper for each operation in your OpenAPI spec. Each helper calls request.fetch on a Playwright APIRequestContext and returns the native APIResponse, with response.json() typed from the spec.
The default resolver turns getPetById into pwGetPetById, written to pwGetPetById.ts. The pw prefix lets these helpers share a barrel with client helpers such as Fetch or Axios. Type names come from @kubb/plugin-ts unchanged.
Installation
bun add -d kubb-plugin-playwrightpnpm add -D kubb-plugin-playwrightnpm install --save-dev kubb-plugin-playwrightyarn add -D kubb-plugin-playwrightOr run kubb add ericlm/kubb-plugin-playwright to install the version the Kubb registry pins and add pluginPlaywright() to kubb.config.ts.
Setup
- Add
@kubb/plugin-tsto the plugins array for the request and response types. - Install
@playwright/test1.63 or newer in the project that runs the tests. Earlier versions have no genericAPIResponse.
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { defineConfig } from 'kubb/config'
import { pluginPlaywright } from 'kubb-plugin-playwright'
export default defineConfig({
input: './petStore.yaml',
adapter: adapterOas(),
output: { path: './src/gen' },
plugins: [pluginTs(), pluginPlaywright()],
})The defaults write named exports to src/gen/playwright and types to src/gen/types.
Example
Pass the Playwright Test request fixture, or a context from request.newContext(), as request. Each helper takes one object with only the groups the operation declares: path, query, body, and headers, plus native fetch options.
import { expect, test } from '@playwright/test'
import { pwGetPetById } from './src/gen/playwright'
test.use({ baseURL: 'http://127.0.0.1:3000' })
test('returns a pet', async ({ request }) => {
const response = await pwGetPetById({
request,
path: { petId: '123' },
query: { tags: ['friendly', 'small'] },
options: { timeout: 5_000 },
})
expect(response.ok()).toBeTruthy()
const pet = await response.json()
expect(pet.id).toBe('123')
})A group is required when it holds a required parameter, and body is required when requestBody.required is true. Path values are URI encoded, and query arrays become repeated keys such as tags=friendly&tags=small.
Options worth knowing
baseURLis written into every generated URL. Without it, helpers use relative paths and Playwright resolves them against the contextbaseURL. OpenAPIserversare ignored.resolverrenames helpers and files, for example to replace thepwprefix.
See Options for every option and its default.
Limits
- The response type is the success response type from
@kubb/plugin-ts. Error bodies, such as a 404 payload, are not part of thejson()type, and the received data is not validated. - Request bodies support JSON (including
+jsonmedia types),application/x-www-form-urlencoded, andmultipart/form-data. Operations whose first body content type is something else are skipped. - Operations with cookie parameters are skipped.
- OpenAPI
style,explode, andallowReservedare not applied. Pass prepared values through the nativeoptions.params,options.form, oroptions.multipartfor other formats.
The generated code makes network requests only when your tests call a helper. The plugin itself writes only inside its output path.
Dependencies
Extensions that must be in the same config as Playwright.