@kubb/plugin-cypress
@kubb/plugin-cypress turns your OpenAPI operations into typed cy.request() wrappers, one helper per operation. Each helper types its path params, body, query, and response, so a broken API call fails at compile time instead of in the test runner. Use the helpers in before and beforeEach hooks to seed data, in custom commands, or in API-only tests.
Each helper takes its parameters as a single grouped options object shaped as { body, path, query, headers }, with camelCase property names. The request still sends the original parameter names from the spec, and Kubb writes that mapping for you. A helper resolves to the response body and its return type is Cypress.Chainable<{Operation}Response>.
Installation
bun add -d @kubb/plugin-cypress@betapnpm add -D @kubb/plugin-cypress@betanpm install --save-dev @kubb/plugin-cypress@betayarn add -D @kubb/plugin-cypress@betaDependencies
This plugin depends on @kubb/plugin-ts for the request, parameter, and response types it imports. Keep pluginTs() in the plugins array.
Example
import { defineConfig } from 'kubb'
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',
barrel: { type: 'named' },
banner: '/* eslint-disable */',
},
group: {
type: 'tag',
name: ({ group }) => `${group}Requests`,
},
}),
],
})import { getPetById } from '../gen/cypress/petRequests'
describe('Pet API', () => {
it('returns the pet by id', () => {
getPetById({ path: { petId: 1 } }).then((pet) => {
expect(pet.id).to.eq(1)
})
})
})