@kubb/plugin-client 3.0.0-alpha.14 → 3.0.0-alpha.16

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 (61) hide show
  1. package/client.ts +1 -1
  2. package/dist/chunk-44KNIIBT.cjs +178 -0
  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-XB4BUZDK.js +169 -0
  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 -4
  15. package/dist/components.d.cts +37 -4
  16. package/dist/components.d.ts +37 -4
  17. package/dist/components.js +1 -2
  18. package/dist/generators.cjs +8 -4
  19. package/dist/generators.d.cts +5 -5
  20. package/dist/generators.d.ts +5 -5
  21. package/dist/generators.js +2 -2
  22. package/dist/index.cjs +9 -107
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +1 -3
  25. package/dist/index.d.ts +1 -3
  26. package/dist/index.js +2 -106
  27. package/dist/index.js.map +1 -1
  28. package/dist/{types-DETYKDFZ.d.cts → types-j-ah_78Y.d.cts} +23 -47
  29. package/dist/{types-DETYKDFZ.d.ts → types-j-ah_78Y.d.ts} +23 -47
  30. package/package.json +14 -13
  31. package/src/components/Client.tsx +76 -56
  32. package/src/generators/__snapshots__/deletePet.ts +17 -0
  33. package/src/generators/__snapshots__/deletePetObject.ts +25 -0
  34. package/src/generators/__snapshots__/findByTags.ts +12 -0
  35. package/src/generators/__snapshots__/findByTagsFull.ts +12 -0
  36. package/src/generators/__snapshots__/findByTagsWithZod.ts +12 -0
  37. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +12 -0
  38. package/src/generators/__snapshots__/importPath.ts +12 -0
  39. package/src/generators/__snapshots__/operations.ts +82 -0
  40. package/src/generators/__snapshots__/updatePetById.ts +15 -0
  41. package/src/generators/clientGenerator.tsx +65 -0
  42. package/src/generators/index.ts +2 -1
  43. package/src/generators/operationsGenerator.tsx +21 -0
  44. package/src/plugin.ts +10 -17
  45. package/src/types.ts +21 -29
  46. package/dist/chunk-AZDWYBLW.cjs +0 -4
  47. package/dist/chunk-AZDWYBLW.cjs.map +0 -1
  48. package/dist/chunk-IPKWNP7B.js +0 -56
  49. package/dist/chunk-IPKWNP7B.js.map +0 -1
  50. package/dist/chunk-JKG3C6DG.cjs +0 -58
  51. package/dist/chunk-JKG3C6DG.cjs.map +0 -1
  52. package/dist/chunk-KGGPZ6QL.cjs +0 -125
  53. package/dist/chunk-KGGPZ6QL.cjs.map +0 -1
  54. package/dist/chunk-YJOVLRSC.js +0 -3
  55. package/dist/chunk-YJOVLRSC.js.map +0 -1
  56. package/dist/chunk-YXOI7DUX.js +0 -122
  57. package/dist/chunk-YXOI7DUX.js.map +0 -1
  58. package/src/components/__snapshots__/Client/showPetById.ts +0 -8
  59. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  60. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
  61. package/src/generators/axiosGenerator.tsx +0 -63
@@ -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
+ }
@@ -0,0 +1,65 @@
1
+ import { createReactGenerator } from '@kubb/plugin-oas'
2
+ import { useOperationManager } from '@kubb/plugin-oas/hooks'
3
+ import { pluginTsName } from '@kubb/plugin-ts'
4
+ import { pluginZodName } from '@kubb/plugin-zod'
5
+ import { File, useApp } from '@kubb/react'
6
+ import { Client } from '../components/Client'
7
+ import type { PluginClient } from '../types'
8
+
9
+ export const clientGenerator = createReactGenerator<PluginClient>({
10
+ name: 'client',
11
+ Operation({ options, operation }) {
12
+ const {
13
+ plugin: { output },
14
+ } = useApp<PluginClient>()
15
+ const { getSchemas, getName, getFile } = useOperationManager()
16
+
17
+ const client = {
18
+ name: getName(operation, { type: 'function' }),
19
+ file: getFile(operation),
20
+ }
21
+
22
+ const type = {
23
+ file: getFile(operation, { pluginKey: [pluginTsName] }),
24
+ schemas: getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' }),
25
+ }
26
+
27
+ const zod = {
28
+ file: getFile(operation, { pluginKey: [pluginZodName] }),
29
+ schemas: getSchemas(operation, { pluginKey: [pluginZodName], type: 'function' }),
30
+ }
31
+
32
+ return (
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} />}
37
+ <File.Import
38
+ extName={output?.extName}
39
+ 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) || []),
46
+ ].filter(Boolean)}
47
+ root={client.file.path}
48
+ path={type.file.path}
49
+ isTypeOnly
50
+ />
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
+ />
62
+ </File>
63
+ )
64
+ },
65
+ })
@@ -1 +1,2 @@
1
- export { axiosGenerator } from './axiosGenerator.tsx'
1
+ export { clientGenerator } from './clientGenerator.tsx'
2
+ export { operationsGenerator } from './operationsGenerator.tsx'
@@ -0,0 +1,21 @@
1
+ import { pluginClientName } from '@kubb/plugin-client'
2
+ import { createReactGenerator } from '@kubb/plugin-oas'
3
+ import { File, useApp } from '@kubb/react'
4
+ import { Operations } from '../components/Operations'
5
+ import type { PluginClient } from '../types'
6
+
7
+ export const operationsGenerator = createReactGenerator<PluginClient>({
8
+ name: 'client',
9
+ Operations({ operations }) {
10
+ const { pluginManager } = useApp<PluginClient>()
11
+
12
+ const name = 'operations'
13
+ const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: [pluginClientName] })
14
+
15
+ return (
16
+ <File baseName={file.baseName} path={file.path} meta={file.meta}>
17
+ <Operations name={name} operations={operations} />
18
+ </File>
19
+ )
20
+ },
21
+ })
package/src/plugin.ts CHANGED
@@ -5,11 +5,11 @@ 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, Operations } from './components/index.ts'
9
-
10
8
  import type { Plugin } from '@kubb/core'
11
9
  import type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'
12
- import { axiosGenerator } from './generators/axiosGenerator.tsx'
10
+ import { pluginZodName } from '@kubb/plugin-zod'
11
+ import { operationsGenerator } from './generators'
12
+ import { clientGenerator } from './generators/clientGenerator.tsx'
13
13
  import type { PluginClient } from './types.ts'
14
14
 
15
15
  export const pluginClientName = 'plugin-client' satisfies PluginClient['name']
@@ -24,7 +24,9 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
24
24
  transformers = {},
25
25
  dataReturnType = 'data',
26
26
  pathParamsType = 'inline',
27
- templates,
27
+ operations = false,
28
+ importPath = '@kubb/plugin-client/client',
29
+ parser = 'client',
28
30
  } = options
29
31
 
30
32
  const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`
@@ -36,22 +38,13 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
36
38
  ...output,
37
39
  },
38
40
  options: {
39
- extName: output.extName,
41
+ parser,
40
42
  dataReturnType,
41
- client: {
42
- importPath: '@kubb/plugin-client/client',
43
- methods: ['get', 'post', 'delete', 'put'],
44
- ...options.client,
45
- },
43
+ importPath,
46
44
  pathParamsType,
47
- templates: {
48
- operations: Operations,
49
- client: Client,
50
- ...templates,
51
- },
52
45
  baseURL: undefined,
53
46
  },
54
- pre: [pluginOasName],
47
+ pre: [pluginOasName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),
55
48
  resolvePath(baseName, pathMode, options) {
56
49
  const root = path.resolve(this.config.root, this.config.output.path)
57
50
  const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))
@@ -106,7 +99,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
106
99
  },
107
100
  )
108
101
 
109
- const files = await operationGenerator.build(axiosGenerator)
102
+ const files = await operationGenerator.build(...[clientGenerator, operations ? operationsGenerator : undefined].filter(Boolean))
110
103
 
111
104
  await this.addFile(...files)
112
105
 
package/src/types.ts CHANGED
@@ -1,14 +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, Operations } from './components/index.ts'
7
-
8
- type Templates = {
9
- operations?: typeof Operations | false
10
- client?: typeof Client | false
11
- }
12
5
 
13
6
  export type Options = {
14
7
  output?: {
@@ -65,21 +58,19 @@ export type Options = {
65
58
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
66
59
  */
67
60
  override?: Array<Override<ResolvedOptions>>
68
- client?: {
69
- /**
70
- * Path to the client import path that will be used to do the API calls.
71
- * It will be used as `import client from '${client.importPath}'`.
72
- * It allows both relative and absolute path.
73
- * the path will be applied as is, so relative path should be based on the file being generated.
74
- * @default '@kubb/plugin-client/client'
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>
82
- }
61
+ /**
62
+ * Create `operations.ts` file with all operations grouped by methods.
63
+ * @default `false`
64
+ */
65
+ operations?: boolean
66
+ /**
67
+ * Path to the client import path that will be used to do the API calls.
68
+ * It will be used as `import client from '${client.importPath}'`.
69
+ * It allows both relative and absolute path.
70
+ * the path will be applied as is, so relative path should be based on the file being generated.
71
+ * @default '@kubb/plugin-client/client'
72
+ */
73
+ importPath?: string
83
74
  /**
84
75
  * ReturnType that needs to be used when calling client().
85
76
  *
@@ -100,25 +91,26 @@ export type Options = {
100
91
  * @private
101
92
  */
102
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'
103
100
  transformers?: {
104
101
  /**
105
102
  * Customize the names based on the type that is provided by the plugin.
106
103
  */
107
104
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string
108
105
  }
109
- /**
110
- * Make it possible to override one of the templates
111
- */
112
- templates?: Partial<Templates>
113
106
  }
114
107
 
115
108
  type ResolvedOptions = {
116
- extName: KubbFile.Extname | undefined
117
109
  baseURL: string | undefined
118
- client: Required<NonNullable<Options['client']>>
110
+ parser: NonNullable<Options['parser']>
111
+ importPath: NonNullable<Options['importPath']>
119
112
  dataReturnType: NonNullable<Options['dataReturnType']>
120
113
  pathParamsType: NonNullable<Options['pathParamsType']>
121
- templates: NonNullable<Templates>
122
114
  }
123
115
 
124
116
  export type FileMeta = {
@@ -1,4 +0,0 @@
1
- 'use strict';
2
-
3
- //# sourceMappingURL=chunk-AZDWYBLW.cjs.map
4
- //# sourceMappingURL=chunk-AZDWYBLW.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"chunk-AZDWYBLW.cjs"}
@@ -1,56 +0,0 @@
1
- import { Operations, Client } from './chunk-YXOI7DUX.js';
2
- import { createReactGenerator } from '@kubb/plugin-oas';
3
- import { useOperationManager } from '@kubb/plugin-oas/hooks';
4
- import { pluginTsName } from '@kubb/plugin-ts';
5
- import { useApp, File } from '@kubb/react';
6
- import { jsx, jsxs } from '@kubb/react/jsx-runtime';
7
-
8
- var axiosGenerator = createReactGenerator({
9
- name: "plugin-client",
10
- Operations({ options, operations }) {
11
- const { pluginManager } = useApp();
12
- if (!options.templates.operations) {
13
- return null;
14
- }
15
- const Template = options.templates.operations || Operations;
16
- const name = "operations";
17
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: ["plugin-client"] });
18
- return /* @__PURE__ */ jsx(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsx(Template, { name, operations }) });
19
- },
20
- Operation({ options, operation }) {
21
- const { getSchemas, getName, getFile } = useOperationManager();
22
- const name = getName(operation, { type: "function" });
23
- const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: "type" });
24
- const file = getFile(operation);
25
- const fileType = getFile(operation, { pluginKey: [pluginTsName] });
26
- if (!options.templates.client) {
27
- return null;
28
- }
29
- const Template = options.templates.client || Client;
30
- return /* @__PURE__ */ jsxs(File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
31
- /* @__PURE__ */ jsx(File.Import, { name: "client", path: options.client.importPath }),
32
- /* @__PURE__ */ jsx(File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
33
- /* @__PURE__ */ jsx(
34
- File.Import,
35
- {
36
- extName: options.extName,
37
- name: [
38
- typedSchemas.request?.name,
39
- typedSchemas.response.name,
40
- typedSchemas.pathParams?.name,
41
- typedSchemas.queryParams?.name,
42
- typedSchemas.headerParams?.name
43
- ].filter(Boolean),
44
- root: file.path,
45
- path: fileType.path,
46
- isTypeOnly: true
47
- }
48
- ),
49
- /* @__PURE__ */ jsx(Template, { name, options, typedSchemas, operation })
50
- ] });
51
- }
52
- });
53
-
54
- export { axiosGenerator };
55
- //# sourceMappingUR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ACX,MAAM,QAAS,CAAA,IAAA;AAAA,UACf,UAAU,EAAA,IAAA;AAAA,SAAA;AAAA,OACZ;AAAA,sBACC,GAAA,CAAA,QAAA,EAAA,EAAS,IAAY,EAAA,OAAA,EAAkB,cAA4B,SAAsB,EAAA,CAAA;AAAA,KAC5F,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-IPKWNP7B.js","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const axiosGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operations({ options, operations }) {\n const { pluginManager } = useApp<PluginClient>()\n\n if (!options.templates.operations) {\n return null\n }\n\n const Template = options.templates.operations || Operations\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <Template name={name} operations={operations} />\n </File>\n )\n },\n Operation({ options, operation }) {\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.templates.client) {\n return null\n }\n\n const Template = options.templates.client || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n extName={options.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n"]}
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkKGGPZ6QL_cjs = require('./chunk-KGGPZ6QL.cjs');
4
- var pluginOas = require('@kubb/plugin-oas');
5
- var hooks = require('@kubb/plugin-oas/hooks');
6
- var pluginTs = require('@kubb/plugin-ts');
7
- var react = require('@kubb/react');
8
- var jsxRuntime = require('@kubb/react/jsx-runtime');
9
-
10
- var axiosGenerator = pluginOas.createReactGenerator({
11
- name: "plugin-client",
12
- Operations({ options, operations }) {
13
- const { pluginManager } = react.useApp();
14
- if (!options.templates.operations) {
15
- return null;
16
- }
17
- const Template = options.templates.operations || chunkKGGPZ6QL_cjs.Operations;
18
- const name = "operations";
19
- const file = pluginManager.getFile({ name, extName: ".ts", pluginKey: ["plugin-client"] });
20
- return /* @__PURE__ */ jsxRuntime.jsx(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: /* @__PURE__ */ jsxRuntime.jsx(Template, { name, operations }) });
21
- },
22
- Operation({ options, operation }) {
23
- const { getSchemas, getName, getFile } = hooks.useOperationManager();
24
- const name = getName(operation, { type: "function" });
25
- const typedSchemas = getSchemas(operation, { pluginKey: [pluginTs.pluginTsName], type: "type" });
26
- const file = getFile(operation);
27
- const fileType = getFile(operation, { pluginKey: [pluginTs.pluginTsName] });
28
- if (!options.templates.client) {
29
- return null;
30
- }
31
- const Template = options.templates.client || chunkKGGPZ6QL_cjs.Client;
32
- return /* @__PURE__ */ jsxRuntime.jsxs(react.File, { baseName: file.baseName, path: file.path, meta: file.meta, children: [
33
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: "client", path: options.client.importPath }),
34
- /* @__PURE__ */ jsxRuntime.jsx(react.File.Import, { name: ["ResponseConfig"], path: options.client.importPath, isTypeOnly: true }),
35
- /* @__PURE__ */ jsxRuntime.jsx(
36
- react.File.Import,
37
- {
38
- extName: options.extName,
39
- name: [
40
- typedSchemas.request?.name,
41
- typedSchemas.response.name,
42
- typedSchemas.pathParams?.name,
43
- typedSchemas.queryParams?.name,
44
- typedSchemas.headerParams?.name
45
- ].filter(Boolean),
46
- root: file.path,
47
- path: fileType.path,
48
- isTypeOnly: true
49
- }
50
- ),
51
- /* @__PURE__ */ jsxRuntime.jsx(Template, { name, options, typedSchemas, operation })
52
- ] });
53
- }
54
- });
55
-
56
- exports.axiosGenerator = axiosGenerator;
57
- //# sourceMappingURL=chunk-JKG3C6DG.cjs.map
58
- //# sourceMappingURL=chunk-JKG3C6DG.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/generators/axiosGenerator.tsx"],"names":["createReactGenerator","useApp","Operations","jsx","File","useOperationManager","pluginTsName","Client","jsxs"],"mappings":";;;;;;;;;AAQO,IAAM,iBAAiBA,8BAAmC,CAAA;AAAA,EAC/D,IAAM,EAAA,eAAA;AAAA,EACN,UAAW,CAAA,EAAE,OAAS,EAAA,UAAA,EAAc,EAAA;AAClC,IAAM,MAAA,EAAE,aAAc,EAAA,GAAIC,YAAqB,EAAA,CAAA;AAE/C,IAAI,IAAA,CAAC,OAAQ,CAAA,SAAA,CAAU,UAAY,EAAA;AACjC,MAAO,OAAA,IAAA,CAAA;AAAA,KACT;AAEA,IAAM,MAAA,QAAA,GAAW,OAAQ,CAAA,SAAA,CAAU,UAAc,IAAAC,4BAAA,CAAA;AACjD,IAAA,MAAM,IAAO,GAAA,YAAA,CAAA;AACb,IAAM,MAAA,IAAA,GAAO,aAAc,CAAA,OAAA,CAAQ,EAAE,IAAA,EAAM,OAAS,EAAA,KAAA,EAAO,SAAW,EAAA,CAAC,eAAe,CAAA,EAAG,CAAA,CAAA;AAEzF,IAAA,uBACGC,cAAA,CAAAC,UAAA,EAAA,EAAK,QAAU,EAAA,IAAA,CAAK,UAAU,IAAM,EAAA,IAAA,CAAK,IAAM,EAAA,IAAA,EAAM,KAAK,IACzD,EAAA,QAAA,kBAAAD,cAAA,CAAC,QAAS,EA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D,cAAA;AAAA,QAACC,UAAK,CAAA,MAAA;AAAA,QAAL;AAAA,UACC,SAAS,OAAQ,CAAA,OAAA;AAAA,UACjB,IAAM,EAAA;AAAA,YACJ,aAAa,OAAS,EAAA,IAAA;AAAA,YACtB,aAAa,QAAS,CAAA,IAAA;AAAA,YACtB,aAAa,UAAY,EAAA,IAAA;AAAA,YACzB,aAAa,WAAa,EAAA,IAAA;AAAA,YAC1B,aAAa,YAAc,EAAA,IAAA;AAAA,WAC7B,CAAE,OAAO,OAAO,CAAA;AAAA,UAChB,MAAM,IAAK,CAAA,IAAA;AAAA,UACX,MAAM,QAAS,CAAA,IAAA;AAAA,UACf,UAAU,EAAA,IAAA;AAAA,SAAA;AAAA,OACZ;AAAA,sBACCD,cAAA,CAAA,QAAA,EAAA,EAAS,IAAY,EAAA,OAAA,EAAkB,cAA4B,SAAsB,EAAA,CAAA;AAAA,KAC5F,EAAA,CAAA,CAAA;AAAA,GAEJ;AACF,CAAC","file":"chunk-JKG3C6DG.cjs","sourcesContent":["import { createReactGenerator } from '@kubb/plugin-oas'\nimport { useOperationManager } from '@kubb/plugin-oas/hooks'\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { File, useApp } from '@kubb/react'\nimport { Client } from '../components/Client'\nimport { Operations } from '../components/Operations'\nimport type { PluginClient } from '../types'\n\nexport const axiosGenerator = createReactGenerator<PluginClient>({\n name: 'plugin-client',\n Operations({ options, operations }) {\n const { pluginManager } = useApp<PluginClient>()\n\n if (!options.templates.operations) {\n return null\n }\n\n const Template = options.templates.operations || Operations\n const name = 'operations'\n const file = pluginManager.getFile({ name, extName: '.ts', pluginKey: ['plugin-client'] })\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <Template name={name} operations={operations} />\n </File>\n )\n },\n Operation({ options, operation }) {\n const { getSchemas, getName, getFile } = useOperationManager()\n\n const name = getName(operation, { type: 'function' })\n const typedSchemas = getSchemas(operation, { pluginKey: [pluginTsName], type: 'type' })\n const file = getFile(operation)\n const fileType = getFile(operation, { pluginKey: [pluginTsName] })\n\n if (!options.templates.client) {\n return null\n }\n\n const Template = options.templates.client || Client\n\n return (\n <File baseName={file.baseName} path={file.path} meta={file.meta}>\n <File.Import name={'client'} path={options.client.importPath} />\n <File.Import name={['ResponseConfig']} path={options.client.importPath} isTypeOnly />\n <File.Import\n extName={options.extName}\n name={[\n typedSchemas.request?.name,\n typedSchemas.response.name,\n typedSchemas.pathParams?.name,\n typedSchemas.queryParams?.name,\n typedSchemas.headerParams?.name,\n ].filter(Boolean)}\n root={file.path}\n path={fileType.path}\n isTypeOnly\n />\n <Template name={name} options={options} typedSchemas={typedSchemas} operation={operation} />\n </File>\n )\n },\n})\n"]}
@@ -1,125 +0,0 @@
1
- 'use strict';
2
-
3
- var utils = require('@kubb/core/utils');
4
- var oas = require('@kubb/oas');
5
- var utils$1 = require('@kubb/plugin-oas/utils');
6
- var react = require('@kubb/react');
7
- var jsxRuntime = require('@kubb/react/jsx-runtime');
8
-
9
- // src/components/Client.tsx
10
- function Client({ name, options, typedSchemas, operation }) {
11
- const contentType = operation.getContentType();
12
- const baseURL = options.baseURL;
13
- const path = new utils.URLPath(operation.path);
14
- const isFormData = contentType === "multipart/form-data";
15
- const headers = [
16
- contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0,
17
- typedSchemas.headerParams?.name ? "...headers" : void 0
18
- ].filter(Boolean);
19
- const params = react.createFunctionParams({
20
- pathParams: {
21
- mode: options.pathParamsType === "object" ? "object" : "inlineSpread",
22
- children: utils$1.getPathParams(typedSchemas.pathParams, { typed: true })
23
- },
24
- data: typedSchemas.request?.name ? {
25
- type: typedSchemas.request?.name,
26
- optional: oas.isOptional(typedSchemas.request?.schema)
27
- } : void 0,
28
- params: typedSchemas.queryParams?.name ? {
29
- type: typedSchemas.queryParams?.name,
30
- optional: oas.isOptional(typedSchemas.queryParams?.schema)
31
- } : void 0,
32
- headers: typedSchemas.headerParams?.name ? {
33
- type: typedSchemas.headerParams?.name,
34
- optional: oas.isOptional(typedSchemas.headerParams?.schema)
35
- } : void 0,
36
- options: {
37
- type: "Partial<Parameters<typeof client>[0]>",
38
- default: "{}"
39
- }
40
- });
41
- const clientParams = react.createFunctionParams({
42
- data: {
43
- mode: "object",
44
- children: {
45
- method: {
46
- type: "string",
47
- value: JSON.stringify(operation.method)
48
- },
49
- url: {
50
- type: "string",
51
- value: path.template
52
- },
53
- baseURL: baseURL ? {
54
- type: "string",
55
- value: JSON.stringify(baseURL)
56
- } : void 0,
57
- params: typedSchemas.queryParams?.name ? {
58
- type: "any"
59
- } : void 0,
60
- data: typedSchemas.request?.name ? {
61
- type: "any",
62
- value: isFormData ? "formData" : void 0
63
- } : void 0,
64
- headers: headers.length ? {
65
- type: "any",
66
- value: headers.length ? `{ ${headers.join(", ")}, ...options.headers }` : void 0
67
- } : void 0,
68
- options: {
69
- type: "any",
70
- mode: "inlineSpread"
71
- }
72
- }
73
- }
74
- });
75
- const formData = isFormData ? `
76
- const formData = new FormData()
77
- if(data) {
78
- Object.keys(data).forEach((key) => {
79
- const value = data[key];
80
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
81
- formData.append(key, value);
82
- }
83
- })
84
- }
85
- ` : void 0;
86
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsxs(
87
- react.Function,
88
- {
89
- name,
90
- async: true,
91
- export: true,
92
- returnType: options.dataReturnType === "data" ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`,
93
- params,
94
- JSDoc: {
95
- comments: utils$1.getComments(operation)
96
- },
97
- children: [
98
- formData || "",
99
- /* @__PURE__ */ jsxRuntime.jsx(
100
- react.Function.Call,
101
- {
102
- name: "res",
103
- to: /* @__PURE__ */ jsxRuntime.jsx(react.Function, { name: "client", async: true, generics: [typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean), params: clientParams })
104
- }
105
- ),
106
- /* @__PURE__ */ jsxRuntime.jsx(react.Function.Return, { children: options.dataReturnType === "data" ? "res.data" : "res" })
107
- ]
108
- }
109
- ) });
110
- }
111
- function Operations({ name, operations }) {
112
- const operationsObject = {};
113
- operations.forEach((operation) => {
114
- operationsObject[operation.getOperationId()] = {
115
- path: new utils.URLPath(operation.path).URL,
116
- method: operation.method
117
- };
118
- });
119
- return /* @__PURE__ */ jsxRuntime.jsx(react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ jsxRuntime.jsx(react.Const, { name, export: true, asConst: true, children: JSON.stringify(operationsObject, void 0, 2) }) });
120
- }
121
-
122
- exports.Client = Client;
123
- exports.Operations = Operations;
124
- //# sourceMappingURL=chunk-KGGPZ6QL.cjs.map
125
- //# sourceMappingURL=chunk-KGGPZ6QL.cjs.map