@kubb/plugin-cypress 5.0.0-beta.10 → 5.0.0-beta.100

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/src/plugin.ts DELETED
@@ -1,95 +0,0 @@
1
- import { camelCase } from '@internals/utils'
2
- import { definePlugin, type Group } from '@kubb/core'
3
- import { pluginTsName } from '@kubb/plugin-ts'
4
- import { cypressGenerator } from './generators/cypressGenerator.tsx'
5
- import { resolverCypress } from './resolvers/resolverCypress.ts'
6
- import type { PluginCypress } from './types.ts'
7
-
8
- /**
9
- * Canonical plugin name for `@kubb/plugin-cypress`, used to identify the plugin
10
- * in driver lookups and warnings.
11
- */
12
- export const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']
13
-
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`.
20
- *
21
- * @example
22
- * ```ts
23
- * import pluginCypress from '@kubb/plugin-cypress'
24
- *
25
- * export default defineConfig({
26
- * plugins: [pluginCypress({ output: { path: 'cypress' } })],
27
- * })
28
- * ```
29
- */
30
- export const pluginCypress = definePlugin<PluginCypress>((options) => {
31
- const {
32
- output = { path: 'cypress', barrelType: 'named' },
33
- group,
34
- exclude = [],
35
- include,
36
- override = [],
37
- dataReturnType = 'data',
38
- baseURL,
39
- paramsCasing,
40
- paramsType = 'inline',
41
- pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
42
- resolver: userResolver,
43
- transformer: userTransformer,
44
- generators: userGenerators = [],
45
- } = options
46
-
47
- const groupConfig = group
48
- ? ({
49
- ...group,
50
- name: group.name
51
- ? group.name
52
- : (ctx: { group: string }) => {
53
- if (group.type === 'path') {
54
- return `${ctx.group.split('/')[1]}`
55
- }
56
- return `${camelCase(ctx.group)}Requests`
57
- },
58
- } satisfies Group)
59
- : undefined
60
-
61
- return {
62
- name: pluginCypressName,
63
- options,
64
- dependencies: [pluginTsName],
65
- hooks: {
66
- 'kubb:plugin:setup'(ctx) {
67
- const resolver = userResolver ? { ...resolverCypress, ...userResolver } : resolverCypress
68
-
69
- ctx.setOptions({
70
- output,
71
- exclude,
72
- include,
73
- override,
74
- dataReturnType,
75
- group: groupConfig,
76
- baseURL,
77
- paramsCasing,
78
- paramsType,
79
- pathParamsType,
80
- resolver,
81
- })
82
- ctx.setResolver(resolver)
83
- if (userTransformer) {
84
- ctx.setTransformer(userTransformer)
85
- }
86
- ctx.addGenerator(cypressGenerator)
87
- for (const gen of userGenerators) {
88
- ctx.addGenerator(gen)
89
- }
90
- },
91
- },
92
- }
93
- })
94
-
95
- export default pluginCypress
@@ -1,25 +0,0 @@
1
- import { camelCase } from '@internals/utils'
2
- import { defineResolver } from '@kubb/core'
3
- import type { PluginCypress } from '../types.ts'
4
-
5
- /**
6
- * Naming convention resolver for Cypress plugin.
7
- *
8
- * Provides default naming helpers using camelCase for functions and file paths.
9
- *
10
- * @example
11
- * `resolverCypress.default('list pets', 'function') // → 'listPets'`
12
- */
13
- export const resolverCypress = defineResolver<PluginCypress>(() => ({
14
- name: 'default',
15
- pluginName: 'plugin-cypress',
16
- default(name, type) {
17
- return camelCase(name, { isFile: type === 'file' })
18
- },
19
- resolveName(name) {
20
- return this.default(name, 'function')
21
- },
22
- resolvePathName(name, type) {
23
- return this.default(name, type)
24
- },
25
- }))
package/src/types.ts DELETED
@@ -1,119 +0,0 @@
1
- import type { ast, Exclude, Generator, Group, Include, Output, Override, PluginFactoryOptions, Resolver } from '@kubb/core'
2
-
3
- /**
4
- * Resolver for Cypress that provides naming methods for test functions.
5
- */
6
- export type ResolverCypress = Resolver & {
7
- /**
8
- * Resolves the function name for an operation.
9
- *
10
- * @example Resolving function names
11
- * `resolver.resolveName('show pet by id') // -> 'showPetById'`
12
- */
13
- resolveName(this: ResolverCypress, name: string): string
14
- /**
15
- * Resolves the output file name for a Cypress request module.
16
- */
17
- resolvePathName(this: ResolverCypress, name: string, type?: 'file' | 'function' | 'type' | 'const'): string
18
- }
19
-
20
- /**
21
- * Parameter handling mode that determines how path params and query/body params are arranged in function signatures.
22
- */
23
- type ParamsTypeOptions =
24
- | {
25
- /**
26
- * All parameters merged into a single destructured object.
27
- */
28
- paramsType: 'object'
29
- /**
30
- * Not applicable when all parameters are merged into a single object.
31
- */
32
- pathParamsType?: never
33
- }
34
- | {
35
- /**
36
- * Each parameter group emitted as a separate function argument.
37
- */
38
- paramsType?: 'inline'
39
- /**
40
- * How path parameters are arranged: grouped in an object or spread inline.
41
- *
42
- * @default 'inline'
43
- */
44
- pathParamsType?: 'object' | 'inline'
45
- }
46
-
47
- export type Options = {
48
- /**
49
- * Specify the export location for the files and define the behavior of the output.
50
- * @default { path: 'cypress', barrelType: 'named' }
51
- */
52
- output?: Output
53
- /**
54
- * Return type when calling cy.request: response data only or full response.
55
- *
56
- * @default 'data'
57
- */
58
- dataReturnType?: 'data' | 'full'
59
- /**
60
- * Apply casing to parameter names.
61
- */
62
- paramsCasing?: 'camelcase'
63
- /**
64
- * Base URL prepended to every generated request URL.
65
- */
66
- baseURL?: string
67
- /**
68
- * Group the Cypress requests based on the provided name.
69
- */
70
- group?: Group
71
- /**
72
- * Tags, operations, or paths to exclude from generation.
73
- */
74
- exclude?: Array<Exclude>
75
- /**
76
- * Tags, operations, or paths to include in generation.
77
- */
78
- include?: Array<Include>
79
- /**
80
- * Override options for specific tags, operations, or paths.
81
- */
82
- override?: Array<Override<ResolvedOptions>>
83
- /**
84
- * Override naming conventions for function names and types.
85
- */
86
- resolver?: Partial<ResolverCypress> & ThisType<ResolverCypress>
87
- /**
88
- * AST visitor to transform generated nodes.
89
- */
90
- transformer?: ast.Visitor
91
- /**
92
- * Additional generators alongside the default generators.
93
- */
94
- generators?: Array<Generator<PluginCypress>>
95
- } & ParamsTypeOptions
96
-
97
- type ResolvedOptions = {
98
- output: Output
99
- exclude: Array<Exclude>
100
- include: Array<Include> | undefined
101
- override: Array<Override<ResolvedOptions>>
102
- group: Group | undefined
103
- baseURL: Options['baseURL'] | undefined
104
- dataReturnType: NonNullable<Options['dataReturnType']>
105
- pathParamsType: NonNullable<NonNullable<Options['pathParamsType']>>
106
- paramsType: NonNullable<Options['paramsType']>
107
- paramsCasing: Options['paramsCasing']
108
- resolver: ResolverCypress
109
- }
110
-
111
- export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, ResolverCypress>
112
-
113
- declare global {
114
- namespace Kubb {
115
- interface PluginRegistry {
116
- 'plugin-cypress': PluginCypress
117
- }
118
- }
119
- }