@kubb/plugin-cypress 5.0.0-beta.15 → 5.0.0-beta.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-cypress",
3
- "version": "5.0.0-beta.15",
3
+ "version": "5.0.0-beta.25",
4
4
  "description": "Generate Cypress request commands and e2e test fixtures from your OpenAPI specification, enabling automated API testing with zero manual setup.",
5
5
  "keywords": [
6
6
  "code-generation",
@@ -47,16 +47,16 @@
47
47
  "registry": "https://registry.npmjs.org/"
48
48
  },
49
49
  "dependencies": {
50
- "@kubb/core": "5.0.0-beta.19",
51
- "@kubb/renderer-jsx": "5.0.0-beta.19",
52
- "@kubb/plugin-ts": "5.0.0-beta.15"
50
+ "@kubb/core": "5.0.0-beta.25",
51
+ "@kubb/renderer-jsx": "5.0.0-beta.25",
52
+ "@kubb/plugin-ts": "5.0.0-beta.25"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@internals/shared": "0.0.0",
56
56
  "@internals/utils": "0.0.0"
57
57
  },
58
58
  "peerDependencies": {
59
- "@kubb/renderer-jsx": "5.0.0-beta.19"
59
+ "@kubb/renderer-jsx": "5.0.0-beta.25"
60
60
  },
61
61
  "size-limit": [
62
62
  {
@@ -20,7 +20,7 @@ type Props = {
20
20
  * TypeScript resolver for resolving param/data/response type names
21
21
  */
22
22
  resolver: ResolverTs
23
- baseURL: string | undefined
23
+ baseURL: string | null | undefined
24
24
  dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']
25
25
  paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']
26
26
  paramsType: PluginCypress['resolvedOptions']['paramsType']
@@ -60,7 +60,7 @@ export function Request({ baseURL = '', name, dataReturnType, resolver, node, pa
60
60
  replacer: (param) => pathParamNameMap.get(camelCase(param)) ?? param,
61
61
  })
62
62
 
63
- const requestOptions: string[] = [`method: '${node.method}'`, `url: ${urlTemplate}`]
63
+ const requestOptions: Array<string> = [`method: '${node.method}'`, `url: ${urlTemplate}`]
64
64
 
65
65
  const queryParams = getOperationParameters(node).query
66
66
  if (queryParams.length > 0) {
@@ -5,11 +5,16 @@ import { File, jsxRendererSync } from '@kubb/renderer-jsx'
5
5
  import { Request } from '../components/Request.tsx'
6
6
  import type { PluginCypress } from '../types.ts'
7
7
 
8
+ /**
9
+ * Built-in generator for `@kubb/plugin-cypress`. Emits one typed
10
+ * `cy.request()` wrapper per OpenAPI operation, ready to call inside Cypress
11
+ * test specs and custom commands.
12
+ */
8
13
  export const cypressGenerator = defineGenerator<PluginCypress>({
9
14
  name: 'cypress',
10
15
  renderer: jsxRendererSync,
11
16
  operation(node, ctx) {
12
- const { config, resolver, driver, root, inputNode } = ctx
17
+ const { config, resolver, driver, root } = ctx
13
18
  const { output, baseURL, dataReturnType, paramsCasing, paramsType, pathParamsType, group } = ctx.options
14
19
 
15
20
  const pluginTs = driver.getPlugin(pluginTsName)
@@ -24,13 +29,16 @@ export const cypressGenerator = defineGenerator<PluginCypress>({
24
29
 
25
30
  const meta = {
26
31
  name: resolver.resolveName(node.operationId),
27
- file: resolver.resolveFile({ name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path }, { root, output, group }),
32
+ file: resolver.resolveFile(
33
+ { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
34
+ { root, output, group: group ?? undefined },
35
+ ),
28
36
  fileTs: tsResolver.resolveFile(
29
37
  { name: node.operationId, extname: '.ts', tag: node.tags[0] ?? 'default', path: node.path },
30
38
  {
31
39
  root,
32
40
  output: pluginTs.options?.output ?? output,
33
- group: pluginTs.options?.group,
41
+ group: pluginTs.options?.group ?? undefined,
34
42
  },
35
43
  ),
36
44
  } as const
@@ -40,8 +48,8 @@ export const cypressGenerator = defineGenerator<PluginCypress>({
40
48
  baseName={meta.file.baseName}
41
49
  path={meta.file.path}
42
50
  meta={meta.file.meta}
43
- banner={resolver.resolveBanner(inputNode, { output, config })}
44
- footer={resolver.resolveFooter(inputNode, { output, config })}
51
+ banner={resolver.resolveBanner(ctx.meta, { output, config })}
52
+ footer={resolver.resolveFooter(ctx.meta, { output, config })}
45
53
  >
46
54
  {meta.fileTs && importedTypeNames.length > 0 && <File.Import name={importedTypeNames} root={meta.file.path} path={meta.fileTs.path} isTypeOnly />}
47
55
  <Request
package/src/plugin.ts CHANGED
@@ -6,24 +6,31 @@ import { resolverCypress } from './resolvers/resolverCypress.ts'
6
6
  import type { PluginCypress } from './types.ts'
7
7
 
8
8
  /**
9
- * Canonical plugin name for `@kubb/plugin-cypress`, used to identify the plugin
10
- * in driver lookups and warnings.
9
+ * Canonical plugin name for `@kubb/plugin-cypress`. Used for driver lookups and
10
+ * cross-plugin dependency references.
11
11
  */
12
12
  export const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']
13
13
 
14
14
  /**
15
- * The `@kubb/plugin-cypress` plugin factory.
16
- *
17
- * Generates Cypress `cy.request()` test functions from an OpenAPI/AST `RootNode`.
18
- * Walks operations, delegates rendering to the active generators,
19
- * and writes barrel files based on `output.barrelType`.
15
+ * Generates one typed `cy.request()` wrapper per OpenAPI operation. Each helper
16
+ * has typed path params, body, query, and a typed response, so failing API
17
+ * calls in Cypress show up at compile time instead of inside the test runner.
20
18
  *
21
19
  * @example
22
20
  * ```ts
23
- * import pluginCypress from '@kubb/plugin-cypress'
21
+ * import { defineConfig } from 'kubb'
22
+ * import { pluginTs } from '@kubb/plugin-ts'
23
+ * import { pluginCypress } from '@kubb/plugin-cypress'
24
24
  *
25
25
  * export default defineConfig({
26
- * plugins: [pluginCypress({ output: { path: 'cypress' } })],
26
+ * input: { path: './petStore.yaml' },
27
+ * output: { path: './src/gen' },
28
+ * plugins: [
29
+ * pluginTs(),
30
+ * pluginCypress({
31
+ * output: { path: './cypress' },
32
+ * }),
33
+ * ],
27
34
  * })
28
35
  * ```
29
36
  */
@@ -56,7 +63,7 @@ export const pluginCypress = definePlugin<PluginCypress>((options) => {
56
63
  return `${camelCase(ctx.group)}Requests`
57
64
  },
58
65
  } satisfies Group)
59
- : undefined
66
+ : null
60
67
 
61
68
  return {
62
69
  name: pluginCypressName,
@@ -3,12 +3,16 @@ import { defineResolver } from '@kubb/core'
3
3
  import type { PluginCypress } from '../types.ts'
4
4
 
5
5
  /**
6
- * Naming convention resolver for Cypress plugin.
6
+ * Default resolver used by `@kubb/plugin-cypress`. Decides the names and file
7
+ * paths for every generated `cy.request()` wrapper. Functions and files use
8
+ * camelCase, matching the convention from `@kubb/plugin-client`.
7
9
  *
8
- * Provides default naming helpers using camelCase for functions and file paths.
10
+ * @example Resolve a helper name
11
+ * ```ts
12
+ * import { resolverCypress } from '@kubb/plugin-cypress'
9
13
  *
10
- * @example
11
- * `resolverCypress.default('list pets', 'function') // → 'listPets'`
14
+ * resolverCypress.default('list pets', 'function') // 'listPets'
15
+ * ```
12
16
  */
13
17
  export const resolverCypress = defineResolver<PluginCypress>(() => ({
14
18
  name: 'default',
package/src/types.ts CHANGED
@@ -23,21 +23,23 @@ export type ResolverCypress = Resolver & {
23
23
  type ParamsTypeOptions =
24
24
  | {
25
25
  /**
26
- * All parameters merged into a single destructured object.
26
+ * Every operation parameter is wrapped in a single destructured object argument.
27
27
  */
28
28
  paramsType: 'object'
29
29
  /**
30
- * Not applicable when all parameters are merged into a single object.
30
+ * `pathParamsType` has no effect when `paramsType` is `'object'`.
31
31
  */
32
32
  pathParamsType?: never
33
33
  }
34
34
  | {
35
35
  /**
36
- * Each parameter group emitted as a separate function argument.
36
+ * Each parameter group is emitted as a separate positional function argument.
37
37
  */
38
38
  paramsType?: 'inline'
39
39
  /**
40
- * How path parameters are arranged: grouped in an object or spread inline.
40
+ * How URL path parameters are arranged inside the inline argument list.
41
+ * - `'object'` groups them into one destructured object.
42
+ * - `'inline'` emits each path param as its own argument.
41
43
  *
42
44
  * @default 'inline'
43
45
  */
@@ -46,50 +48,56 @@ type ParamsTypeOptions =
46
48
 
47
49
  export type Options = {
48
50
  /**
49
- * Specify the export location for the files and define the behavior of the output.
50
- * @default { path: 'cypress', barrelType: 'named' }
51
+ * Where the generated Cypress helpers are written and how they are exported.
52
+ *
53
+ * @default { path: 'cypress', barrel: { type: 'named' } }
51
54
  */
52
55
  output?: Output
53
56
  /**
54
- * Return type when calling cy.request: response data only or full response.
57
+ * Shape of the value returned from each helper.
58
+ * - `'data'` — only the response body.
59
+ * - `'full'` — the full Cypress response object (headers, status, body).
55
60
  *
56
61
  * @default 'data'
57
62
  */
58
63
  dataReturnType?: 'data' | 'full'
59
64
  /**
60
- * Apply casing to parameter names.
65
+ * Rename parameter properties in the generated helpers (path, query, headers).
66
+ *
67
+ * @note Must match the value of `paramsCasing` on `@kubb/plugin-ts`.
61
68
  */
62
69
  paramsCasing?: 'camelcase'
63
70
  /**
64
- * Base URL prepended to every generated request URL.
71
+ * Base URL prepended to every request URL. When omitted, falls back to the
72
+ * adapter's server URL (typically `servers[0].url`).
65
73
  */
66
74
  baseURL?: string
67
75
  /**
68
- * Group the Cypress requests based on the provided name.
76
+ * Split generated files into subfolders based on the operation's tag.
69
77
  */
70
78
  group?: Group
71
79
  /**
72
- * Tags, operations, or paths to exclude from generation.
80
+ * Skip operations matching at least one entry in the list.
73
81
  */
74
82
  exclude?: Array<Exclude>
75
83
  /**
76
- * Tags, operations, or paths to include in generation.
84
+ * Restrict generation to operations matching at least one entry in the list.
77
85
  */
78
86
  include?: Array<Include>
79
87
  /**
80
- * Override options for specific tags, operations, or paths.
88
+ * Apply a different options object to operations matching a pattern.
81
89
  */
82
90
  override?: Array<Override<ResolvedOptions>>
83
91
  /**
84
- * Override naming conventions for function names and types.
92
+ * Override how helper names and file paths are built.
85
93
  */
86
94
  resolver?: Partial<ResolverCypress> & ThisType<ResolverCypress>
87
95
  /**
88
- * AST visitor to transform generated nodes.
96
+ * AST visitor applied to each operation node before printing.
89
97
  */
90
98
  transformer?: ast.Visitor
91
99
  /**
92
- * Additional generators alongside the default generators.
100
+ * Custom generators that run alongside the built-in Cypress generators.
93
101
  */
94
102
  generators?: Array<Generator<PluginCypress>>
95
103
  } & ParamsTypeOptions
@@ -99,7 +107,7 @@ type ResolvedOptions = {
99
107
  exclude: Array<Exclude>
100
108
  include: Array<Include> | undefined
101
109
  override: Array<Override<ResolvedOptions>>
102
- group: Group | undefined
110
+ group: Group | null
103
111
  baseURL: Options['baseURL'] | undefined
104
112
  dataReturnType: NonNullable<Options['dataReturnType']>
105
113
  pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>