plugins: [pluginCypress()]OpenAPI to Cypress request generator
@kubb/plugin-cypress
Generates a typed cy.request() wrapper per OpenAPI operation, so your Cypress tests call the API through helpers and catch broken calls at compile time.
- Downloads59.9K/ monthnpm, last 30 days
- GitHub stars14kubb-labs/plugins
- Unpacked size192.8kBv5.3.6 on npm
- Latest release17h agov5.3.6 · Nov 22, 2026
The Cypress plugin generates a typed cy.request() helper for each operation in your OpenAPI spec. A helper returns Cypress.Chainable<{Operation}Response>.
Each helper takes grouped path, query, headers, cookies, and body parameters named after the spec.
Installation
kubb add plugin-cypressbun add -d @kubb/plugin-cypresspnpm add -D @kubb/plugin-cypressnpm install --save-dev @kubb/plugin-cypressyarn add -D @kubb/plugin-cypresskubb add installs the version the Kubb registry pins and adds pluginCypress() to kubb.config.ts. It needs a kubb.config.ts, so run kubb init first in a new project.
Setup
- Add
@kubb/plugin-tsfor the request and response types. - Install
cypressv15 or v16 in the project that runs the tests. - Add
"types": ["cypress"]to the tsconfig that covers the generated files. The helpers use the globalCypressnamespace.
Options worth knowing
| Option | Default | What it does |
|---|---|---|
baseURL | None | Prepends a host. Without it, Cypress resolves the path against its own baseUrl. |
The other options are the shared plugin options.
Example
This config writes the helpers to src/gen/cypress. contentType keeps the JSON response of the Petstore spec, which also declares XML, so bodies are not typed as Pet | string. integerType: 'number' types the int64 petId as number.
import { defineConfig } from 'kubb/config'
import { adapterOas } from '@kubb/adapter-oas'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginCypress } from '@kubb/plugin-cypress'
export default defineConfig({
input: './petStore.yaml',
output: { path: './src/gen' },
adapter: adapterOas({ contentType: 'application/json', integerType: 'number' }),
plugins: [
pluginTs(),
pluginCypress({ output: { path: 'cypress', mode: 'directory' } }),
],
})import type { GetPetByIdOptions, GetPetByIdResponse } from '../types/GetPetById'
export function getPetById({ path }: GetPetByIdOptions, options: Partial<Cypress.RequestOptions> = {}): Cypress.Chainable<GetPetByIdResponse> {
return cy
.request<GetPetByIdResponse>({
method: 'GET',
url: `/pet/${path.petId}`,
...options,
})
.then((res) => res.body) as Cypress.Chainable<GetPetByIdResponse>
}import { getPetById } from '../../src/gen/cypress/getPetById'
describe('Pet API', () => {
it('returns the pet by id', () => {
getPetById({ path: { petId: 1 } }).then((pet) => {
expect(pet.name).to.be.a('string')
})
})
})Dependencies
Extensions that must be in the same config as Cypress.
