@kubb/plugin-client 3.0.0-alpha.1 → 3.0.0-alpha.11

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 (53) hide show
  1. package/client.ts +1 -1
  2. package/dist/chunk-3NQF7BGA.cjs +58 -0
  3. package/dist/chunk-3NQF7BGA.cjs.map +1 -0
  4. package/dist/chunk-AZDWYBLW.cjs +4 -0
  5. package/dist/chunk-AZDWYBLW.cjs.map +1 -0
  6. package/dist/chunk-PO22ZUSH.cjs +125 -0
  7. package/dist/chunk-PO22ZUSH.cjs.map +1 -0
  8. package/dist/chunk-QBFKND4S.js +122 -0
  9. package/dist/chunk-QBFKND4S.js.map +1 -0
  10. package/dist/chunk-QLVGX3VO.js +56 -0
  11. package/dist/chunk-QLVGX3VO.js.map +1 -0
  12. package/dist/chunk-YJOVLRSC.js +3 -0
  13. package/dist/chunk-YJOVLRSC.js.map +1 -0
  14. package/dist/client.cjs +16 -7
  15. package/dist/client.cjs.map +1 -1
  16. package/dist/client.d.cts +1 -1
  17. package/dist/client.d.ts +1 -1
  18. package/dist/client.js +5 -6
  19. package/dist/client.js.map +1 -1
  20. package/dist/components.cjs +12 -4
  21. package/dist/components.cjs.map +1 -1
  22. package/dist/components.d.cts +3 -5
  23. package/dist/components.d.ts +3 -5
  24. package/dist/components.js +3 -8
  25. package/dist/components.js.map +1 -1
  26. package/dist/generators.cjs +13 -0
  27. package/dist/generators.cjs.map +1 -0
  28. package/dist/generators.d.cts +10 -0
  29. package/dist/generators.d.ts +10 -0
  30. package/dist/generators.js +4 -0
  31. package/dist/generators.js.map +1 -0
  32. package/dist/index.cjs +51 -104
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +3 -5
  35. package/dist/index.d.ts +3 -5
  36. package/dist/index.js +31 -91
  37. package/dist/index.js.map +1 -1
  38. package/dist/{types-xK4X9e5d.d.cts → types-DETYKDFZ.d.cts} +19 -108
  39. package/dist/{types-xK4X9e5d.d.ts → types-DETYKDFZ.d.ts} +19 -108
  40. package/package.json +22 -14
  41. package/src/components/Client.tsx +77 -198
  42. package/src/components/Operations.tsx +9 -75
  43. package/src/components/__snapshots__/Client/showPetById.ts +3 -6
  44. package/src/components/__snapshots__/Operations/showPetById.ts +5 -5
  45. package/src/generators/axiosGenerator.tsx +63 -0
  46. package/src/generators/index.ts +1 -0
  47. package/src/plugin.ts +21 -38
  48. package/src/types.ts +9 -3
  49. package/dist/chunk-W57BRY5O.js +0 -201
  50. package/dist/chunk-W57BRY5O.js.map +0 -1
  51. package/dist/chunk-W7F5CMU6.cjs +0 -201
  52. package/dist/chunk-W7F5CMU6.cjs.map +0 -1
  53. package/src/OperationGenerator.tsx +0 -65
@@ -1,83 +1,85 @@
1
1
  import { URLPath } from '@kubb/core/utils'
2
- import { Parser, File, Function, useApp } from '@kubb/react'
3
- import { pluginTsName } from '@kubb/plugin-ts'
4
- import { useOperation, useOperationManager } from '@kubb/plugin-oas/hooks'
5
- import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
2
 
7
- import { isOptional } from '@kubb/oas'
8
- import type { HttpMethod } from '@kubb/oas'
9
- import type { KubbNode, Params } from '@kubb/react'
10
- import type { ComponentProps, ComponentType } from 'react'
11
- import type { FileMeta, PluginClient } from '../types.ts'
3
+ import { type Operation, isOptional } from '@kubb/oas'
4
+ import type { OperationSchemas } from '@kubb/plugin-oas'
5
+ import { getComments, getPathParams } from '@kubb/plugin-oas/utils'
6
+ import { File, Function, createFunctionParams } from '@kubb/react'
7
+ import type { KubbNode, Params } from '@kubb/react/types'
8
+ import type { PluginClient } from '../types.ts'
12
9
 
13
- type TemplateProps = {
10
+ type Props = {
14
11
  /**
15
12
  * Name of the function
16
13
  */
17
14
  name: string
18
- /**
19
- * Parameters/options/props that need to be used
20
- */
21
- params: Params
22
- /**
23
- * Generics that needs to be added for TypeScript
24
- */
25
- generics?: string
26
- /**
27
- * ReturnType(see async for adding Promise type)
28
- */
29
- returnType?: string
30
- /**
31
- * Options for JSdocs
32
- */
33
- JSDoc?: {
34
- comments: string[]
35
- }
36
- client: {
37
- baseURL: string | undefined
38
- generics: string | string[]
39
- method: HttpMethod
40
- path: URLPath
41
- dataReturnType: PluginClient['options']['dataReturnType']
42
- withQueryParams: boolean
43
- withData: boolean
44
- withHeaders: boolean
45
- contentType: string
46
- }
15
+ options: PluginClient['resolvedOptions']
16
+ typedSchemas: OperationSchemas
17
+ operation: Operation
47
18
  }
48
19
 
49
- function Template({ name, generics, returnType, params, JSDoc, client }: TemplateProps): KubbNode {
50
- const isFormData = client.contentType === 'multipart/form-data'
20
+ export function Client({ name, options, typedSchemas, operation }: Props): KubbNode {
21
+ const contentType = operation.getContentType()
22
+ const baseURL = options.client.importPath === '@kubb/plugin-client/client' ? options.baseURL : undefined
23
+ const path = new URLPath(operation.path)
24
+ const isFormData = contentType === 'multipart/form-data'
51
25
  const headers = [
52
- client.contentType !== 'application/json' ? `'Content-Type': '${client.contentType}'` : undefined,
53
- client.withHeaders ? '...headers' : undefined,
54
- ]
55
- .filter(Boolean)
56
- .join(', ')
57
- const clientParams: Params = {
26
+ contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,
27
+ typedSchemas.headerParams?.name ? '...headers' : undefined,
28
+ ].filter(Boolean)
29
+
30
+ const params = createFunctionParams({
31
+ pathParams: {
32
+ mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',
33
+ children: getPathParams(typedSchemas.pathParams, { typed: true }),
34
+ },
35
+ data: typedSchemas.request?.name
36
+ ? {
37
+ type: typedSchemas.request?.name,
38
+ optional: isOptional(typedSchemas.request?.schema),
39
+ }
40
+ : undefined,
41
+ params: typedSchemas.queryParams?.name
42
+ ? {
43
+ type: typedSchemas.queryParams?.name,
44
+ optional: isOptional(typedSchemas.queryParams?.schema),
45
+ }
46
+ : undefined,
47
+ headers: typedSchemas.headerParams?.name
48
+ ? {
49
+ type: typedSchemas.headerParams?.name,
50
+ optional: isOptional(typedSchemas.headerParams?.schema),
51
+ }
52
+ : undefined,
53
+ options: {
54
+ type: 'Partial<Parameters<typeof client>[0]>',
55
+ default: '{}',
56
+ },
57
+ })
58
+
59
+ const clientParams = createFunctionParams({
58
60
  data: {
59
61
  mode: 'object',
60
62
  children: {
61
63
  method: {
62
64
  type: 'string',
63
- value: JSON.stringify(client.method),
65
+ value: JSON.stringify(operation.method),
64
66
  },
65
67
  url: {
66
68
  type: 'string',
67
- value: client.path.template,
69
+ value: path.template,
68
70
  },
69
- baseURL: client.baseURL
71
+ baseURL: baseURL
70
72
  ? {
71
73
  type: 'string',
72
- value: JSON.stringify(client.baseURL),
74
+ value: JSON.stringify(baseURL),
73
75
  }
74
76
  : undefined,
75
- params: client.withQueryParams
77
+ params: typedSchemas.queryParams?.name
76
78
  ? {
77
79
  type: 'any',
78
80
  }
79
81
  : undefined,
80
- data: client.withData
82
+ data: typedSchemas.request?.name
81
83
  ? {
82
84
  type: 'any',
83
85
  value: isFormData ? 'formData' : undefined,
@@ -86,7 +88,7 @@ function Template({ name, generics, returnType, params, JSDoc, client }: Templat
86
88
  headers: headers.length
87
89
  ? {
88
90
  type: 'any',
89
- value: headers.length ? `{ ${headers}, ...options.headers }` : undefined,
91
+ value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,
90
92
  }
91
93
  : undefined,
92
94
  options: {
@@ -95,7 +97,7 @@ function Template({ name, generics, returnType, params, JSDoc, client }: Templat
95
97
  },
96
98
  },
97
99
  },
98
- }
100
+ })
99
101
 
100
102
  const formData = isFormData
101
103
  ? `
@@ -112,149 +114,26 @@ function Template({ name, generics, returnType, params, JSDoc, client }: Templat
112
114
  : undefined
113
115
 
114
116
  return (
115
- <Function name={name} async export generics={generics} returnType={returnType} params={params} JSDoc={JSDoc}>
116
- {formData || ''}
117
- <Function.Call name="res" to={<Function name="client" async generics={client.generics} params={clientParams} />} />
118
- <Function.Return>{client.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>
119
- </Function>
120
- )
121
- }
122
-
123
- type RootTemplateProps = {
124
- children?: React.ReactNode
125
- }
126
-
127
- function RootTemplate({ children }: RootTemplateProps) {
128
- const {
129
- plugin: {
130
- options: {
131
- client: { importPath },
132
- extName,
133
- },
134
- },
135
- } = useApp<PluginClient>()
136
-
137
- const { getSchemas, getFile } = useOperationManager()
138
- const operation = useOperation()
139
-
140
- const file = getFile(operation)
141
- const fileType = getFile(operation, { pluginKey: [pluginTsName] })
142
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
143
-
144
- return (
145
- <Parser language="typescript">
146
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta}>
147
- <File.Import name={'client'} path={importPath} />
148
- <File.Import name={['ResponseConfig']} path={importPath} isTypeOnly />
149
- <File.Import
150
- extName={extName}
151
- name={[schemas.request?.name, schemas.response.name, schemas.pathParams?.name, schemas.queryParams?.name, schemas.headerParams?.name].filter(Boolean)}
152
- root={file.path}
153
- path={fileType.path}
154
- isTypeOnly
117
+ <File.Source name={name} isExportable isIndexable>
118
+ <Function
119
+ name={name}
120
+ async
121
+ export
122
+ returnType={
123
+ options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`
124
+ }
125
+ params={params}
126
+ JSDoc={{
127
+ comments: getComments(operation),
128
+ }}
129
+ >
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} />}
155
134
  />
156
- <File.Source>{children}</File.Source>
157
- </File>
158
- </Parser>
135
+ <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>
136
+ </Function>
137
+ </File.Source>
159
138
  )
160
139
  }
161
-
162
- const defaultTemplates = { default: Template, root: RootTemplate } as const
163
-
164
- type Templates = Partial<typeof defaultTemplates>
165
-
166
- type ClientProps = {
167
- baseURL: string | undefined
168
- /**
169
- * This will make it possible to override the default behaviour.
170
- */
171
- Template?: ComponentType<ComponentProps<typeof Template>>
172
- }
173
-
174
- export function Client({ baseURL, Template = defaultTemplates.default }: ClientProps): KubbNode {
175
- const {
176
- plugin: {
177
- options: { client, dataReturnType, pathParamsType },
178
- },
179
- } = useApp<PluginClient>()
180
-
181
- const { getSchemas, getName } = useOperationManager()
182
- const operation = useOperation()
183
-
184
- const contentType = operation.getContentType()
185
- const name = getName(operation, { type: 'function' })
186
- const schemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
187
-
188
- return (
189
- <Template
190
- name={name}
191
- params={{
192
- pathParams: {
193
- mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
194
- children: getPathParams(schemas.pathParams, { typed: true }),
195
- },
196
- data: schemas.request?.name
197
- ? {
198
- type: schemas.request?.name,
199
- optional: isOptional(schemas.request?.schema),
200
- }
201
- : undefined,
202
- params: schemas.queryParams?.name
203
- ? {
204
- type: schemas.queryParams?.name,
205
- optional: isOptional(schemas.queryParams?.schema),
206
- }
207
- : undefined,
208
- headers: schemas.headerParams?.name
209
- ? {
210
- type: schemas.headerParams?.name,
211
- optional: isOptional(schemas.headerParams?.schema),
212
- }
213
- : undefined,
214
- options: {
215
- type: 'Partial<Parameters<typeof client>[0]>',
216
- default: '{}',
217
- },
218
- }}
219
- returnType={dataReturnType === 'data' ? `ResponseConfig<${schemas.response.name}>["data"]` : `ResponseConfig<${schemas.response.name}>`}
220
- JSDoc={{
221
- comments: getComments(operation),
222
- }}
223
- client={{
224
- // only set baseURL from serverIndex(swagger) when no custom client(default) is used
225
- baseURL: client.importPath === '@kubb/plugin-client/client' ? baseURL : undefined,
226
- generics: [schemas.response.name, schemas.request?.name].filter(Boolean),
227
- dataReturnType,
228
- withQueryParams: !!schemas.queryParams?.name,
229
- withData: !!schemas.request?.name,
230
- withHeaders: !!schemas.headerParams?.name,
231
- method: operation.method,
232
- path: new URLPath(operation.path),
233
- contentType,
234
- }}
235
- />
236
- )
237
- }
238
-
239
- type FileProps = {
240
- baseURL: string | undefined
241
- /**
242
- * This will make it possible to override the default behaviour.
243
- */
244
- templates?: Templates
245
- }
246
-
247
- Client.File = function ({ baseURL, ...props }: FileProps): KubbNode {
248
- const templates = { ...defaultTemplates, ...props.templates }
249
-
250
- const Template = templates.default
251
- const RootTemplate = templates.root
252
-
253
- return (
254
- <RootTemplate>
255
- <Client baseURL={baseURL} Template={Template} />
256
- </RootTemplate>
257
- )
258
- }
259
-
260
- Client.templates = defaultTemplates
@@ -1,22 +1,14 @@
1
1
  import { URLPath } from '@kubb/core/utils'
2
- import { useOperations } from '@kubb/plugin-oas/hooks'
3
- import { Const, File, Parser, useApp } from '@kubb/react'
2
+ import { Const, File } from '@kubb/react'
4
3
 
5
4
  import type { HttpMethod, Operation } from '@kubb/oas'
6
- import type { KubbNode } from '@kubb/react'
7
- import type { ComponentProps, ComponentType } from 'react'
8
- import type { FileMeta, PluginClient } from '../types.ts'
9
5
 
10
- type TemplateProps = {
11
- /**
12
- * Name of the function
13
- */
6
+ type OperationsProps = {
14
7
  name: string
15
- operations: Operation[]
16
- baseURL: string | undefined
8
+ operations: Array<Operation>
17
9
  }
18
10
 
19
- function Template({ name, operations }: TemplateProps): KubbNode {
11
+ export function Operations({ name, operations }: OperationsProps) {
20
12
  const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}
21
13
 
22
14
  operations.forEach((operation) => {
@@ -25,70 +17,12 @@ function Template({ name, operations }: TemplateProps): KubbNode {
25
17
  method: operation.method,
26
18
  }
27
19
  })
28
- return (
29
- <Const name={name} export asConst>
30
- {JSON.stringify(operationsObject, undefined, 2)}
31
- </Const>
32
- )
33
- }
34
-
35
- type RootTemplateProps = {
36
- children?: React.ReactNode
37
- }
38
-
39
- function RootTemplate({ children }: RootTemplateProps) {
40
- const {
41
- pluginManager,
42
- plugin: { key: pluginKey },
43
- } = useApp<PluginClient>()
44
- const file = pluginManager.getFile({ name: 'operations', extName: '.ts', pluginKey })
45
-
46
- return (
47
- <Parser language="typescript">
48
- <File<FileMeta> baseName={file.baseName} path={file.path} meta={file.meta} exportable={false}>
49
- <File.Source>{children}</File.Source>
50
- </File>
51
- </Parser>
52
- )
53
- }
54
-
55
- const defaultTemplates = { default: Template, root: RootTemplate } as const
56
-
57
- type Templates = Partial<typeof defaultTemplates>
58
-
59
- type Props = {
60
- baseURL: string | undefined
61
- /**
62
- * This will make it possible to override the default behaviour.
63
- */
64
- Template?: ComponentType<ComponentProps<typeof Template>>
65
- }
66
-
67
- export function Operations({ baseURL, Template = defaultTemplates.default }: Props): KubbNode {
68
- const operations = useOperations()
69
-
70
- return <Template baseURL={baseURL} name="operations" operations={operations} />
71
- }
72
-
73
- type FileProps = {
74
- baseURL: string | undefined
75
- /**
76
- * This will make it possible to override the default behaviour.
77
- */
78
- templates?: Templates
79
- }
80
-
81
- Operations.File = function ({ baseURL, ...props }: FileProps): KubbNode {
82
- const templates = { ...defaultTemplates, ...props.templates }
83
-
84
- const Template = templates.default
85
- const RootTemplate = templates.root
86
20
 
87
21
  return (
88
- <RootTemplate>
89
- <Operations baseURL={baseURL} Template={Template} />
90
- </RootTemplate>
22
+ <File.Source name={name} isExportable isIndexable>
23
+ <Const name={name} export asConst>
24
+ {JSON.stringify(operationsObject, undefined, 2)}
25
+ </Const>
26
+ </File.Source>
91
27
  )
92
28
  }
93
-
94
- Operations.templates = defaultTemplates
@@ -2,10 +2,7 @@
2
2
  * @summary Info for a specific pet
3
3
  * @link /pets/:pet_id
4
4
  */
5
- export async function showPetById(
6
- { petId, testId }: { petId: ShowPetByIdPathParams['pet_id']; testId: ShowPetByIdPathParams['testId'] },
7
- options: Partial<Parameters<typeof client>[0]> = {},
8
- ): Promise<ResponseConfig<ShowPetByIdQueryResponse>['data']> {
9
- const res = await client<ShowPetByIdQueryResponse>({ method: 'get', url: `/pets/${petId}`, ...options })
5
+ export async function showPetById({ petId, testId }: { petId: ShowPetByIdPathParams["pet_id"]; testId: ShowPetByIdPathParams["testId"] }, options: Partial<Parameters<typeof client>[0]> = {}): Promise<ResponseConfig<ShowPetByIdQueryResponse>["data"]> {
6
+ const res = await client<ShowPetByIdQueryResponse>({ method : "get", url : `/pets/${petId}`, ... options })
10
7
  return res.data
11
- }
8
+ }
@@ -1,6 +1,6 @@
1
1
  export const operations = {
2
- showPetById: {
3
- path: '/pets/:pet_id',
4
- method: 'get',
5
- },
6
- } as const
2
+ "showPetById": {
3
+ "path": "/pets/:pet_id",
4
+ "method": "get"
5
+ }
6
+ } as const
@@ -0,0 +1,63 @@
1
+ import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { pluginTsName } from '@kubb/plugin-ts'
4
+ import { File, useApp } from '@kubb/react'
5
+ import { Client } from '../components/Client'
6
+ import { Operations } from '../components/Operations'
7
+ import type { PluginClient } from '../types'
8
+
9
+ export const axiosGenerator = createReactGenerator<PluginClient>({
10
+ name: 'plugin-client',
11
+ Operations({ options, operations }) {
12
+ const { pluginManager } = useApp<PluginClient>()
13
+
14
+ if (!options.templates.operations) {
15
+ return null
16
+ }
17
+
18
+ const Template = options.templates.operations || Operations
19
+ const name = 'operations'
20
+ const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })
21
+
22
+ return (
23
+ <File baseName={file.baseName} path={file.path} meta={file.meta}>
24
+ <Template name={name} operations={operations} />
25
+ </File>
26
+ )
27
+ },
28
+ Operation({ options, operation }) {
29
+ const { getSchemas, getName, getFile } = useOperationManager()
30
+
31
+ const name = getName(operation, { type: 'function' })
32
+ const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })
33
+ const file = getFile(operation)
34
+ const fileType = getFile(operation, { pluginKey: [pluginTsName] })
35
+
36
+ if (!options.templates.client) {
37
+ return null
38
+ }
39
+
40
+ const Template = options.templates.client || Client
41
+
42
+ return (
43
+ <File baseName={file.baseName} path={file.path} meta={file.meta}>
44
+ <File.Import name={'client'} path={options.client.importPath} />
45
+ <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />
46
+ <File.Import
47
+ extName={options.extName}
48
+ name={[
49
+ typedSchemas.request?.name,
50
+ typedSchemas.response.name,
51
+ typedSchemas.pathParams?.name,
52
+ typedSchemas.queryParams?.name,
53
+ typedSchemas.headerParams?.name,
54
+ ].filter(Boolean)}
55
+ root={file.path}
56
+ path={fileType.path}
57
+ isTypeOnly
58
+ />
59
+ <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />
60
+ </File>
61
+ )
62
+ },
63
+ })
@@ -0,0 +1 @@
1
+ export { axiosGenerator } from './axiosGenerator.tsx'
package/src/plugin.ts CHANGED
@@ -3,14 +3,13 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
7
- import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
8
7
 
9
- import { OperationGenerator } from './OperationGenerator.tsx'
10
8
  import { Client, Operations } from './components/index.ts'
11
9
 
12
10
  import type { Plugin } from '@kubb/core'
13
11
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
12
+ import { axiosGenerator } from './generators/axiosGenerator.tsx'
14
13
  import type { PluginClient } from './types.ts'
15
14
 
16
15
  export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
@@ -32,17 +31,22 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
32
31
 
33
32
  return {
34
33
  name: pluginClientName,
34
+ output: {
35
+ exportType: 'barrelNamed',
36
+ ...output,
37
+ },
35
38
  options: {
36
39
  extName: output.extName,
37
40
  dataReturnType,
38
41
  client: {
39
42
  importPath: '@kubb/plugin-client/client',
43
+ methods: ['get', 'post', 'delete', 'put'],
40
44
  ...options.client,
41
45
  },
42
46
  pathParamsType,
43
47
  templates: {
44
- operations: Operations.templates,
45
- client: Client.templates,
48
+ operations: Operations,
49
+ client: Client,
46
50
  ...templates,
47
51
  },
48
52
  baseURL: undefined,
@@ -77,20 +81,13 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
77
81
 
78
82
  return resolvedName
79
83
  },
80
- async writeFile(path, source) {
81
- if (!source) {
82
- return
83
- }
84
-
85
- return this.fileManager.write(path, source, { sanity: false })
86
- },
87
84
  async buildStart() {
88
85
  const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
89
86
 
90
- const oas = await swaggerPlugin.api.getOas()
87
+ const oas = await swaggerPlugin.context.getOas()
91
88
  const root = path.resolve(this.config.root, this.config.output.path)
92
89
  const mode = FileManager.getMode(path.resolve(root, output.path))
93
- const baseURL = await swaggerPlugin.api.getBaseURL()
90
+ const baseURL = await swaggerPlugin.context.getBaseURL()
94
91
 
95
92
  const operationGenerator = new OperationGenerator(
96
93
  {
@@ -101,7 +98,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
101
98
  oas,
102
99
  pluginManager: this.pluginManager,
103
100
  plugin: this.plugin,
104
- contentType: swaggerPlugin.api.contentType,
101
+ contentType: swaggerPlugin.context.contentType,
105
102
  exclude,
106
103
  include,
107
104
  override,
@@ -109,37 +106,23 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
109
106
  },
110
107
  )
111
108
 
112
- const files = await operationGenerator.build()
109
+ const files = await operationGenerator.build(axiosGenerator)
113
110
 
114
111
  await this.addFile(...files)
115
- },
116
- async buildEnd() {
117
- if (this.config.output.write === false) {
118
- return
119
- }
120
-
121
- const root = path.resolve(this.config.root, this.config.output.path)
122
112
 
123
- if (group?.type === 'tag') {
124
- const rootFiles = await getGroupedByTagFiles({
125
- logger: this.logger,
126
- files: this.fileManager.files,
127
- plugin: this.plugin,
128
- template,
129
- exportAs: group.exportAs || '{{tag}}Service',
113
+ if (this.config.output.exportType) {
114
+ const barrelFiles = await this.fileManager.getBarrelFiles({
130
115
  root,
131
116
  output,
117
+ files: this.fileManager.files,
118
+ meta: {
119
+ pluginKey: this.plugin.key,
120
+ },
121
+ logger: this.logger,
132
122
  })
133
123
 
134
- await this.addFile(...rootFiles)
124
+ await this.addFile(...barrelFiles)
135
125
  }
136
-
137
- await this.fileManager.addIndexes({
138
- root,
139
- output,
140
- meta: { pluginKey: this.plugin.key },
141
- logger: this.logger,
142
- })
143
126
  },
144
127
  }
145
128
  })
package/src/types.ts CHANGED
@@ -1,12 +1,13 @@
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'
4
5
  import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
6
  import type { Client, Operations } from './components/index.ts'
6
7
 
7
8
  type Templates = {
8
- operations?: typeof Operations.templates | false
9
- client?: typeof Client.templates | false
9
+ operations?: typeof Operations | false
10
+ client?: typeof Client | false
10
11
  }
11
12
 
12
13
  export type Options = {
@@ -26,7 +27,7 @@ export type Options = {
26
27
  extName?: KubbFile.Extname
27
28
  /**
28
29
  * Define what needs to exported, here you can also disable the export of barrel files
29
- * @default `'barrel'`
30
+ * @default `'barrelNamed'`
30
31
  */
31
32
  exportType?: 'barrel' | 'barrelNamed' | false
32
33
  }
@@ -73,6 +74,11 @@ export type Options = {
73
74
  * @default '@kubb/plugin-client/client'
74
75
  */
75
76
  importPath?: string
77
+ /**
78
+ * Define which HttpMethods can be used for queries
79
+ * @default ['get', 'post', 'put', 'delete']
80
+ */
81
+ methods?: Array<HttpMethod>
76
82
  }
77
83
  /**
78
84
  * ReturnType that needs to be used when calling client().