@kubb/plugin-cypress 5.0.0-alpha.9 → 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/LICENSE +17 -10
- package/README.md +38 -23
- package/dist/index.cjs +401 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +130 -6
- package/dist/index.js +394 -63
- package/dist/index.js.map +1 -1
- package/package.json +38 -77
- package/dist/components-BK_6GU4v.js +0 -257
- package/dist/components-BK_6GU4v.js.map +0 -1
- package/dist/components-Drg_gLu2.cjs +0 -305
- package/dist/components-Drg_gLu2.cjs.map +0 -1
- package/dist/components.cjs +0 -3
- package/dist/components.d.ts +0 -50
- package/dist/components.js +0 -2
- package/dist/generators-B3FWG2Ck.js +0 -71
- package/dist/generators-B3FWG2Ck.js.map +0 -1
- package/dist/generators-C73nd-xB.cjs +0 -75
- package/dist/generators-C73nd-xB.cjs.map +0 -1
- package/dist/generators.cjs +0 -3
- package/dist/generators.d.ts +0 -505
- package/dist/generators.js +0 -2
- package/dist/types-DGvL0jsn.d.ts +0 -85
- package/src/components/Request.tsx +0 -147
- package/src/components/index.ts +0 -1
- package/src/generators/cypressGenerator.tsx +0 -66
- package/src/generators/index.ts +0 -1
- package/src/index.ts +0 -2
- package/src/plugin.ts +0 -119
- package/src/types.ts +0 -83
- /package/dist/{chunk--u3MIqq1.js → rolldown-runtime-C0LytTxp.js} +0 -0
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
import { URLPath } from '@internals/utils'
|
|
2
|
-
import { type HttpMethod, isAllOptional, isOptional } from '@kubb/oas'
|
|
3
|
-
import type { OperationSchemas } from '@kubb/plugin-oas'
|
|
4
|
-
import { getPathParams } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { File, Function, FunctionParams } from '@kubb/react-fabric'
|
|
6
|
-
import type { FabricReactNode } from '@kubb/react-fabric/types'
|
|
7
|
-
import type { PluginCypress } from '../types.ts'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
/**
|
|
11
|
-
* Name of the function
|
|
12
|
-
*/
|
|
13
|
-
name: string
|
|
14
|
-
typeSchemas: OperationSchemas
|
|
15
|
-
url: string
|
|
16
|
-
baseURL: string | undefined
|
|
17
|
-
dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']
|
|
18
|
-
paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']
|
|
19
|
-
paramsType: PluginCypress['resolvedOptions']['paramsType']
|
|
20
|
-
pathParamsType: PluginCypress['resolvedOptions']['pathParamsType']
|
|
21
|
-
method: HttpMethod
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
type GetParamsProps = {
|
|
25
|
-
paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']
|
|
26
|
-
paramsType: PluginCypress['resolvedOptions']['paramsType']
|
|
27
|
-
pathParamsType: PluginCypress['resolvedOptions']['pathParamsType']
|
|
28
|
-
typeSchemas: OperationSchemas
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
32
|
-
if (paramsType === 'object') {
|
|
33
|
-
const pathParams = getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing })
|
|
34
|
-
|
|
35
|
-
return FunctionParams.factory({
|
|
36
|
-
data: {
|
|
37
|
-
mode: 'object',
|
|
38
|
-
children: {
|
|
39
|
-
...pathParams,
|
|
40
|
-
data: typeSchemas.request?.name
|
|
41
|
-
? {
|
|
42
|
-
type: typeSchemas.request?.name,
|
|
43
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
44
|
-
}
|
|
45
|
-
: undefined,
|
|
46
|
-
params: typeSchemas.queryParams?.name
|
|
47
|
-
? {
|
|
48
|
-
type: typeSchemas.queryParams?.name,
|
|
49
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
50
|
-
}
|
|
51
|
-
: undefined,
|
|
52
|
-
headers: typeSchemas.headerParams?.name
|
|
53
|
-
? {
|
|
54
|
-
type: typeSchemas.headerParams?.name,
|
|
55
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
56
|
-
}
|
|
57
|
-
: undefined,
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
options: {
|
|
61
|
-
type: 'Partial<Cypress.RequestOptions>',
|
|
62
|
-
default: '{}',
|
|
63
|
-
},
|
|
64
|
-
})
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return FunctionParams.factory({
|
|
68
|
-
pathParams: typeSchemas.pathParams?.name
|
|
69
|
-
? {
|
|
70
|
-
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
71
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
72
|
-
default: isAllOptional(typeSchemas.pathParams?.schema) ? '{}' : undefined,
|
|
73
|
-
}
|
|
74
|
-
: undefined,
|
|
75
|
-
data: typeSchemas.request?.name
|
|
76
|
-
? {
|
|
77
|
-
type: typeSchemas.request?.name,
|
|
78
|
-
optional: isOptional(typeSchemas.request?.schema),
|
|
79
|
-
}
|
|
80
|
-
: undefined,
|
|
81
|
-
params: typeSchemas.queryParams?.name
|
|
82
|
-
? {
|
|
83
|
-
type: typeSchemas.queryParams?.name,
|
|
84
|
-
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
85
|
-
}
|
|
86
|
-
: undefined,
|
|
87
|
-
headers: typeSchemas.headerParams?.name
|
|
88
|
-
? {
|
|
89
|
-
type: typeSchemas.headerParams?.name,
|
|
90
|
-
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
91
|
-
}
|
|
92
|
-
: undefined,
|
|
93
|
-
options: {
|
|
94
|
-
type: 'Partial<Cypress.RequestOptions>',
|
|
95
|
-
default: '{}',
|
|
96
|
-
},
|
|
97
|
-
})
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
export function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }: Props): FabricReactNode {
|
|
101
|
-
const path = new URLPath(url, { casing: paramsCasing })
|
|
102
|
-
|
|
103
|
-
const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
104
|
-
|
|
105
|
-
const returnType =
|
|
106
|
-
dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`
|
|
107
|
-
|
|
108
|
-
// Build the URL template string - this will convert /pets/:petId to /pets/${petId}
|
|
109
|
-
const urlTemplate = path.toTemplateString({ prefix: baseURL })
|
|
110
|
-
|
|
111
|
-
// Build request options object
|
|
112
|
-
const requestOptions: string[] = [`method: '${method}'`, `url: ${urlTemplate}`]
|
|
113
|
-
|
|
114
|
-
// Add query params if they exist
|
|
115
|
-
if (typeSchemas.queryParams?.name) {
|
|
116
|
-
requestOptions.push('qs: params')
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Add headers if they exist
|
|
120
|
-
if (typeSchemas.headerParams?.name) {
|
|
121
|
-
requestOptions.push('headers')
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Add body if request schema exists
|
|
125
|
-
if (typeSchemas.request?.name) {
|
|
126
|
-
requestOptions.push('body: data')
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Spread additional Cypress options
|
|
130
|
-
requestOptions.push('...options')
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<File.Source name={name} isIndexable isExportable>
|
|
134
|
-
<Function name={name} export params={params.toConstructor()} returnType={returnType}>
|
|
135
|
-
{dataReturnType === 'data'
|
|
136
|
-
? `return cy.request<${typeSchemas.response.name}>({
|
|
137
|
-
${requestOptions.join(',\n ')}
|
|
138
|
-
}).then((res) => res.body)`
|
|
139
|
-
: `return cy.request<${typeSchemas.response.name}>({
|
|
140
|
-
${requestOptions.join(',\n ')}
|
|
141
|
-
})`}
|
|
142
|
-
</Function>
|
|
143
|
-
</File.Source>
|
|
144
|
-
)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
Request.getParams = getParams
|
package/src/components/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { Request } from './Request.tsx'
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { usePluginDriver } from '@kubb/core/hooks'
|
|
2
|
-
import { createReactGenerator } from '@kubb/plugin-oas/generators'
|
|
3
|
-
import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
|
|
4
|
-
import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
|
|
5
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
|
-
import { File } from '@kubb/react-fabric'
|
|
7
|
-
import { Request } from '../components'
|
|
8
|
-
import type { PluginCypress } from '../types'
|
|
9
|
-
|
|
10
|
-
export const cypressGenerator = createReactGenerator<PluginCypress>({
|
|
11
|
-
name: 'cypress',
|
|
12
|
-
Operation({ operation, generator, plugin }) {
|
|
13
|
-
const {
|
|
14
|
-
options: { output, baseURL, dataReturnType, paramsCasing, paramsType, pathParamsType },
|
|
15
|
-
} = plugin
|
|
16
|
-
const driver = usePluginDriver()
|
|
17
|
-
|
|
18
|
-
const oas = useOas()
|
|
19
|
-
const { getSchemas, getName, getFile } = useOperationManager(generator)
|
|
20
|
-
|
|
21
|
-
const request = {
|
|
22
|
-
name: getName(operation, { type: 'function' }),
|
|
23
|
-
file: getFile(operation),
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const type = {
|
|
27
|
-
file: getFile(operation, { pluginName: pluginTsName }),
|
|
28
|
-
schemas: getSchemas(operation, { pluginName: pluginTsName, type: 'type' }),
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return (
|
|
32
|
-
<File
|
|
33
|
-
baseName={request.file.baseName}
|
|
34
|
-
path={request.file.path}
|
|
35
|
-
meta={request.file.meta}
|
|
36
|
-
banner={getBanner({ oas, output, config: driver.config })}
|
|
37
|
-
footer={getFooter({ oas, output })}
|
|
38
|
-
>
|
|
39
|
-
<File.Import
|
|
40
|
-
name={[
|
|
41
|
-
type.schemas.request?.name,
|
|
42
|
-
type.schemas.response.name,
|
|
43
|
-
type.schemas.pathParams?.name,
|
|
44
|
-
type.schemas.queryParams?.name,
|
|
45
|
-
type.schemas.headerParams?.name,
|
|
46
|
-
...(type.schemas.statusCodes?.map((item) => item.name) || []),
|
|
47
|
-
].filter(Boolean)}
|
|
48
|
-
root={request.file.path}
|
|
49
|
-
path={type.file.path}
|
|
50
|
-
isTypeOnly
|
|
51
|
-
/>
|
|
52
|
-
<Request
|
|
53
|
-
name={request.name}
|
|
54
|
-
dataReturnType={dataReturnType}
|
|
55
|
-
paramsCasing={paramsCasing}
|
|
56
|
-
paramsType={paramsType}
|
|
57
|
-
pathParamsType={pathParamsType}
|
|
58
|
-
typeSchemas={type.schemas}
|
|
59
|
-
method={operation.method}
|
|
60
|
-
baseURL={baseURL}
|
|
61
|
-
url={operation.path}
|
|
62
|
-
/>
|
|
63
|
-
</File>
|
|
64
|
-
)
|
|
65
|
-
},
|
|
66
|
-
})
|
package/src/generators/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { cypressGenerator } from './cypressGenerator.tsx'
|
package/src/index.ts
DELETED
package/src/plugin.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import path from 'node:path'
|
|
2
|
-
import { camelCase } from '@internals/utils'
|
|
3
|
-
import { createPlugin, type Group, getBarrelFiles, getMode } from '@kubb/core'
|
|
4
|
-
import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
|
|
5
|
-
import { pluginTsName } from '@kubb/plugin-ts'
|
|
6
|
-
import { cypressGenerator } from './generators'
|
|
7
|
-
import type { PluginCypress } from './types.ts'
|
|
8
|
-
|
|
9
|
-
export const pluginCypressName = 'plugin-cypress' satisfies PluginCypress['name']
|
|
10
|
-
|
|
11
|
-
export const pluginCypress = createPlugin<PluginCypress>((options) => {
|
|
12
|
-
const {
|
|
13
|
-
output = { path: 'cypress', barrelType: 'named' },
|
|
14
|
-
group,
|
|
15
|
-
dataReturnType = 'data',
|
|
16
|
-
exclude = [],
|
|
17
|
-
include,
|
|
18
|
-
override = [],
|
|
19
|
-
transformers = {},
|
|
20
|
-
generators = [cypressGenerator].filter(Boolean),
|
|
21
|
-
contentType,
|
|
22
|
-
baseURL,
|
|
23
|
-
paramsCasing,
|
|
24
|
-
paramsType = 'inline',
|
|
25
|
-
pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
|
|
26
|
-
} = options
|
|
27
|
-
|
|
28
|
-
return {
|
|
29
|
-
name: pluginCypressName,
|
|
30
|
-
options: {
|
|
31
|
-
output,
|
|
32
|
-
dataReturnType,
|
|
33
|
-
group,
|
|
34
|
-
baseURL,
|
|
35
|
-
|
|
36
|
-
paramsCasing,
|
|
37
|
-
paramsType,
|
|
38
|
-
pathParamsType,
|
|
39
|
-
},
|
|
40
|
-
pre: [pluginOasName, pluginTsName].filter(Boolean),
|
|
41
|
-
resolvePath(baseName, pathMode, options) {
|
|
42
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
43
|
-
const mode = pathMode ?? getMode(path.resolve(root, output.path))
|
|
44
|
-
|
|
45
|
-
if (mode === 'single') {
|
|
46
|
-
/**
|
|
47
|
-
* when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
|
|
48
|
-
* Other plugins then need to call addOrAppend instead of just add from the fileManager class
|
|
49
|
-
*/
|
|
50
|
-
return path.resolve(root, output.path)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (group && (options?.group?.path || options?.group?.tag)) {
|
|
54
|
-
const groupName: Group['name'] = group?.name
|
|
55
|
-
? group.name
|
|
56
|
-
: (ctx) => {
|
|
57
|
-
if (group?.type === 'path') {
|
|
58
|
-
return `${ctx.group.split('/')[1]}`
|
|
59
|
-
}
|
|
60
|
-
return `${camelCase(ctx.group)}Requests`
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return path.resolve(
|
|
64
|
-
root,
|
|
65
|
-
output.path,
|
|
66
|
-
groupName({
|
|
67
|
-
group: group.type === 'path' ? options.group.path! : options.group.tag!,
|
|
68
|
-
}),
|
|
69
|
-
baseName,
|
|
70
|
-
)
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
return path.resolve(root, output.path, baseName)
|
|
74
|
-
},
|
|
75
|
-
resolveName(name, type) {
|
|
76
|
-
const resolvedName = camelCase(name, {
|
|
77
|
-
isFile: type === 'file',
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
if (type) {
|
|
81
|
-
return transformers?.name?.(resolvedName, type) || resolvedName
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return resolvedName
|
|
85
|
-
},
|
|
86
|
-
async install() {
|
|
87
|
-
const root = path.resolve(this.config.root, this.config.output.path)
|
|
88
|
-
const mode = getMode(path.resolve(root, output.path))
|
|
89
|
-
const oas = await this.getOas()
|
|
90
|
-
|
|
91
|
-
const operationGenerator = new OperationGenerator(this.plugin.options, {
|
|
92
|
-
fabric: this.fabric,
|
|
93
|
-
oas,
|
|
94
|
-
driver: this.driver,
|
|
95
|
-
events: this.events,
|
|
96
|
-
plugin: this.plugin,
|
|
97
|
-
contentType,
|
|
98
|
-
exclude,
|
|
99
|
-
include,
|
|
100
|
-
override,
|
|
101
|
-
mode,
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
const files = await operationGenerator.build(...generators)
|
|
105
|
-
await this.upsertFile(...files)
|
|
106
|
-
|
|
107
|
-
const barrelFiles = await getBarrelFiles(this.fabric.files, {
|
|
108
|
-
type: output.barrelType ?? 'named',
|
|
109
|
-
root,
|
|
110
|
-
output,
|
|
111
|
-
meta: {
|
|
112
|
-
pluginName: this.plugin.name,
|
|
113
|
-
},
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
await this.upsertFile(...barrelFiles)
|
|
117
|
-
},
|
|
118
|
-
}
|
|
119
|
-
})
|
package/src/types.ts
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import type { Group, Output, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
|
|
2
|
-
|
|
3
|
-
import type { contentType, Oas } from '@kubb/oas'
|
|
4
|
-
import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
|
|
5
|
-
import type { Generator } from '@kubb/plugin-oas/generators'
|
|
6
|
-
|
|
7
|
-
export type Options = {
|
|
8
|
-
/**
|
|
9
|
-
* Specify the export location for the files and define the behavior of the output
|
|
10
|
-
* @default { path: 'cypress', barrelType: 'named' }
|
|
11
|
-
*/
|
|
12
|
-
output?: Output<Oas>
|
|
13
|
-
/**
|
|
14
|
-
* Define which contentType should be used.
|
|
15
|
-
* By default, the first JSON valid mediaType is used
|
|
16
|
-
*/
|
|
17
|
-
contentType?: contentType
|
|
18
|
-
/**
|
|
19
|
-
* Return type when calling cy.request.
|
|
20
|
-
* - 'data' returns ResponseConfig[data].
|
|
21
|
-
* - 'full' returns ResponseConfig.
|
|
22
|
-
* @default 'data'
|
|
23
|
-
*/
|
|
24
|
-
dataReturnType?: 'data' | 'full'
|
|
25
|
-
/**
|
|
26
|
-
* How to style your params, by default no casing is applied
|
|
27
|
-
* - 'camelcase' uses camelcase for the params names
|
|
28
|
-
*/
|
|
29
|
-
paramsCasing?: 'camelcase'
|
|
30
|
-
/**
|
|
31
|
-
* How to pass your params.
|
|
32
|
-
* - 'object' returns the params and pathParams as an object.
|
|
33
|
-
* - 'inline' returns the params as comma separated params.
|
|
34
|
-
* @default 'inline'
|
|
35
|
-
*/
|
|
36
|
-
paramsType?: 'object' | 'inline'
|
|
37
|
-
/**
|
|
38
|
-
* How to pass your pathParams.
|
|
39
|
-
* - 'object' returns the pathParams as an object.
|
|
40
|
-
* - 'inline' returns the pathParams as comma separated params.
|
|
41
|
-
* @default 'inline'
|
|
42
|
-
*/
|
|
43
|
-
pathParamsType?: 'object' | 'inline'
|
|
44
|
-
baseURL?: string
|
|
45
|
-
/**
|
|
46
|
-
* Group the Cypress requests based on the provided name.
|
|
47
|
-
*/
|
|
48
|
-
group?: Group
|
|
49
|
-
/**
|
|
50
|
-
* Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
|
|
51
|
-
*/
|
|
52
|
-
exclude?: Array<Exclude>
|
|
53
|
-
/**
|
|
54
|
-
* Array containing include parameters to include tags/operations/methods/paths.
|
|
55
|
-
*/
|
|
56
|
-
include?: Array<Include>
|
|
57
|
-
/**
|
|
58
|
-
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
59
|
-
*/
|
|
60
|
-
override?: Array<Override<ResolvedOptions>>
|
|
61
|
-
transformers?: {
|
|
62
|
-
/**
|
|
63
|
-
* Customize the names based on the type that is provided by the plugin.
|
|
64
|
-
*/
|
|
65
|
-
name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Define some generators next to the Cypress generators.
|
|
69
|
-
*/
|
|
70
|
-
generators?: Array<Generator<PluginCypress>>
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
type ResolvedOptions = {
|
|
74
|
-
output: Output<Oas>
|
|
75
|
-
group: Options['group']
|
|
76
|
-
baseURL: Options['baseURL'] | undefined
|
|
77
|
-
dataReturnType: NonNullable<Options['dataReturnType']>
|
|
78
|
-
pathParamsType: NonNullable<Options['pathParamsType']>
|
|
79
|
-
paramsType: NonNullable<Options['paramsType']>
|
|
80
|
-
paramsCasing: Options['paramsCasing']
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>
|
|
File without changes
|