Typed request helpers against staging
Point the generated helpers at a non-production host with baseURL, so every cy.request() runs against staging. Keep pluginTs() in the array for the request and response types.
typescript
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', clean: true },
plugins: [
pluginTs({ output: { path: 'models.ts', mode: 'file' } }),
pluginCypress({
output: { path: 'cypress', mode: 'directory' },
baseURL: 'https://staging.example.com',
}),
],
})Output example
typescript
import type { GetPetByIdOptions, GetPetByIdResponse } from '../models'
export function getPetById({ path }: GetPetByIdOptions, options: Partial<Cypress.RequestOptions> = {}): Cypress.Chainable<GetPetByIdResponse> {
return cy.request<GetPetByIdResponse>({
method: 'GET',
url: `https://staging.example.com/pet/${path.petId}`,
...options
}).then((res) => res.body)
}The baseURL is inlined directly into the template literal, so every helper resolves against staging.example.com without any extra runtime configuration.
typescript
import { getPetById } from '../src/gen/cypress'
describe('Pet API', () => {
it('returns the pet by id', () => {
getPetById({ path: { petId: 1n } }).then((res) => {
expect(res.id).to.eq(1n)
})
})
})