@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
package/dist/index.js CHANGED
@@ -1,108 +1,4 @@
1
- import './chunk-YJOVLRSC.js';
2
- import { axiosGenerator } from './chunk-IPKWNP7B.js';
3
- import { Operations, Client } from './chunk-YXOI7DUX.js';
4
- import path from 'node:path';
5
- import { createPlugin, FileManager, PluginManager } from '@kubb/core';
6
- import { camelCase } from '@kubb/core/transformers';
7
- import { renderTemplate } from '@kubb/core/utils';
8
- import { pluginOasName, OperationGenerator } from '@kubb/plugin-oas';
9
-
10
- var pluginClientName = "plugin-client";
11
- var pluginClient = createPlugin((options) => {
12
- const {
13
- output = { path: "clients" },
14
- group,
15
- exclude = [],
16
- include,
17
- override = [],
18
- transformers = {},
19
- dataReturnType = "data",
20
- pathParamsType = "inline",
21
- templates
22
- } = options;
23
- const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`;
24
- return {
25
- name: pluginClientName,
26
- output: {
27
- exportType: "barrelNamed",
28
- ...output
29
- },
30
- options: {
31
- extName: output.extName,
32
- dataReturnType,
33
- client: {
34
- importPath: "@kubb/plugin-client/client",
35
- methods: ["get", "post", "delete", "put"],
36
- ...options.client
37
- },
38
- pathParamsType,
39
- templates: {
40
- operations: Operations,
41
- client: Client,
42
- ...templates
43
- },
44
- baseURL: void 0
45
- },
46
- pre: [pluginOasName],
47
- resolvePath(baseName, pathMode, options2) {
48
- const root = path.resolve(this.config.root, this.config.output.path);
49
- const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
50
- if (mode === "single") {
51
- return path.resolve(root, output.path);
52
- }
53
- if (options2?.tag && group?.type === "tag") {
54
- const tag = camelCase(options2.tag);
55
- return path.resolve(root, renderTemplate(template, { tag }), baseName);
56
- }
57
- return path.resolve(root, output.path, baseName);
58
- },
59
- resolveName(name, type) {
60
- const resolvedName = camelCase(name, { isFile: type === "file" });
61
- if (type) {
62
- return transformers?.name?.(resolvedName, type) || resolvedName;
63
- }
64
- return resolvedName;
65
- },
66
- async buildStart() {
67
- const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
68
- const oas = await swaggerPlugin.context.getOas();
69
- const root = path.resolve(this.config.root, this.config.output.path);
70
- const mode = FileManager.getMode(path.resolve(root, output.path));
71
- const baseURL = await swaggerPlugin.context.getBaseURL();
72
- const operationGenerator = new OperationGenerator(
73
- {
74
- ...this.plugin.options,
75
- baseURL
76
- },
77
- {
78
- oas,
79
- pluginManager: this.pluginManager,
80
- plugin: this.plugin,
81
- contentType: swaggerPlugin.context.contentType,
82
- exclude,
83
- include,
84
- override,
85
- mode
86
- }
87
- );
88
- const files = await operationGenerator.build(axiosGenerator);
89
- await this.addFile(...files);
90
- if (this.config.output.exportType) {
91
- const barrelFiles = await this.fileManager.getBarrelFiles({
92
- root,
93
- output,
94
- files: this.fileManager.files,
95
- meta: {
96
- pluginKey: this.plugin.key
97
- },
98
- logger: this.logger
99
- });
100
- await this.addFile(...barrelFiles);
101
- }
102
- }
103
- };
104
- });
105
-
106
- export { pluginClient, pluginClientName };
1
+ export { pluginClient, pluginClientName } from './chunk-XB4BUZDK.js';
2
+ import './chunk-HGQQGWKN.js';
107
3
  //# sourceMappingURL=index.js.map
108
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAcO,IAAM,gBAAmB,GAAA,gBAAA;AAEnB,IAAA,YAAA,GAAe,YAA2B,CAAA,CAAC,OAAY,KAAA;AAClE,EAAM,MAAA;AAAA,IACJ,MAAA,GAAS,EAAE,IAAA,EAAM,SAAU,EAAA;AAAA,IAC3B,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,eAAe,EAAC;AAAA,IAChB,cAAiB,GAAA,MAAA;AAAA,IACjB,cAAiB,GAAA,QAAA;AAAA,IACjB,SAAA;AAAA,GACE,GAAA,OAAA,CAAA;AAEJ,EAAA,MAAM,WAAW,KAAO,EAAA,MAAA,GAAS,MAAM,MAAS,GAAA,CAAA,EAAG,OAAO,IAAI,CAAA,kBAAA,CAAA,CAAA;AAE9D,EAAO,OAAA;AAAA,IACL,IAAM,EAAA,gBAAA;AAAA,IACN,MAAQ,EAAA;AAAA,MACN,UAAY,EAAA,aAAA;AAAA,MACZ,GAAG,MAAA;AAAA,KACL;AAAA,IACA,OAAS,EAAA;AAAA,MACP,SAAS,MAAO,CAAA,OAAA;AAAA,MAChB,cAAA;AAAA,MACA,MAAQ,EAAA;AAAA,QACN,UAAY,EAAA,4BAAA;AAAA,QACZ,OAAS,EAAA,CAAC,KAAO,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CAAA;AAE3D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA,CAAA;AAE3B,MAAI,IAAA,IAAA,CAAK,MAAO,CAAA,MAAA,CAAO,UAAY,EAAA;AACjC,QAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,UACxD,IAAA;AAAA,UACA,MAAA;AAAA,UACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,UACxB,IAAM,EAAA;AAAA,YACJ,SAAA,EAAW,KAAK,MAAO,CAAA,GAAA;AAAA,WACzB;AAAA,UACA,QAAQ,IAAK,CAAA,MAAA;AAAA,SACd,CAAA,CAAA;AAED,QAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA,CAAA;AAAA,OACnC;AAAA,KACF;AAAA,GACF,CAAA;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase } from '@kubb/core/transformers'\nimport { renderTemplate } from '@kubb/core/utils'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { axiosGenerator } from './generators/axiosGenerator.tsx'\nimport type { PluginClient } from './types.ts'\n\nexport const pluginClientName = 'plugin-client' satisfies PluginClient['name']\n\nexport const pluginClient = createPlugin<PluginClient>((options) => {\n const {\n output = { path: 'clients' },\n group,\n exclude = [],\n include,\n override = [],\n transformers = {},\n dataReturnType = 'data',\n pathParamsType = 'inline',\n templates,\n } = options\n\n const template = group?.output ? group.output : `${output.path}/{{tag}}Controller`\n\n return {\n name: pluginClientName,\n output: {\n exportType: 'barrelNamed',\n ...output,\n },\n options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n methods: ['get', 'post', 'delete', 'put'],\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations,\n client: Client,\n ...templates,\n },\n baseURL: undefined,\n },\n pre: [pluginOasName],\n resolvePath(baseName, pathMode, options) {\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path))\n\n if (mode === 'single') {\n /**\n * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend\n * Other plugins then need to call addOrAppend instead of just add from the fileManager class\n */\n return path.resolve(root, output.path)\n }\n\n if (options?.tag && group?.type === 'tag') {\n const tag = camelCase(options.tag)\n\n return path.resolve(root, renderTemplate(template, { tag }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n const resolvedName = camelCase(name, { isFile: type === 'file' })\n\n if (type) {\n return transformers?.name?.(resolvedName, type) || resolvedName\n }\n\n return resolvedName\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.context.getOas()\n const root = path.resolve(this.config.root, this.config.output.path)\n const mode = FileManager.getMode(path.resolve(root, output.path))\n const baseURL = await swaggerPlugin.context.getBaseURL()\n\n const operationGenerator = new OperationGenerator(\n {\n ...this.plugin.options,\n baseURL,\n },\n {\n oas,\n pluginManager: this.pluginManager,\n plugin: this.plugin,\n contentType: swaggerPlugin.context.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build(axiosGenerator)\n\n await this.addFile(...files)\n\n if (this.config.output.exportType) {\n const barrelFiles = await this.fileManager.getBarrelFiles({\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n }\n },\n }\n})\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -1,30 +1,7 @@
1
1
  import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
2
  import * as KubbFile from '@kubb/fs/types';
3
- import { Operation, HttpMethod } from '@kubb/oas';
4
- import { OperationSchemas, ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
- import { KubbNode } from '@kubb/react/types';
3
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
6
4
 
7
- type Props = {
8
- /**
9
- * Name of the function
10
- */
11
- name: string;
12
- options: PluginClient['resolvedOptions'];
13
- typedSchemas: OperationSchemas;
14
- operation: Operation;
15
- };
16
- declare function Client({ name, options, typedSchemas, operation }: Props): KubbNode;
17
-
18
- type OperationsProps = {
19
- name: string;
20
- operations: Array<Operation>;
21
- };
22
- declare function Operations({ name, operations }: OperationsProps): JSX.Element;
23
-
24
- type Templates = {
25
- operations?: typeof Operations | false;
26
- client?: typeof Client | false;
27
- };
28
5
  type Options = {
29
6
  output?: {
30
7
  /**
@@ -80,21 +57,19 @@ type Options = {
80
57
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
81
58
  */
82
59
  override?: Array<Override<ResolvedOptions>>;
83
- client?: {
84
- /**
85
- * Path to the client import path that will be used to do the API calls.
86
- * It will be used as `import client from '${client.importPath}'`.
87
- * It allows both relative and absolute path.
88
- * the path will be applied as is, so relative path should be based on the file being generated.
89
- * @default '@kubb/plugin-client/client'
90
- */
91
- importPath?: string;
92
- /**
93
- * Define which HttpMethods can be used for queries
94
- * @default ['get', 'post', 'put', 'delete']
95
- */
96
- methods?: Array<HttpMethod>;
97
- };
60
+ /**
61
+ * Create `operations.ts` file with all operations grouped by methods.
62
+ * @default `false`
63
+ */
64
+ operations?: boolean;
65
+ /**
66
+ * Path to the client import path that will be used to do the API calls.
67
+ * It will be used as `import client from '${client.importPath}'`.
68
+ * It allows both relative and absolute path.
69
+ * the path will be applied as is, so relative path should be based on the file being generated.
70
+ * @default '@kubb/plugin-client/client'
71
+ */
72
+ importPath?: string;
98
73
  /**
99
74
  * ReturnType that needs to be used when calling client().
100
75
  *
@@ -115,25 +90,26 @@ type Options = {
115
90
  * @private
116
91
  */
117
92
  pathParamsType?: 'object' | 'inline';
93
+ /**
94
+ * Which parser can be used before returning the data
95
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
96
+ * @default 'client'
97
+ */
98
+ parser?: 'client' | 'zod';
118
99
  transformers?: {
119
100
  /**
120
101
  * Customize the names based on the type that is provided by the plugin.
121
102
  */
122
103
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
123
104
  };
124
- /**
125
- * Make it possible to override one of the templates
126
- */
127
- templates?: Partial<Templates>;
128
105
  };
129
106
  type ResolvedOptions = {
130
- extName: KubbFile.Extname | undefined;
131
107
  baseURL: string | undefined;
132
- client: Required<NonNullable<Options['client']>>;
108
+ parser: NonNullable<Options['parser']>;
109
+ importPath: NonNullable<Options['importPath']>;
133
110
  dataReturnType: NonNullable<Options['dataReturnType']>;
134
111
  pathParamsType: NonNullable<Options['pathParamsType']>;
135
- templates: NonNullable<Templates>;
136
112
  };
137
113
  type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
138
114
 
139
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
115
+ export type { Options as O, PluginClient as P };
@@ -1,30 +1,7 @@
1
1
  import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
2
2
  import * as KubbFile from '@kubb/fs/types';
3
- import { Operation, HttpMethod } from '@kubb/oas';
4
- import { OperationSchemas, ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
5
- import { KubbNode } from '@kubb/react/types';
3
+ import { ResolvePathOptions, Exclude, Include, Override } from '@kubb/plugin-oas';
6
4
 
7
- type Props = {
8
- /**
9
- * Name of the function
10
- */
11
- name: string;
12
- options: PluginClient['resolvedOptions'];
13
- typedSchemas: OperationSchemas;
14
- operation: Operation;
15
- };
16
- declare function Client({ name, options, typedSchemas, operation }: Props): KubbNode;
17
-
18
- type OperationsProps = {
19
- name: string;
20
- operations: Array<Operation>;
21
- };
22
- declare function Operations({ name, operations }: OperationsProps): JSX.Element;
23
-
24
- type Templates = {
25
- operations?: typeof Operations | false;
26
- client?: typeof Client | false;
27
- };
28
5
  type Options = {
29
6
  output?: {
30
7
  /**
@@ -80,21 +57,19 @@ type Options = {
80
57
  * Array containing override parameters to override `options` based on tags/operations/methods/paths.
81
58
  */
82
59
  override?: Array<Override<ResolvedOptions>>;
83
- client?: {
84
- /**
85
- * Path to the client import path that will be used to do the API calls.
86
- * It will be used as `import client from '${client.importPath}'`.
87
- * It allows both relative and absolute path.
88
- * the path will be applied as is, so relative path should be based on the file being generated.
89
- * @default '@kubb/plugin-client/client'
90
- */
91
- importPath?: string;
92
- /**
93
- * Define which HttpMethods can be used for queries
94
- * @default ['get', 'post', 'put', 'delete']
95
- */
96
- methods?: Array<HttpMethod>;
97
- };
60
+ /**
61
+ * Create `operations.ts` file with all operations grouped by methods.
62
+ * @default `false`
63
+ */
64
+ operations?: boolean;
65
+ /**
66
+ * Path to the client import path that will be used to do the API calls.
67
+ * It will be used as `import client from '${client.importPath}'`.
68
+ * It allows both relative and absolute path.
69
+ * the path will be applied as is, so relative path should be based on the file being generated.
70
+ * @default '@kubb/plugin-client/client'
71
+ */
72
+ importPath?: string;
98
73
  /**
99
74
  * ReturnType that needs to be used when calling client().
100
75
  *
@@ -115,25 +90,26 @@ type Options = {
115
90
  * @private
116
91
  */
117
92
  pathParamsType?: 'object' | 'inline';
93
+ /**
94
+ * Which parser can be used before returning the data
95
+ * `'zod'` will use `@kubb/plugin-zod` to parse the data.
96
+ * @default 'client'
97
+ */
98
+ parser?: 'client' | 'zod';
118
99
  transformers?: {
119
100
  /**
120
101
  * Customize the names based on the type that is provided by the plugin.
121
102
  */
122
103
  name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
123
104
  };
124
- /**
125
- * Make it possible to override one of the templates
126
- */
127
- templates?: Partial<Templates>;
128
105
  };
129
106
  type ResolvedOptions = {
130
- extName: KubbFile.Extname | undefined;
131
107
  baseURL: string | undefined;
132
- client: Required<NonNullable<Options['client']>>;
108
+ parser: NonNullable<Options['parser']>;
109
+ importPath: NonNullable<Options['importPath']>;
133
110
  dataReturnType: NonNullable<Options['dataReturnType']>;
134
111
  pathParamsType: NonNullable<Options['pathParamsType']>;
135
- templates: NonNullable<Templates>;
136
112
  };
137
113
  type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
138
114
 
139
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
115
+ export type { Options as O, PluginClient as P };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "3.0.0-alpha.14",
3
+ "version": "3.0.0-alpha.16",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -72,27 +72,28 @@
72
72
  "!/**/__tests__/**"
73
73
  ],
74
74
  "dependencies": {
75
- "@kubb/core": "3.0.0-alpha.14",
76
- "@kubb/fs": "3.0.0-alpha.14",
77
- "@kubb/oas": "3.0.0-alpha.14",
78
- "@kubb/parser-ts": "3.0.0-alpha.14",
79
- "@kubb/plugin-oas": "3.0.0-alpha.14",
80
- "@kubb/plugin-ts": "3.0.0-alpha.14",
81
- "@kubb/react": "3.0.0-alpha.14"
75
+ "@kubb/core": "3.0.0-alpha.16",
76
+ "@kubb/fs": "3.0.0-alpha.16",
77
+ "@kubb/oas": "3.0.0-alpha.16",
78
+ "@kubb/parser-ts": "3.0.0-alpha.16",
79
+ "@kubb/plugin-oas": "3.0.0-alpha.16",
80
+ "@kubb/plugin-ts": "3.0.0-alpha.16",
81
+ "@kubb/plugin-zod": "3.0.0-alpha.16",
82
+ "@kubb/react": "3.0.0-alpha.16"
82
83
  },
83
84
  "devDependencies": {
84
85
  "@types/react": "^18.3.5",
85
86
  "axios": "^1.7.7",
86
87
  "react": "^18.3.1",
87
88
  "tsup": "^8.2.4",
88
- "typescript": "^5.5.4",
89
- "@kubb/config-biome": "3.0.0-alpha.14",
90
- "@kubb/config-ts": "3.0.0-alpha.14",
91
- "@kubb/config-tsup": "3.0.0-alpha.14"
89
+ "typescript": "^5.6.2",
90
+ "@kubb/config-biome": "3.0.0-alpha.16",
91
+ "@kubb/config-ts": "3.0.0-alpha.16",
92
+ "@kubb/config-tsup": "3.0.0-alpha.16"
92
93
  },
93
94
  "peerDependencies": {
94
95
  "axios": "^1.7.2",
95
- "@kubb/react": "3.0.0-alpha.14"
96
+ "@kubb/react": "3.0.0-alpha.16"
96
97
  },
97
98
  "peerDependenciesMeta": {
98
99
  "axios": {
@@ -3,8 +3,8 @@ 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'
7
- import type { KubbNode, Params } from '@kubb/react/types'
6
+ import { File, Function, FunctionParams } from '@kubb/react'
7
+ import type { KubbNode } from '@kubb/react/types'
8
8
  import type { PluginClient } from '../types.ts'
9
9
 
10
10
  type Props = {
@@ -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
+ }