@kubb/plugin-cypress 4.12.5 → 4.12.7

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.
Files changed (41) hide show
  1. package/dist/components-CKNcdnr_.js +101 -0
  2. package/dist/components-CKNcdnr_.js.map +1 -0
  3. package/dist/components-UBGR5HIj.cjs +107 -0
  4. package/dist/components-UBGR5HIj.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.cts +23 -2
  7. package/dist/components.d.ts +23 -2
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-Nkjg7hcp.cjs → generators-Ct9I-qNg.cjs} +7 -5
  10. package/dist/generators-Ct9I-qNg.cjs.map +1 -0
  11. package/dist/{generators-CnEpcL-m.js → generators-D_AameR6.js} +7 -5
  12. package/dist/generators-D_AameR6.js.map +1 -0
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.d.cts +1 -1
  15. package/dist/generators.d.ts +1 -1
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +6 -3
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.cts +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +6 -3
  22. package/dist/index.js.map +1 -1
  23. package/dist/{types-DjLyok_a.d.cts → types-Bi9SkBrH.d.cts} +34 -4
  24. package/dist/{types-BVMff21d.d.ts → types-Bs7HVpiD.d.ts} +34 -4
  25. package/package.json +6 -6
  26. package/src/components/Request.tsx +104 -12
  27. package/src/generators/__snapshots__/createPet.ts +2 -2
  28. package/src/generators/__snapshots__/deletePet.ts +9 -5
  29. package/src/generators/__snapshots__/getPets.ts +4 -4
  30. package/src/generators/__snapshots__/getPetsWithTemplateString.ts +4 -4
  31. package/src/generators/__snapshots__/showPetById.ts +4 -5
  32. package/src/generators/__snapshots__/updatePet.ts +19 -0
  33. package/src/generators/cypressGenerator.tsx +5 -3
  34. package/src/plugin.ts +7 -0
  35. package/src/types.ts +22 -0
  36. package/dist/components-CNBoaPo0.cjs +0 -48
  37. package/dist/components-CNBoaPo0.cjs.map +0 -1
  38. package/dist/components-GZOhGVCA.js +0 -42
  39. package/dist/components-GZOhGVCA.js.map +0 -1
  40. package/dist/generators-CnEpcL-m.js.map +0 -1
  41. package/dist/generators-Nkjg7hcp.cjs.map +0 -1
@@ -100,7 +100,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
100
100
  * console.log('Starting Kubb generation')
101
101
  * })
102
102
  *
103
- * events.on('plugin:end', (plugin, duration) => {
103
+ * events.on('plugin:end', (plugin, { duration }) => {
104
104
  * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
105
105
  * })
106
106
  * ```
@@ -246,8 +246,13 @@ interface KubbEvents {
246
246
  'plugin:start': [plugin: Plugin];
247
247
  /**
248
248
  * Emitted when a plugin completes execution.
249
+ * Duration in ms
249
250
  */
250
- 'plugin:end': [plugin: Plugin, duration: number];
251
+ 'plugin:end': [plugin: Plugin, meta: {
252
+ duration: number;
253
+ success: boolean;
254
+ error?: Error;
255
+ }];
251
256
  /**
252
257
  * Emitted when plugin hook progress tracking starts.
253
258
  * Contains the hook name and list of plugins to execute.
@@ -706,8 +711,11 @@ type FileMetaBase = {
706
711
  };
707
712
  //#endregion
708
713
  //#region ../plugin-oas/src/types.d.ts
714
+ type GetOasOptions = {
715
+ validate?: boolean;
716
+ };
709
717
  type Context$2 = {
710
- getOas(): Promise<Oas>;
718
+ getOas(options?: GetOasOptions): Promise<Oas>;
711
719
  getBaseURL(): Promise<string | undefined>;
712
720
  };
713
721
  declare global {
@@ -1170,6 +1178,25 @@ type Options = {
1170
1178
  * @default 'data'
1171
1179
  */
1172
1180
  dataReturnType?: 'data' | 'full';
1181
+ /**
1182
+ * How to style your params, by default no casing is applied
1183
+ * - 'camelcase' will use camelcase for the params names
1184
+ */
1185
+ paramsCasing?: 'camelcase';
1186
+ /**
1187
+ * How to pass your params
1188
+ * - 'object' will return the params and pathParams as an object.
1189
+ * - 'inline' will return the params as comma separated params.
1190
+ * @default 'inline'
1191
+ */
1192
+ paramsType?: 'object' | 'inline';
1193
+ /**
1194
+ * How to pass your pathParams.
1195
+ * - 'object' will return the pathParams as an object.
1196
+ * - 'inline' will return the pathParams as comma separated params.
1197
+ * @default 'inline'
1198
+ */
1199
+ pathParamsType?: 'object' | 'inline';
1173
1200
  baseURL?: string;
1174
1201
  /**
1175
1202
  * Group the Cypress requests based on the provided name.
@@ -1203,8 +1230,11 @@ type ResolvedOptions = {
1203
1230
  group: Options['group'];
1204
1231
  baseURL: Options['baseURL'] | undefined;
1205
1232
  dataReturnType: NonNullable<Options['dataReturnType']>;
1233
+ pathParamsType: NonNullable<Options['pathParamsType']>;
1234
+ paramsType: NonNullable<Options['paramsType']>;
1235
+ paramsCasing: Options['paramsCasing'];
1206
1236
  };
1207
1237
  type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>;
1208
1238
  //#endregion
1209
1239
  export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginCypress as n, HttpMethod as o, ReactGenerator as r, Options as t };
1210
- //# sourceMappingURL=types-DjLyok_a.d.cts.map
1240
+ //# sourceMappingURL=types-Bi9SkBrH.d.cts.map
@@ -100,7 +100,7 @@ type ExecutedMeta<H extends PluginLifecycleHooks = PluginLifecycleHooks> = {
100
100
  * console.log('Starting Kubb generation')
101
101
  * })
102
102
  *
103
- * events.on('plugin:end', (plugin, duration) => {
103
+ * events.on('plugin:end', (plugin, { duration }) => {
104
104
  * console.log(`Plugin ${plugin.name} completed in ${duration}ms`)
105
105
  * })
106
106
  * ```
@@ -246,8 +246,13 @@ interface KubbEvents {
246
246
  'plugin:start': [plugin: Plugin];
247
247
  /**
248
248
  * Emitted when a plugin completes execution.
249
+ * Duration in ms
249
250
  */
250
- 'plugin:end': [plugin: Plugin, duration: number];
251
+ 'plugin:end': [plugin: Plugin, meta: {
252
+ duration: number;
253
+ success: boolean;
254
+ error?: Error;
255
+ }];
251
256
  /**
252
257
  * Emitted when plugin hook progress tracking starts.
253
258
  * Contains the hook name and list of plugins to execute.
@@ -706,8 +711,11 @@ type FileMetaBase = {
706
711
  };
707
712
  //#endregion
708
713
  //#region ../plugin-oas/src/types.d.ts
714
+ type GetOasOptions = {
715
+ validate?: boolean;
716
+ };
709
717
  type Context$2 = {
710
- getOas(): Promise<Oas>;
718
+ getOas(options?: GetOasOptions): Promise<Oas>;
711
719
  getBaseURL(): Promise<string | undefined>;
712
720
  };
713
721
  declare global {
@@ -1170,6 +1178,25 @@ type Options = {
1170
1178
  * @default 'data'
1171
1179
  */
1172
1180
  dataReturnType?: 'data' | 'full';
1181
+ /**
1182
+ * How to style your params, by default no casing is applied
1183
+ * - 'camelcase' will use camelcase for the params names
1184
+ */
1185
+ paramsCasing?: 'camelcase';
1186
+ /**
1187
+ * How to pass your params
1188
+ * - 'object' will return the params and pathParams as an object.
1189
+ * - 'inline' will return the params as comma separated params.
1190
+ * @default 'inline'
1191
+ */
1192
+ paramsType?: 'object' | 'inline';
1193
+ /**
1194
+ * How to pass your pathParams.
1195
+ * - 'object' will return the pathParams as an object.
1196
+ * - 'inline' will return the pathParams as comma separated params.
1197
+ * @default 'inline'
1198
+ */
1199
+ pathParamsType?: 'object' | 'inline';
1173
1200
  baseURL?: string;
1174
1201
  /**
1175
1202
  * Group the Cypress requests based on the provided name.
@@ -1203,8 +1230,11 @@ type ResolvedOptions = {
1203
1230
  group: Options['group'];
1204
1231
  baseURL: Options['baseURL'] | undefined;
1205
1232
  dataReturnType: NonNullable<Options['dataReturnType']>;
1233
+ pathParamsType: NonNullable<Options['pathParamsType']>;
1234
+ paramsType: NonNullable<Options['paramsType']>;
1235
+ paramsCasing: Options['paramsCasing'];
1206
1236
  };
1207
1237
  type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>;
1208
1238
  //#endregion
1209
1239
  export { UserPluginWithLifeCycle as a, OperationSchemas as i, PluginCypress as n, HttpMethod as o, ReactGenerator as r, Options as t };
1210
- //# sourceMappingURL=types-BVMff21d.d.ts.map
1240
+ //# sourceMappingURL=types-Bs7HVpiD.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-cypress",
3
- "version": "4.12.5",
3
+ "version": "4.12.7",
4
4
  "description": "Cypress test generator plugin for Kubb, creating end-to-end tests from OpenAPI specifications for automated API testing.",
5
5
  "keywords": [
6
6
  "cypress",
@@ -74,11 +74,11 @@
74
74
  }
75
75
  ],
76
76
  "dependencies": {
77
- "@kubb/react-fabric": "0.7.1",
78
- "@kubb/core": "4.12.5",
79
- "@kubb/oas": "4.12.5",
80
- "@kubb/plugin-oas": "4.12.5",
81
- "@kubb/plugin-ts": "4.12.5"
77
+ "@kubb/react-fabric": "0.7.2",
78
+ "@kubb/core": "4.12.7",
79
+ "@kubb/oas": "4.12.7",
80
+ "@kubb/plugin-oas": "4.12.7",
81
+ "@kubb/plugin-ts": "4.12.7"
82
82
  },
83
83
  "engines": {
84
84
  "node": ">=20"
@@ -1,6 +1,7 @@
1
1
  import { URLPath } from '@kubb/core/utils'
2
2
  import { type HttpMethod, isOptional } from '@kubb/oas'
3
3
  import type { OperationSchemas } from '@kubb/plugin-oas'
4
+ import { getPathParams } from '@kubb/plugin-oas/utils'
4
5
  import { File, Function, FunctionParams } from '@kubb/react-fabric'
5
6
  import type { KubbNode } from '@kubb/react-fabric/types'
6
7
  import type { PluginCypress } from '../types.ts'
@@ -14,42 +15,133 @@ type Props = {
14
15
  url: string
15
16
  baseURL: string | undefined
16
17
  dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']
18
+ paramsCasing: PluginCypress['resolvedOptions']['paramsCasing']
19
+ paramsType: PluginCypress['resolvedOptions']['paramsType']
20
+ pathParamsType: PluginCypress['resolvedOptions']['pathParamsType']
17
21
  method: HttpMethod
18
22
  }
19
23
 
20
- export function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): KubbNode {
21
- const params = FunctionParams.factory({
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
+ return FunctionParams.factory({
34
+ data: {
35
+ mode: 'object',
36
+ children: {
37
+ ...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
38
+ data: typeSchemas.request?.name
39
+ ? {
40
+ type: typeSchemas.request?.name,
41
+ optional: isOptional(typeSchemas.request?.schema),
42
+ }
43
+ : undefined,
44
+ params: typeSchemas.queryParams?.name
45
+ ? {
46
+ type: typeSchemas.queryParams?.name,
47
+ optional: isOptional(typeSchemas.queryParams?.schema),
48
+ }
49
+ : undefined,
50
+ headers: typeSchemas.headerParams?.name
51
+ ? {
52
+ type: typeSchemas.headerParams?.name,
53
+ optional: isOptional(typeSchemas.headerParams?.schema),
54
+ }
55
+ : undefined,
56
+ },
57
+ },
58
+ options: {
59
+ type: 'Partial<Cypress.RequestOptions>',
60
+ optional: true,
61
+ default: '{}',
62
+ },
63
+ })
64
+ }
65
+
66
+ return FunctionParams.factory({
67
+ pathParams: typeSchemas.pathParams?.name
68
+ ? {
69
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
70
+ children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
71
+ optional: isOptional(typeSchemas.pathParams?.schema),
72
+ }
73
+ : undefined,
22
74
  data: typeSchemas.request?.name
23
75
  ? {
24
76
  type: typeSchemas.request?.name,
25
77
  optional: isOptional(typeSchemas.request?.schema),
26
78
  }
27
79
  : undefined,
28
-
80
+ params: typeSchemas.queryParams?.name
81
+ ? {
82
+ type: typeSchemas.queryParams?.name,
83
+ optional: isOptional(typeSchemas.queryParams?.schema),
84
+ }
85
+ : undefined,
86
+ headers: typeSchemas.headerParams?.name
87
+ ? {
88
+ type: typeSchemas.headerParams?.name,
89
+ optional: isOptional(typeSchemas.headerParams?.schema),
90
+ }
91
+ : undefined,
29
92
  options: {
30
93
  type: 'Partial<Cypress.RequestOptions>',
31
94
  optional: true,
32
95
  default: '{}',
33
96
  },
34
97
  })
98
+ }
99
+
100
+ export function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method, paramsType, paramsCasing, pathParamsType }: Props): KubbNode {
101
+ const path = new URLPath(url, { casing: paramsCasing })
102
+
103
+ const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
35
104
 
36
105
  const returnType =
37
106
  dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`
38
107
 
39
- const body = typeSchemas.request?.name ? 'data' : undefined
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')
40
131
 
41
132
  return (
42
133
  <File.Source name={name} isIndexable isExportable>
43
134
  <Function name={name} export params={params.toConstructor()} returnType={returnType}>
44
- {dataReturnType === 'data' &&
45
- `return cy.request({
46
- method: '${method}',
47
- url: \`${baseURL ?? ''}${new URLPath(url).toURLPath().replace(/([^/]):/g, '$1\\\\:')}\`,
48
- body: ${body},
49
- ...options,
50
- }).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}
51
- {dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}
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
+ })`}
52
142
  </Function>
53
143
  </File.Source>
54
144
  )
55
145
  }
146
+
147
+ Request.getParams = getParams
@@ -5,11 +5,11 @@
5
5
 
6
6
  export function createPets(data: CreatePetsMutationRequest, options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<CreatePetsMutationResponse> {
7
7
  return cy
8
- .request({
8
+ .request<CreatePetsMutationResponse>({
9
9
  method: 'post',
10
10
  url: `/pets`,
11
11
  body: data,
12
12
  ...options,
13
13
  })
14
- .then((res: Cypress.Response<CreatePetsMutationResponse>) => res.body)
14
+ .then((res) => res.body)
15
15
  }
@@ -3,13 +3,17 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export function deletePetsPetid(options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<DeletePetsPetidMutationResponse> {
6
+ export function deletePet(
7
+ petId: DeletePetPathParams['petId'],
8
+ headers?: DeletePetHeaderParams,
9
+ options?: Partial<Cypress.RequestOptions>,
10
+ ): Cypress.Chainable<DeletePetMutationResponse> {
7
11
  return cy
8
- .request({
12
+ .request<DeletePetMutationResponse>({
9
13
  method: 'delete',
10
- url: `/pets/:petId`,
11
- body: undefined,
14
+ url: `/pets/${petId}`,
15
+ headers,
12
16
  ...options,
13
17
  })
14
- .then((res: Cypress.Response<DeletePetsPetidMutationResponse>) => res.body)
18
+ .then((res) => res.body)
15
19
  }
@@ -3,13 +3,13 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export function listPets(options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ListPetsQueryResponse> {
6
+ export function listPets(params?: ListPetsQueryParams, options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ListPetsQueryResponse> {
7
7
  return cy
8
- .request({
8
+ .request<ListPetsQueryResponse>({
9
9
  method: 'get',
10
10
  url: `/pets`,
11
- body: undefined,
11
+ qs: params,
12
12
  ...options,
13
13
  })
14
- .then((res: Cypress.Response<ListPetsQueryResponse>) => res.body)
14
+ .then((res) => res.body)
15
15
  }
@@ -3,13 +3,13 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export function listPets(options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ListPetsQueryResponse> {
6
+ export function listPets(params?: ListPetsQueryParams, options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ListPetsQueryResponse> {
7
7
  return cy
8
- .request({
8
+ .request<ListPetsQueryResponse>({
9
9
  method: 'get',
10
10
  url: `${123456}/pets`,
11
- body: undefined,
11
+ qs: params,
12
12
  ...options,
13
13
  })
14
- .then((res: Cypress.Response<ListPetsQueryResponse>) => res.body)
14
+ .then((res) => res.body)
15
15
  }
@@ -3,13 +3,12 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
 
6
- export function showPetById(options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ShowPetByIdQueryResponse> {
6
+ export function showPetById(petId: ShowPetByIdPathParams['petId'], options?: Partial<Cypress.RequestOptions>): Cypress.Chainable<ShowPetByIdQueryResponse> {
7
7
  return cy
8
- .request({
8
+ .request<ShowPetByIdQueryResponse>({
9
9
  method: 'get',
10
- url: `/pets/:petId`,
11
- body: undefined,
10
+ url: `/pets/${petId}`,
12
11
  ...options,
13
12
  })
14
- .then((res: Cypress.Response<ShowPetByIdQueryResponse>) => res.body)
13
+ .then((res) => res.body)
15
14
  }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Generated by Kubb (https://kubb.dev/).
3
+ * Do not edit manually.
4
+ */
5
+
6
+ export function updatePet(
7
+ petId: UpdatePetPathParams['petId'],
8
+ data: UpdatePetMutationRequest,
9
+ options?: Partial<Cypress.RequestOptions>,
10
+ ): Cypress.Chainable<UpdatePetMutationResponse> {
11
+ return cy
12
+ .request<UpdatePetMutationResponse>({
13
+ method: 'put',
14
+ url: `/pets/${petId}`,
15
+ body: data,
16
+ ...options,
17
+ })
18
+ .then((res) => res.body)
19
+ }
@@ -1,5 +1,4 @@
1
1
  import { usePluginManager } from '@kubb/core/hooks'
2
- import { URLPath } from '@kubb/core/utils'
3
2
  import { createReactGenerator } from '@kubb/plugin-oas/generators'
4
3
  import { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'
5
4
  import { getBanner, getFooter } from '@kubb/plugin-oas/utils'
@@ -12,7 +11,7 @@ export const cypressGenerator = createReactGenerator<PluginCypress>({
12
11
  name: 'cypress',
13
12
  Operation({ operation, generator, plugin }) {
14
13
  const {
15
- options: { output, baseURL, dataReturnType },
14
+ options: { output, baseURL, dataReturnType, paramsCasing, paramsType, pathParamsType },
16
15
  } = plugin
17
16
  const pluginManager = usePluginManager()
18
17
 
@@ -53,10 +52,13 @@ export const cypressGenerator = createReactGenerator<PluginCypress>({
53
52
  <Request
54
53
  name={request.name}
55
54
  dataReturnType={dataReturnType}
55
+ paramsCasing={paramsCasing}
56
+ paramsType={paramsType}
57
+ pathParamsType={pathParamsType}
56
58
  typeSchemas={type.schemas}
57
59
  method={operation.method}
58
60
  baseURL={baseURL}
59
- url={new URLPath(operation.path).toURLPath()}
61
+ url={operation.path}
60
62
  />
61
63
  </File>
62
64
  )
package/src/plugin.ts CHANGED
@@ -20,6 +20,9 @@ export const pluginCypress = definePlugin<PluginCypress>((options) => {
20
20
  generators = [cypressGenerator].filter(Boolean),
21
21
  contentType,
22
22
  baseURL,
23
+ paramsCasing = 'camelcase',
24
+ paramsType = 'inline',
25
+ pathParamsType = paramsType === 'object' ? 'object' : options.pathParamsType || 'inline',
23
26
  } = options
24
27
 
25
28
  return {
@@ -29,6 +32,10 @@ export const pluginCypress = definePlugin<PluginCypress>((options) => {
29
32
  dataReturnType,
30
33
  group,
31
34
  baseURL,
35
+
36
+ paramsCasing,
37
+ paramsType,
38
+ pathParamsType,
32
39
  },
33
40
  pre: [pluginOasName, pluginTsName].filter(Boolean),
34
41
  resolvePath(baseName, pathMode, options) {
package/src/types.ts CHANGED
@@ -22,6 +22,25 @@ export type Options = {
22
22
  * @default 'data'
23
23
  */
24
24
  dataReturnType?: 'data' | 'full'
25
+ /**
26
+ * How to style your params, by default no casing is applied
27
+ * - 'camelcase' will use camelcase for the params names
28
+ */
29
+ paramsCasing?: 'camelcase'
30
+ /**
31
+ * How to pass your params
32
+ * - 'object' will return the params and pathParams as an object.
33
+ * - 'inline' will return the params as comma separated params.
34
+ * @default 'inline'
35
+ */
36
+ paramsType?: 'object' | 'inline'
37
+ /**
38
+ * How to pass your pathParams.
39
+ * - 'object' will return the pathParams as an object.
40
+ * - 'inline' will return the pathParams as comma separated params.
41
+ * @default 'inline'
42
+ */
43
+ pathParamsType?: 'object' | 'inline'
25
44
  baseURL?: string
26
45
  /**
27
46
  * Group the Cypress requests based on the provided name.
@@ -56,6 +75,9 @@ type ResolvedOptions = {
56
75
  group: Options['group']
57
76
  baseURL: Options['baseURL'] | undefined
58
77
  dataReturnType: NonNullable<Options['dataReturnType']>
78
+ pathParamsType: NonNullable<Options['pathParamsType']>
79
+ paramsType: NonNullable<Options['paramsType']>
80
+ paramsCasing: Options['paramsCasing']
59
81
  }
60
82
 
61
83
  export type PluginCypress = PluginFactoryOptions<'plugin-cypress', Options, ResolvedOptions, never, ResolvePathOptions>
@@ -1,48 +0,0 @@
1
- const require_index = require('./index.cjs');
2
- let _kubb_core_utils = require("@kubb/core/utils");
3
- let _kubb_react_fabric = require("@kubb/react-fabric");
4
- let _kubb_oas = require("@kubb/oas");
5
- let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
6
-
7
- //#region src/components/Request.tsx
8
- function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method }) {
9
- const params = _kubb_react_fabric.FunctionParams.factory({
10
- data: typeSchemas.request?.name ? {
11
- type: typeSchemas.request?.name,
12
- optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
13
- } : void 0,
14
- options: {
15
- type: "Partial<Cypress.RequestOptions>",
16
- optional: true,
17
- default: "{}"
18
- }
19
- });
20
- const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
21
- const body = typeSchemas.request?.name ? "data" : void 0;
22
- return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
23
- name,
24
- isIndexable: true,
25
- isExportable: true,
26
- children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
27
- name,
28
- export: true,
29
- params: params.toConstructor(),
30
- returnType,
31
- children: [dataReturnType === "data" && `return cy.request({
32
- method: '${method}',
33
- url: \`${baseURL ?? ""}${new _kubb_core_utils.URLPath(url).toURLPath().replace(/([^/]):/g, "$1\\\\:")}\`,
34
- body: ${body},
35
- ...options,
36
- }).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`, dataReturnType === "full" && `return cy.request('${method}', '${new _kubb_core_utils.URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body})`]
37
- })
38
- });
39
- }
40
-
41
- //#endregion
42
- Object.defineProperty(exports, 'Request', {
43
- enumerable: true,
44
- get: function () {
45
- return Request;
46
- }
47
- });
48
- //# sourceMappingURL=components-CNBoaPo0.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-CNBoaPo0.cjs","names":["FunctionParams","File","Function","URLPath"],"sources":["../src/components/Request.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { type HttpMethod, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginCypress } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeSchemas: OperationSchemas\n url: string\n baseURL: string | undefined\n dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']\n method: HttpMethod\n}\n\nexport function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): KubbNode {\n const params = FunctionParams.factory({\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n\n options: {\n type: 'Partial<Cypress.RequestOptions>',\n optional: true,\n default: '{}',\n },\n })\n\n const returnType =\n dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`\n\n const body = typeSchemas.request?.name ? 'data' : undefined\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()} returnType={returnType}>\n {dataReturnType === 'data' &&\n `return cy.request({\n method: '${method}', \n url: \\`${baseURL ?? ''}${new URLPath(url).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\\`, \n body: ${body},\n ...options,\n }).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}\n {dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;;AAmBA,SAAgB,QAAQ,EAAE,UAAU,IAAI,MAAM,gBAAgB,aAAa,KAAK,UAA2B;CACzG,MAAM,SAASA,kCAAe,QAAQ;EACpC,MAAM,YAAY,SAAS,OACvB;GACE,MAAM,YAAY,SAAS;GAC3B,oCAAqB,YAAY,SAAS,OAAO;GAClD,GACD;EAEJ,SAAS;GACP,MAAM;GACN,UAAU;GACV,SAAS;GACV;EACF,CAAC;CAEF,MAAM,aACJ,mBAAmB,SAAS,qBAAqB,YAAY,SAAS,KAAK,KAAK,sCAAsC,YAAY,SAAS,KAAK;CAElJ,MAAM,OAAO,YAAY,SAAS,OAAO,SAAS;AAElD,QACE,wDAACC,wBAAK;EAAa;EAAM;EAAY;YACnC,yDAACC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;GAAc;cACtE,mBAAmB,UAClB;uBACa,OAAO;qBACT,WAAW,KAAK,IAAIC,yBAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,UAAU,CAAC;oBAC7E,KAAK;;2CAEkB,YAAY,SAAS,KAAK,kBAC5D,mBAAmB,UAAU,sBAAsB,OAAO,MAAM,IAAIA,yBAAQ,GAAG,WAAW,KAAK,MAAM,CAAC,WAAW,CAAC,KAAK,KAAK;IACpH;GACC"}
@@ -1,42 +0,0 @@
1
- import { URLPath } from "@kubb/core/utils";
2
- import { File, Function, FunctionParams } from "@kubb/react-fabric";
3
- import { isOptional } from "@kubb/oas";
4
- import { jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
5
-
6
- //#region src/components/Request.tsx
7
- function Request({ baseURL = "", name, dataReturnType, typeSchemas, url, method }) {
8
- const params = FunctionParams.factory({
9
- data: typeSchemas.request?.name ? {
10
- type: typeSchemas.request?.name,
11
- optional: isOptional(typeSchemas.request?.schema)
12
- } : void 0,
13
- options: {
14
- type: "Partial<Cypress.RequestOptions>",
15
- optional: true,
16
- default: "{}"
17
- }
18
- });
19
- const returnType = dataReturnType === "data" ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`;
20
- const body = typeSchemas.request?.name ? "data" : void 0;
21
- return /* @__PURE__ */ jsx(File.Source, {
22
- name,
23
- isIndexable: true,
24
- isExportable: true,
25
- children: /* @__PURE__ */ jsxs(Function, {
26
- name,
27
- export: true,
28
- params: params.toConstructor(),
29
- returnType,
30
- children: [dataReturnType === "data" && `return cy.request({
31
- method: '${method}',
32
- url: \`${baseURL ?? ""}${new URLPath(url).toURLPath().replace(/([^/]):/g, "$1\\\\:")}\`,
33
- body: ${body},
34
- ...options,
35
- }).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`, dataReturnType === "full" && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ""}${url}`).toURLPath()}', ${body})`]
36
- })
37
- });
38
- }
39
-
40
- //#endregion
41
- export { Request as t };
42
- //# sourceMappingURL=components-GZOhGVCA.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"components-GZOhGVCA.js","names":[],"sources":["../src/components/Request.tsx"],"sourcesContent":["import { URLPath } from '@kubb/core/utils'\nimport { type HttpMethod, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { File, Function, FunctionParams } from '@kubb/react-fabric'\nimport type { KubbNode } from '@kubb/react-fabric/types'\nimport type { PluginCypress } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n typeSchemas: OperationSchemas\n url: string\n baseURL: string | undefined\n dataReturnType: PluginCypress['resolvedOptions']['dataReturnType']\n method: HttpMethod\n}\n\nexport function Request({ baseURL = '', name, dataReturnType, typeSchemas, url, method }: Props): KubbNode {\n const params = FunctionParams.factory({\n data: typeSchemas.request?.name\n ? {\n type: typeSchemas.request?.name,\n optional: isOptional(typeSchemas.request?.schema),\n }\n : undefined,\n\n options: {\n type: 'Partial<Cypress.RequestOptions>',\n optional: true,\n default: '{}',\n },\n })\n\n const returnType =\n dataReturnType === 'data' ? `Cypress.Chainable<${typeSchemas.response.name}>` : `Cypress.Chainable<Cypress.Response<${typeSchemas.response.name}>>`\n\n const body = typeSchemas.request?.name ? 'data' : undefined\n\n return (\n <File.Source name={name} isIndexable isExportable>\n <Function name={name} export params={params.toConstructor()} returnType={returnType}>\n {dataReturnType === 'data' &&\n `return cy.request({\n method: '${method}', \n url: \\`${baseURL ?? ''}${new URLPath(url).toURLPath().replace(/([^/]):/g, '$1\\\\\\\\:')}\\`, \n body: ${body},\n ...options,\n }).then((res: Cypress.Response<${typeSchemas.response.name}>) => res.body)`}\n {dataReturnType === 'full' && `return cy.request('${method}', '${new URLPath(`${baseURL ?? ''}${url}`).toURLPath()}', ${body})`}\n </Function>\n </File.Source>\n )\n}\n"],"mappings":";;;;;;AAmBA,SAAgB,QAAQ,EAAE,UAAU,IAAI,MAAM,gBAAgB,aAAa,KAAK,UAA2B;CACzG,MAAM,SAAS,eAAe,QAAQ;EACpC,MAAM,YAAY,SAAS,OACvB;GACE,MAAM,YAAY,SAAS;GAC3B,UAAU,WAAW,YAAY,SAAS,OAAO;GAClD,GACD;EAEJ,SAAS;GACP,MAAM;GACN,UAAU;GACV,SAAS;GACV;EACF,CAAC;CAEF,MAAM,aACJ,mBAAmB,SAAS,qBAAqB,YAAY,SAAS,KAAK,KAAK,sCAAsC,YAAY,SAAS,KAAK;CAElJ,MAAM,OAAO,YAAY,SAAS,OAAO,SAAS;AAElD,QACE,oBAAC,KAAK;EAAa;EAAM;EAAY;YACnC,qBAAC;GAAe;GAAM;GAAO,QAAQ,OAAO,eAAe;GAAc;cACtE,mBAAmB,UAClB;uBACa,OAAO;qBACT,WAAW,KAAK,IAAI,QAAQ,IAAI,CAAC,WAAW,CAAC,QAAQ,YAAY,UAAU,CAAC;oBAC7E,KAAK;;2CAEkB,YAAY,SAAS,KAAK,kBAC5D,mBAAmB,UAAU,sBAAsB,OAAO,MAAM,IAAI,QAAQ,GAAG,WAAW,KAAK,MAAM,CAAC,WAAW,CAAC,KAAK,KAAK;IACpH;GACC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generators-CnEpcL-m.js","names":[],"sources":["../src/generators/cypressGenerator.tsx"],"sourcesContent":["import { usePluginManager } from '@kubb/core/hooks'\nimport { URLPath } from '@kubb/core/utils'\nimport { createReactGenerator } from '@kubb/plugin-oas/generators'\nimport { useOas, useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { getBanner, getFooter } from '@kubb/plugin-oas/utils'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File } from '@kubb/react-fabric'\nimport { Request } from '../components'\nimport type { PluginCypress } from '../types'\n\nexport const cypressGenerator = createReactGenerator<PluginCypress>({\n name: 'cypress',\n Operation({ operation, generator, plugin }) {\n const {\n options: { output, baseURL, dataReturnType },\n } = plugin\n const pluginManager = usePluginManager()\n\n const oas = useOas()\n const { getSchemas, getName, getFile } = useOperationManager(generator)\n\n const request = {\n name: getName(operation, { type: 'function' }),\n file: getFile(operation),\n }\n\n const type = {\n file: getFile(operation, { pluginKey: [pluginTsName] }),\n schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),\n }\n\n return (\n <File\n baseName={request.file.baseName}\n path={request.file.path}\n meta={request.file.meta}\n banner={getBanner({ oas, output, config: pluginManager.config })}\n footer={getFooter({ oas, output })}\n >\n <File.Import\n name={[\n type.schemas.request?.name,\n type.schemas.response.name,\n type.schemas.pathParams?.name,\n type.schemas.queryParams?.name,\n type.schemas.headerParams?.name,\n ...(type.schemas.statusCodes?.map((item) => item.name) || []),\n ].filter(Boolean)}\n root={request.file.path}\n path={type.file.path}\n isTypeOnly\n />\n <Request\n name={request.name}\n dataReturnType={dataReturnType}\n typeSchemas={type.schemas}\n method={operation.method}\n baseURL={baseURL}\n url={new URLPath(operation.path).toURLPath()}\n />\n </File>\n )\n },\n})\n"],"mappings":";;;;;;;;;;;AAUA,MAAa,mBAAmB,qBAAoC;CAClE,MAAM;CACN,UAAU,EAAE,WAAW,WAAW,UAAU;EAC1C,MAAM,EACJ,SAAS,EAAE,QAAQ,SAAS,qBAC1B;EACJ,MAAM,gBAAgB,kBAAkB;EAExC,MAAM,MAAM,QAAQ;EACpB,MAAM,EAAE,YAAY,SAAS,YAAY,oBAAoB,UAAU;EAEvE,MAAM,UAAU;GACd,MAAM,QAAQ,WAAW,EAAE,MAAM,YAAY,CAAC;GAC9C,MAAM,QAAQ,UAAU;GACzB;EAED,MAAM,OAAO;GACX,MAAM,QAAQ,WAAW,EAAE,WAAW,CAAC,aAAa,EAAE,CAAC;GACvD,SAAS,WAAW,WAAW;IAAE,WAAW,CAAC,aAAa;IAAE,MAAM;IAAQ,CAAC;GAC5E;AAED,SACE,qBAAC;GACC,UAAU,QAAQ,KAAK;GACvB,MAAM,QAAQ,KAAK;GACnB,MAAM,QAAQ,KAAK;GACnB,QAAQ,UAAU;IAAE;IAAK;IAAQ,QAAQ,cAAc;IAAQ,CAAC;GAChE,QAAQ,UAAU;IAAE;IAAK;IAAQ,CAAC;cAElC,oBAAC,KAAK;IACJ,MAAM;KACJ,KAAK,QAAQ,SAAS;KACtB,KAAK,QAAQ,SAAS;KACtB,KAAK,QAAQ,YAAY;KACzB,KAAK,QAAQ,aAAa;KAC1B,KAAK,QAAQ,cAAc;KAC3B,GAAI,KAAK,QAAQ,aAAa,KAAK,SAAS,KAAK,KAAK,IAAI,EAAE;KAC7D,CAAC,OAAO,QAAQ;IACjB,MAAM,QAAQ,KAAK;IACnB,MAAM,KAAK,KAAK;IAChB;KACA,EACF,oBAAC;IACC,MAAM,QAAQ;IACE;IAChB,aAAa,KAAK;IAClB,QAAQ,UAAU;IACT;IACT,KAAK,IAAI,QAAQ,UAAU,KAAK,CAAC,WAAW;KAC5C;IACG;;CAGZ,CAAC"}