@kubb/plugin-client 3.0.0-alpha.15 → 3.0.0-alpha.17

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 (51) hide show
  1. package/client.ts +1 -1
  2. package/dist/{chunk-TNO4CNBR.cjs → chunk-44KNIIBT.cjs} +52 -30
  3. package/dist/chunk-44KNIIBT.cjs.map +1 -0
  4. package/dist/chunk-HGQQGWKN.js +130 -0
  5. package/dist/chunk-HGQQGWKN.js.map +1 -0
  6. package/dist/chunk-NEK3OJBX.cjs +133 -0
  7. package/dist/chunk-NEK3OJBX.cjs.map +1 -0
  8. package/dist/{chunk-H2OOHGK2.js → chunk-XB4BUZDK.js} +51 -29
  9. package/dist/chunk-XB4BUZDK.js.map +1 -0
  10. package/dist/client.cjs.map +1 -1
  11. package/dist/client.d.cts +1 -1
  12. package/dist/client.d.ts +1 -1
  13. package/dist/client.js.map +1 -1
  14. package/dist/components.cjs +3 -3
  15. package/dist/components.d.cts +29 -4
  16. package/dist/components.d.ts +29 -4
  17. package/dist/components.js +1 -1
  18. package/dist/generators.cjs +4 -4
  19. package/dist/generators.d.cts +1 -3
  20. package/dist/generators.d.ts +1 -3
  21. package/dist/generators.js +2 -2
  22. package/dist/index.cjs +4 -4
  23. package/dist/index.d.cts +1 -3
  24. package/dist/index.d.ts +1 -3
  25. package/dist/index.js +2 -2
  26. package/dist/{types-CzL-44IA.d.cts → types-j-ah_78Y.d.cts} +9 -17
  27. package/dist/{types-CzL-44IA.d.ts → types-j-ah_78Y.d.ts} +9 -17
  28. package/package.json +14 -13
  29. package/src/components/Client.tsx +75 -55
  30. package/src/generators/__snapshots__/deletePet.ts +17 -0
  31. package/src/generators/__snapshots__/deletePetObject.ts +25 -0
  32. package/src/generators/__snapshots__/findByTags.ts +12 -0
  33. package/src/generators/__snapshots__/findByTagsFull.ts +12 -0
  34. package/src/generators/__snapshots__/findByTagsWithZod.ts +12 -0
  35. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +12 -0
  36. package/src/generators/__snapshots__/importPath.ts +12 -0
  37. package/src/generators/__snapshots__/operations.ts +82 -0
  38. package/src/generators/__snapshots__/updatePetById.ts +15 -0
  39. package/src/generators/clientGenerator.tsx +40 -21
  40. package/src/generators/operationsGenerator.tsx +1 -1
  41. package/src/plugin.ts +4 -4
  42. package/src/types.ts +7 -4
  43. package/dist/chunk-BAX6ZFGY.js +0 -122
  44. package/dist/chunk-BAX6ZFGY.js.map +0 -1
  45. package/dist/chunk-H2OOHGK2.js.map +0 -1
  46. package/dist/chunk-TNO4CNBR.cjs.map +0 -1
  47. package/dist/chunk-XDWPA5EL.cjs +0 -125
  48. package/dist/chunk-XDWPA5EL.cjs.map +0 -1
  49. package/src/components/__snapshots__/Client/showPetById.ts +0 -8
  50. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  51. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
@@ -3,7 +3,7 @@ import { URLPath } from '@kubb/core/utils'
3
3
  import { type Operation, isOptional } from '@kubb/oas'
4
4
  import type { OperationSchemas } from '@kubb/plugin-oas'
5
5
  import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
- import { File, Function, createFunctionParams } from '@kubb/react'
6
+ import { File, Function, FunctionParams } from '@kubb/react'
7
7
  import type { KubbNode } from '@kubb/react/types'
8
8
  import type { PluginClient } from '../types.ts'
9
9
 
@@ -12,87 +12,107 @@ type Props = {
12
12
  * Name of the function
13
13
  */
14
14
  name: string
15
- options: PluginClient['resolvedOptions']
16
- typedSchemas: OperationSchemas
15
+ isExportable?: boolean
16
+ isIndexable?: boolean
17
+
18
+ baseURL: string | undefined
19
+ dataReturnType: PluginClient['resolvedOptions']['dataReturnType']
20
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
21
+ parser: PluginClient['resolvedOptions']['parser'] | undefined
22
+ typeSchemas: OperationSchemas
23
+ zodSchemas: OperationSchemas | undefined
17
24
  operation: Operation
18
25
  }
19
26
 
20
- export function Client({ name, options, typedSchemas, operation }: Props): KubbNode {
21
- const contentType = operation.getContentType()
22
- const baseURL = options.baseURL
23
- const path = new URLPath(operation.path)
24
- const isFormData = contentType === 'multipart/form-data'
25
- const headers = [
26
- contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
27
- typedSchemas.headerParams?.name ? '...headers' : undefined,
28
- ].filter(Boolean)
27
+ type GetParamsProps = {
28
+ pathParamsType: PluginClient['resolvedOptions']['pathParamsType']
29
+ typeSchemas: OperationSchemas
30
+ }
29
31
 
30
- const params = createFunctionParams({
32
+ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
33
+ return FunctionParams.factory({
31
34
  pathParams: {
32
- mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',
33
- children: getPathParams(typedSchemas.pathParams, { typed: true }),
35
+ mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
36
+ children: getPathParams(typeSchemas.pathParams, { typed: true }),
34
37
  },
35
- data: typedSchemas.request?.name
38
+ data: typeSchemas.request?.name
36
39
  ? {
37
- type: typedSchemas.request?.name,
38
- optional: isOptional(typedSchemas.request?.schema),
40
+ type: typeSchemas.request?.name,
41
+ optional: isOptional(typeSchemas.request?.schema),
39
42
  }
40
43
  : undefined,
41
- params: typedSchemas.queryParams?.name
44
+ params: typeSchemas.queryParams?.name
42
45
  ? {
43
- type: typedSchemas.queryParams?.name,
44
- optional: isOptional(typedSchemas.queryParams?.schema),
46
+ type: typeSchemas.queryParams?.name,
47
+ optional: isOptional(typeSchemas.queryParams?.schema),
45
48
  }
46
49
  : undefined,
47
- headers: typedSchemas.headerParams?.name
50
+ headers: typeSchemas.headerParams?.name
48
51
  ? {
49
- type: typedSchemas.headerParams?.name,
50
- optional: isOptional(typedSchemas.headerParams?.schema),
52
+ type: typeSchemas.headerParams?.name,
53
+ optional: isOptional(typeSchemas.headerParams?.schema),
51
54
  }
52
55
  : undefined,
53
- options: {
54
- type: 'Partial<Parameters<typeof client>[0]>',
56
+ config: {
57
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>>` : 'Partial<RequestConfig>',
55
58
  default: '{}',
56
59
  },
57
60
  })
61
+ }
62
+
63
+ export function Client({
64
+ name,
65
+ isExportable = true,
66
+ isIndexable = true,
67
+ typeSchemas,
68
+ baseURL,
69
+ dataReturnType,
70
+ parser,
71
+ zodSchemas,
72
+ pathParamsType,
73
+ operation,
74
+ }: Props): KubbNode {
75
+ const path = new URLPath(operation.path)
76
+ const contentType = operation.getContentType()
77
+ const isFormData = contentType === 'multipart/form-data'
78
+ const headers = [
79
+ contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
80
+ typeSchemas.headerParams?.name ? '...headers' : undefined,
81
+ ].filter(Boolean)
58
82
 
59
- const clientParams = createFunctionParams({
60
- data: {
83
+ const generics = [
84
+ typeSchemas.response.name,
85
+ typeSchemas.errors?.map((item) => item.name).join(' | ') || 'unknown',
86
+ typeSchemas.request?.name || 'unknown',
87
+ ].filter(Boolean)
88
+ const params = getParams({ pathParamsType, typeSchemas })
89
+ const clientParams = FunctionParams.factory({
90
+ config: {
61
91
  mode: 'object',
62
92
  children: {
63
93
  method: {
64
- type: 'string',
65
94
  value: JSON.stringify(operation.method),
66
95
  },
67
96
  url: {
68
- type: 'string',
69
97
  value: path.template,
70
98
  },
71
99
  baseURL: baseURL
72
100
  ? {
73
- type: 'string',
74
101
  value: JSON.stringify(baseURL),
75
102
  }
76
103
  : undefined,
77
- params: typedSchemas.queryParams?.name
104
+ params: typeSchemas.queryParams?.name ? {} : undefined,
105
+ data: typeSchemas.request?.name
78
106
  ? {
79
- type: 'any',
80
- }
81
- : undefined,
82
- data: typedSchemas.request?.name
83
- ? {
84
- type: 'any',
85
107
  value: isFormData ? 'formData' : undefined,
86
108
  }
87
109
  : undefined,
88
110
  headers: headers.length
89
111
  ? {
90
- type: 'any',
91
- value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,
112
+ value: headers.length ? `{ ${headers.join(', ')}, ...config.headers }` : undefined,
92
113
  }
93
114
  : undefined,
94
- options: {
95
- type: 'any',
115
+ config: {
96
116
  mode: 'inlineSpread',
97
117
  },
98
118
  },
@@ -111,29 +131,29 @@ export function Client({ name, options, typedSchemas, operation }: Props): KubbN
111
131
  })
112
132
  }
113
133
  `
114
- : undefined
134
+ : ''
115
135
 
116
136
  return (
117
- <File.Source name={name} isExportable isIndexable>
137
+ <File.Source name={name} isExportable={isExportable} isIndexable={isIndexable}>
118
138
  <Function
119
139
  name={name}
120
140
  async
121
- export
122
- returnType={
123
- options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`
124
- }
125
- params={params}
141
+ export={isExportable}
142
+ params={params.toConstructor()}
126
143
  JSDoc={{
127
144
  comments: getComments(operation),
128
145
  }}
129
146
  >
130
- {formData || ''}
131
- <Function.Call
132
- name="res"
133
- to={<Function name="client" async generics={[typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean)} params={clientParams} />}
134
- />
135
- <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>
147
+ {formData}
148
+ {`const res = await client<${generics.join(', ')}>(${clientParams.toCall()})`}
149
+ <br />
150
+ {dataReturnType === 'full' && parser === 'zod' && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`}
151
+ {dataReturnType === 'data' && parser === 'zod' && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`}
152
+ {dataReturnType === 'full' && parser === 'client' && 'return res'}
153
+ {dataReturnType === 'data' && parser === 'client' && 'return res.data'}
136
154
  </Function>
137
155
  </File.Source>
138
156
  )
139
157
  }
158
+
159
+ Client.getParams = getParams
@@ -0,0 +1,17 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description delete a pet
6
+ * @summary Deletes a pet
7
+ * @link /pet/:petId
8
+ */
9
+ export async function deletePet(petId: DeletePetPathParams['petId'], headers?: DeletePetHeaderParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
11
+ method: 'delete',
12
+ url: `/pet/${petId}`,
13
+ headers: { ...headers, ...config.headers },
14
+ ...config,
15
+ })
16
+ return res.data
17
+ }
@@ -0,0 +1,25 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description delete a pet
6
+ * @summary Deletes a pet
7
+ * @link /pet/:petId
8
+ */
9
+ export async function deletePet(
10
+ {
11
+ petId,
12
+ }: {
13
+ petId: DeletePetPathParams['petId']
14
+ },
15
+ headers?: DeletePetHeaderParams,
16
+ config: Partial<RequestConfig> = {},
17
+ ) {
18
+ const res = await client<DeletePetMutationResponse, DeletePet400, unknown>({
19
+ method: 'delete',
20
+ url: `/pet/${petId}`,
21
+ headers: { ...headers, ...config.headers },
22
+ ...config,
23
+ })
24
+ return res.data
25
+ }
@@ -0,0 +1,12 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
6
+ * @summary Finds Pets by tags
7
+ * @link /pet/findByTags
8
+ */
9
+ export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'get', url: `/pet/findByTags`, params, ...config })
11
+ return res.data
12
+ }
@@ -0,0 +1,12 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
6
+ * @summary Finds Pets by tags
7
+ * @link /pet/findByTags
8
+ */
9
+ export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'get', url: `/pet/findByTags`, params, ...config })
11
+ return res
12
+ }
@@ -0,0 +1,12 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
6
+ * @summary Finds Pets by tags
7
+ * @link /pet/findByTags
8
+ */
9
+ export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'get', url: `/pet/findByTags`, params, ...config })
11
+ return findPetsByTagsQueryResponse.parse(res.data)
12
+ }
@@ -0,0 +1,12 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
6
+ * @summary Finds Pets by tags
7
+ * @link /pet/findByTags
8
+ */
9
+ export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'get', url: `/pet/findByTags`, params, ...config })
11
+ return { ...res, data: findPetsByTagsQueryResponse.parse(res.data) }
12
+ }
@@ -0,0 +1,12 @@
1
+ import client from 'axios'
2
+ import type { RequestConfig } from 'axios'
3
+
4
+ /**
5
+ * @description Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.
6
+ * @summary Finds Pets by tags
7
+ * @link /pet/findByTags
8
+ */
9
+ export async function findPetsByTags(params?: FindPetsByTagsQueryParams, config: Partial<RequestConfig> = {}) {
10
+ const res = await client<FindPetsByTagsQueryResponse, FindPetsByTags400, unknown>({ method: 'get', url: `/pet/findByTags`, params, ...config })
11
+ return res.data
12
+ }
@@ -0,0 +1,82 @@
1
+ export const operations = {
2
+ updatePet: {
3
+ path: '/pet',
4
+ method: 'put',
5
+ },
6
+ addPet: {
7
+ path: '/pet',
8
+ method: 'post',
9
+ },
10
+ findPetsByStatus: {
11
+ path: '/pet/findByStatus',
12
+ method: 'get',
13
+ },
14
+ findPetsByTags: {
15
+ path: '/pet/findByTags',
16
+ method: 'get',
17
+ },
18
+ getPetById: {
19
+ path: '/pet/:petId',
20
+ method: 'get',
21
+ },
22
+ updatePetWithForm: {
23
+ path: '/pet/:petId',
24
+ method: 'post',
25
+ },
26
+ deletePet: {
27
+ path: '/pet/:petId',
28
+ method: 'delete',
29
+ },
30
+ uploadFile: {
31
+ path: '/pet/:petId/uploadImage',
32
+ method: 'post',
33
+ },
34
+ getInventory: {
35
+ path: '/store/inventory',
36
+ method: 'get',
37
+ },
38
+ placeOrder: {
39
+ path: '/store/order',
40
+ method: 'post',
41
+ },
42
+ placeOrderPatch: {
43
+ path: '/store/order',
44
+ method: 'patch',
45
+ },
46
+ getOrderById: {
47
+ path: '/store/order/:orderId',
48
+ method: 'get',
49
+ },
50
+ deleteOrder: {
51
+ path: '/store/order/:orderId',
52
+ method: 'delete',
53
+ },
54
+ createUser: {
55
+ path: '/user',
56
+ method: 'post',
57
+ },
58
+ createUsersWithListInput: {
59
+ path: '/user/createWithList',
60
+ method: 'post',
61
+ },
62
+ loginUser: {
63
+ path: '/user/login',
64
+ method: 'get',
65
+ },
66
+ logoutUser: {
67
+ path: '/user/logout',
68
+ method: 'get',
69
+ },
70
+ getUserByName: {
71
+ path: '/user/:username',
72
+ method: 'get',
73
+ },
74
+ updateUser: {
75
+ path: '/user/:username',
76
+ method: 'put',
77
+ },
78
+ deleteUser: {
79
+ path: '/user/:username',
80
+ method: 'delete',
81
+ },
82
+ } as const
@@ -0,0 +1,15 @@
1
+ import client from '@kubb/plugin-client/client'
2
+ import type { RequestConfig } from '@kubb/plugin-client/client'
3
+
4
+ /**
5
+ * @summary Updates a pet in the store with form data
6
+ * @link /pet/:petId
7
+ */
8
+ export async function updatePetWithForm(
9
+ petId: UpdatePetWithFormPathParams['petId'],
10
+ params?: UpdatePetWithFormQueryParams,
11
+ config: Partial<RequestConfig> = {},
12
+ ) {
13
+ const res = await client<UpdatePetWithFormMutationResponse, UpdatePetWithForm405, unknown>({ method: 'post', url: `/pet/${petId}`, params, ...config })
14
+ return res.data
15
+ }
@@ -1,45 +1,64 @@
1
1
  import { createReactGenerator } from '@kubb/plugin-oas'
2
2
  import { useOperationManager } from '@kubb/plugin-oas/hooks'
3
3
  import { pluginTsName } from '@kubb/plugin-ts'
4
+ import { pluginZodName } from '@kubb/plugin-zod'
4
5
  import { File, useApp } from '@kubb/react'
5
6
  import { Client } from '../components/Client'
6
7
  import type { PluginClient } from '../types'
7
8
 
8
9
  export const clientGenerator = createReactGenerator<PluginClient>({
9
- name: 'plugin-client',
10
+ name: 'client',
10
11
  Operation({ options, operation }) {
11
- const { plugin } = useApp<PluginClient>()
12
+ const {
13
+ plugin: { output },
14
+ } = useApp<PluginClient>()
12
15
  const { getSchemas, getName, getFile } = useOperationManager()
13
16
 
14
- const name = getName(operation, { type: 'function' })
15
- const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
16
- const file = getFile(operation)
17
- const typedFile = getFile(operation, { pluginKey: [pluginTsName] })
17
+ const client = {
18
+ name: getName(operation, { type: 'function' }),
19
+ file: getFile(operation),
20
+ }
18
21
 
19
- if (!options.template) {
20
- return null
22
+ const type = {
23
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
24
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
21
25
  }
22
26
 
23
- const Template = options.template || Client
27
+ const zod = {
28
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
29
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
30
+ }
24
31
 
25
32
  return (
26
- <File baseName={file.baseName} path={file.path} meta={file.meta}>
27
- <File.Import name={'client'} path={options.importPath || '@kubb/plugin-client/client'} />
28
- <File.Import name={['ResponseConfig']} path={options.importPath || '@kubb/plugin-client/client'} isTypeOnly />
33
+ <File baseName={client.file.baseName} path={client.file.path} meta={client.file.meta}>
34
+ <File.Import name={'client'} path={options.importPath} />
35
+ <File.Import name={['RequestConfig']} path={options.importPath} isTypeOnly />
36
+ {options.parser === 'zod' && <File.Import extName={output?.extName} name={[zod.schemas.response.name]} root={client.file.path} path={zod.file.path} />}
29
37
  <File.Import
30
- extName={plugin.output?.extName}
38
+ extName={output?.extName}
31
39
  name={[
32
- typedSchemas.request?.name,
33
- typedSchemas.response.name,
34
- typedSchemas.pathParams?.name,
35
- typedSchemas.queryParams?.name,
36
- typedSchemas.headerParams?.name,
40
+ type.schemas.request?.name,
41
+ type.schemas.response.name,
42
+ type.schemas.pathParams?.name,
43
+ type.schemas.queryParams?.name,
44
+ type.schemas.headerParams?.name,
45
+ ...(type.schemas.statusCodes?.map((item) => item.name) || []),
37
46
  ].filter(Boolean)}
38
- root={file.path}
39
- path={typedFile.path}
47
+ root={client.file.path}
48
+ path={type.file.path}
40
49
  isTypeOnly
41
50
  />
42
- <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />
51
+
52
+ <Client
53
+ name={client.name}
54
+ baseURL={options.baseURL}
55
+ dataReturnType={options.dataReturnType}
56
+ pathParamsType={options.pathParamsType}
57
+ typeSchemas={type.schemas}
58
+ operation={operation}
59
+ parser={options.parser}
60
+ zodSchemas={zod.schemas}
61
+ />
43
62
  </File>
44
63
  )
45
64
  },
@@ -5,7 +5,7 @@ import { Operations } from '../components/Operations'
5
5
  import type { PluginClient } from '../types'
6
6
 
7
7
  export const operationsGenerator = createReactGenerator<PluginClient>({
8
- name: 'plugin-client',
8
+ name: 'client',
9
9
  Operations({ operations }) {
10
10
  const { pluginManager } = useApp<PluginClient>()
11
11
 
package/src/plugin.ts CHANGED
@@ -5,10 +5,9 @@ import { camelCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
6
  import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
7
 
8
- import { Client } from './components/index.ts'
9
-
10
8
  import type { Plugin } from '@kubb/core'
11
9
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
10
+ import { pluginZodName } from '@kubb/plugin-zod'
12
11
  import { operationsGenerator } from './generators'
13
12
  import { clientGenerator } from './generators/clientGenerator.tsx'
14
13
  import type { PluginClient } from './types.ts'
@@ -27,6 +26,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
27
26
  pathParamsType = 'inline',
28
27
  operations = false,
29
28
  importPath = '@kubb/plugin-client/client',
29
+ parser = 'client',
30
30
  } = options
31
31
 
32
32
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
@@ -38,13 +38,13 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
38
38
  ...output,
39
39
  },
40
40
  options: {
41
+ parser,
41
42
  dataReturnType,
42
43
  importPath,
43
- template: options.template || Client,
44
44
  pathParamsType,
45
45
  baseURL: undefined,
46
46
  },
47
- pre: [pluginOasName],
47
+ pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
48
48
  resolvePath(baseName, pathMode, options) {
49
49
  const root = path.resolve(this.config.root, this.config.output.path)
50
50
  const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
package/src/types.ts CHANGED
@@ -1,9 +1,7 @@
1
1
  import type { Plugin, PluginFactoryOptions, ResolveNameParams } from '@kubb/core'
2
2
  import type * as KubbFile from '@kubb/fs/types'
3
3
 
4
- import type { HttpMethod } from '@kubb/oas'
5
4
  import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
6
- import type { Client } from './components/index.ts'
7
5
 
8
6
  export type Options = {
9
7
  output?: {
@@ -73,7 +71,6 @@ export type Options = {
73
71
  * @default '@kubb/plugin-client/client'
74
72
  */
75
73
  importPath?: string
76
- template?: typeof Client
77
74
  /**
78
75
  * ReturnType that needs to be used when calling client().
79
76
  *
@@ -94,6 +91,12 @@ export type Options = {
94
91
  * @private
95
92
  */
96
93
  pathParamsType?: 'object' | 'inline'
94
+ /**
95
+ * Which parser can be used before returning the data
96
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
97
+ * @default 'client'
98
+ */
99
+ parser?: 'client' | 'zod'
97
100
  transformers?: {
98
101
  /**
99
102
  * Customize the names based on the type that is provided by the plugin.
@@ -104,8 +107,8 @@ export type Options = {
104
107
 
105
108
  type ResolvedOptions = {
106
109
  baseURL: string | undefined
110
+ parser: NonNullable<Options['parser']>
107
111
  importPath: NonNullable<Options['importPath']>
108
- template: NonNullable<Options['template']>
109
112
  dataReturnType: NonNullable<Options['dataReturnType']>
110
113
  pathParamsType: NonNullable<Options['pathParamsType']>
111
114
  }