Skip to content
Plugin
Cypress logo
plugins: [pluginCypress()]
Officialv5.3.6kubb >=5.19.0node >=22.22

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.

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

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-cypress

kubb 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-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. The helpers use the global Cypress namespace.

Options worth knowing

OptionDefaultWhat it does
baseURLNonePrepends 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' } }),
  ],
})

Dependencies

Extensions that must be in the same config as Cypress.