|
| 1 | +--- |
| 2 | +layout: doc |
| 3 | + |
| 4 | +title: \@kubb/plugin-cypress |
| 5 | +outline: deep |
| 6 | +--- |
| 7 | + |
| 8 | +# @kubb/plugin-cypress |
| 9 | + |
| 10 | +With the [Cypress](https://docs.cypress.io/app/get-started/why-cypress) plugin you can use any of your API's endpoint as a Cypress request. |
| 11 | + |
| 12 | +## Installation |
| 13 | + |
| 14 | +::: code-group |
| 15 | + |
| 16 | +```shell [bun] |
| 17 | +bun add -d @kubb/plugin-cypress |
| 18 | +``` |
| 19 | + |
| 20 | +```shell [pnpm] |
| 21 | +pnpm add -D @kubb/plugin-cypress |
| 22 | +``` |
| 23 | + |
| 24 | +```shell [npm] |
| 25 | +npm install --save-dev @kubb/plugin-cypress |
| 26 | +``` |
| 27 | + |
| 28 | +```shell [yarn] |
| 29 | +yarn add -D @kubb/plugin-cypress |
| 30 | +``` |
| 31 | + |
| 32 | +::: |
| 33 | + |
| 34 | +## Options |
| 35 | + |
| 36 | +### output |
| 37 | +Specify the export location for the files and define the behavior of the output. |
| 38 | + |
| 39 | +#### output.path |
| 40 | + |
| 41 | +Path to the output folder or file that will contain the generated code. |
| 42 | + |
| 43 | +> [!TIP] |
| 44 | +> if `output.path` is a file, `group` cannot be used. |
| 45 | +
|
| 46 | +| | | |
| 47 | +|----------:|:----------| |
| 48 | +| Type: | `string` | |
| 49 | +| Required: | `true` | |
| 50 | +| Default: | `'cypress'` | |
| 51 | + |
| 52 | +#### output.barrelType |
| 53 | + |
| 54 | +Define what needs to be exported, here you can also disable the export of barrel files. |
| 55 | + |
| 56 | +> [!TIP] |
| 57 | +> Using propagate will prevent a plugin from creating a barrel file, but it will still propagate, allowing [`output.barrelType`](/getting-started/configure#output-barreltype) to export the specific function or type. |
| 58 | +
|
| 59 | +| | | |
| 60 | +|----------:|:--------------------------------| |
| 61 | +| Type: | `'all' \| 'named' \| 'propagate' \| false` | |
| 62 | +| Required: | `false` | |
| 63 | +| Default: | `'named'` | |
| 64 | + |
| 65 | +<!--@include: ../core/barrelTypes.md--> |
| 66 | + |
| 67 | +#### output.banner |
| 68 | +Add a banner text in the beginning of every file. |
| 69 | + |
| 70 | +| | | |
| 71 | +|----------:|:--------------------------------------| |
| 72 | +| Type: | `string \| (oas: Oas) => string` | |
| 73 | +| Required: | `false` | |
| 74 | + |
| 75 | +#### output.footer |
| 76 | +Add a footer text at the end of every file. |
| 77 | + |
| 78 | +| | | |
| 79 | +|----------:|:--------------------------------------| |
| 80 | +| Type: | `string \| (oas: Oas) => string` | |
| 81 | +| Required: | `false` | |
| 82 | + |
| 83 | +### contentType |
| 84 | +<!--@include: ../core/contentType.md--> |
| 85 | + |
| 86 | +### baseURL |
| 87 | +<!--@include: ../plugin-client/baseURL.md--> |
| 88 | + |
| 89 | +### group |
| 90 | +<!--@include: ../core/group.md--> |
| 91 | + |
| 92 | +#### group.type |
| 93 | +Define a type where to group the files on. |
| 94 | + |
| 95 | +| | | |
| 96 | +|----------:|:--------| |
| 97 | +| Type: | `'tag'` | |
| 98 | +| Required: | `true` | |
| 99 | + |
| 100 | +<!--@include: ../core/groupTypes.md--> |
| 101 | + |
| 102 | +#### group.name |
| 103 | + |
| 104 | +Return the name of a group based on the group name, this will be used for the file and name generation. |
| 105 | + |
| 106 | +| | | |
| 107 | +|----------:|:------------------------------------| |
| 108 | +| Type: | `(context: GroupContext) => string` | |
| 109 | +| Required: | `false` | |
| 110 | +| Default: | `(ctx) => '${ctx.group}Requests'` | |
| 111 | + |
| 112 | +### include |
| 113 | +<!--@include: ../core/include.md--> |
| 114 | + |
| 115 | +### exclude |
| 116 | +<!--@include: ../core/exclude.md--> |
| 117 | + |
| 118 | +### override |
| 119 | +<!--@include: ../core/override.md--> |
| 120 | + |
| 121 | +### generators <img src="/icons/experimental.svg"/> |
| 122 | +<!--@include: ../core/generators.md--> |
| 123 | + |
| 124 | +| | | |
| 125 | +|----------:|:------------------------------| |
| 126 | +| Type: | `Array<Generator<PluginMsw>>` | |
| 127 | +| Required: | `false` | |
| 128 | + |
| 129 | + |
| 130 | +### transformers |
| 131 | +<!--@include: ../core/transformers.md--> |
| 132 | + |
| 133 | +#### transformers.name |
| 134 | +Customize the names based on the type that is provided by the plugin. |
| 135 | + |
| 136 | +| | | |
| 137 | +|----------:|:------------------------------------------------------------------------------| |
| 138 | +| Type: | `(name: string, type?: ResolveType) => string` | |
| 139 | +| Required: | `false` | |
| 140 | + |
| 141 | +```typescript |
| 142 | +type ResolveType = 'file' | 'function' | 'type' | 'const' |
| 143 | +``` |
| 144 | +
|
| 145 | +## Example |
| 146 | +
|
| 147 | +```typescript twoslash |
| 148 | +import { defineConfig } from '@kubb/core' |
| 149 | +import { pluginOas } from '@kubb/plugin-oas' |
| 150 | +import { pluginTs } from '@kubb/plugin-ts' |
| 151 | +import { pluginCypress } from '@kubb/plugin-cypress' |
| 152 | + |
| 153 | +export default defineConfig({ |
| 154 | + input: { |
| 155 | + path: './petStore.yaml', |
| 156 | + }, |
| 157 | + output: { |
| 158 | + path: './src/gen', |
| 159 | + }, |
| 160 | + plugins: [ |
| 161 | + pluginOas(), |
| 162 | + pluginTs(), |
| 163 | + pluginCypress({ |
| 164 | + output: { |
| 165 | + path: './cypress', |
| 166 | + barrelType: 'named', |
| 167 | + banner: '/* eslint-disable no-alert, no-console */', |
| 168 | + footer: '' |
| 169 | + }, |
| 170 | + group: { |
| 171 | + type: 'tag', |
| 172 | + name: ({ group }) => `${group}Requests`, |
| 173 | + }, |
| 174 | + }), |
| 175 | + ], |
| 176 | +}) |
| 177 | +``` |
| 178 | +## Links |
| 179 | + |
| 180 | +- [Cypress](https://docs.cypress.io/) |
0 commit comments