Skip to content
Plugin
Cypress
plugins: [pluginCypress()]
Officialv5.0.10kubb >=5.8.3node >=22

Cypress

@kubb/plugin-cypress

Generates a typed cy.request() wrapper per OpenAPI operation so your Cypress tests call the API through generated helpers and catch broken calls at compile time.

kubb add plugin-cypress
cypresse2e-testingapi-testingtest-generationcodegenopenapi

The Cypress plugin generates a typed cy.request() helper for each operation in your OpenAPI spec.

Each helper takes grouped path, query, headers, and body parameters named after the spec. It returns the response body typed as Cypress.Chainable<{Operation}Response>.

Installation

bun add -d @kubb/plugin-cypress

Or run kubb add plugin-cypress to install the version the Kubb registry pins and add pluginCypress() to kubb.config.ts.

Setup

  • Add @kubb/plugin-ts for the request and response types.
  • Install cypress v15 or v16 in the project that runs the tests.
  • Add "types": ["cypress"] to the tsconfig that covers the generated files, because the helpers use the global Cypress namespace.

Options worth knowing

  • baseURL is prepended to every request. Without it, Cypress resolves the path against its own baseUrl.

See Options for every option and its default.

Example

The config below writes the helpers to src/gen/cypress.

kubb.config.ts
import { defineConfig } from 'kubb/config'
import { pluginTs } from '@kubb/plugin-ts'
import { pluginCypress } from '@kubb/plugin-cypress'

export default defineConfig({
  input: './petStore.yaml',
  output: { path: './src/gen' },
  plugins: [
    pluginTs(),
    pluginCypress({ output: { path: 'cypress', mode: 'directory' } }),
  ],
})

A test then calls a helper and gets a typed response body. petId is an int64, which the default adapter types as bigint.

cypress/e2e/pet.cy.ts
import { getPetById } from '../../src/gen/cypress/getPetById'

describe('Pet API', () => {
  it('returns the pet by id', () => {
    getPetById({ path: { petId: 1n } }).then((pet) => {
      expect(pet.name).to.be.a('string')
    })
  })
})

Dependencies

Extensions that must be in the same config as Cypress.