@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.
- package/client.ts +1 -1
- package/dist/chunk-44KNIIBT.cjs +178 -0
- package/dist/chunk-44KNIIBT.cjs.map +1 -0
- package/dist/chunk-HGQQGWKN.js +130 -0
- package/dist/chunk-HGQQGWKN.js.map +1 -0
- package/dist/chunk-NEK3OJBX.cjs +133 -0
- package/dist/chunk-NEK3OJBX.cjs.map +1 -0
- package/dist/chunk-XB4BUZDK.js +169 -0
- package/dist/chunk-XB4BUZDK.js.map +1 -0
- package/dist/client.cjs.map +1 -1
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/client.js.map +1 -1
- package/dist/components.cjs +3 -4
- package/dist/components.d.cts +37 -4
- package/dist/components.d.ts +37 -4
- package/dist/components.js +1 -2
- package/dist/generators.cjs +8 -4
- package/dist/generators.d.cts +5 -5
- package/dist/generators.d.ts +5 -5
- package/dist/generators.js +2 -2
- package/dist/index.cjs +9 -107
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -3
- package/dist/index.d.ts +1 -3
- package/dist/index.js +2 -106
- package/dist/index.js.map +1 -1
- package/dist/{types-DETYKDFZ.d.cts → types-j-ah_78Y.d.cts} +23 -47
- package/dist/{types-DETYKDFZ.d.ts → types-j-ah_78Y.d.ts} +23 -47
- package/package.json +14 -13
- package/src/components/Client.tsx +76 -56
- package/src/generators/__snapshots__/deletePet.ts +17 -0
- package/src/generators/__snapshots__/deletePetObject.ts +25 -0
- package/src/generators/__snapshots__/findByTags.ts +12 -0
- package/src/generators/__snapshots__/findByTagsFull.ts +12 -0
- package/src/generators/__snapshots__/findByTagsWithZod.ts +12 -0
- package/src/generators/__snapshots__/findByTagsWithZodFull.ts +12 -0
- package/src/generators/__snapshots__/importPath.ts +12 -0
- package/src/generators/__snapshots__/operations.ts +82 -0
- package/src/generators/__snapshots__/updatePetById.ts +15 -0
- package/src/generators/clientGenerator.tsx +65 -0
- package/src/generators/index.ts +2 -1
- package/src/generators/operationsGenerator.tsx +21 -0
- package/src/plugin.ts +10 -17
- package/src/types.ts +21 -29
- package/dist/chunk-AZDWYBLW.cjs +0 -4
- package/dist/chunk-AZDWYBLW.cjs.map +0 -1
- package/dist/chunk-IPKWNP7B.js +0 -56
- package/dist/chunk-IPKWNP7B.js.map +0 -1
- package/dist/chunk-JKG3C6DG.cjs +0 -58
- package/dist/chunk-JKG3C6DG.cjs.map +0 -1
- package/dist/chunk-KGGPZ6QL.cjs +0 -125
- package/dist/chunk-KGGPZ6QL.cjs.map +0 -1
- package/dist/chunk-YJOVLRSC.js +0 -3
- package/dist/chunk-YJOVLRSC.js.map +0 -1
- package/dist/chunk-YXOI7DUX.js +0 -122
- package/dist/chunk-YXOI7DUX.js.map +0 -1
- package/src/components/__snapshots__/Client/showPetById.ts +0 -8
- package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
- package/src/components/__snapshots__/Query/showPetById.ts +0 -15
- package/src/generators/axiosGenerator.tsx +0 -63
package/dist/index.js
CHANGED
|
@@ -1,108 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
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":[
|
|
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 {
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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 {
|
|
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 {
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
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 {
|
|
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.
|
|
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.
|
|
76
|
-
"@kubb/fs": "3.0.0-alpha.
|
|
77
|
-
"@kubb/oas": "3.0.0-alpha.
|
|
78
|
-
"@kubb/parser-ts": "3.0.0-alpha.
|
|
79
|
-
"@kubb/plugin-oas": "3.0.0-alpha.
|
|
80
|
-
"@kubb/plugin-ts": "3.0.0-alpha.
|
|
81
|
-
"@kubb/
|
|
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.
|
|
89
|
-
"@kubb/config-biome": "3.0.0-alpha.
|
|
90
|
-
"@kubb/config-ts": "3.0.0-alpha.
|
|
91
|
-
"@kubb/config-tsup": "3.0.0-alpha.
|
|
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.
|
|
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,
|
|
7
|
-
import type { KubbNode
|
|
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
|
-
|
|
16
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
32
|
+
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
33
|
+
return FunctionParams.factory({
|
|
31
34
|
pathParams: {
|
|
32
|
-
mode:
|
|
33
|
-
children: getPathParams(
|
|
35
|
+
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
36
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
34
37
|
},
|
|
35
|
-
data:
|
|
38
|
+
data: typeSchemas.request?.name
|
|
36
39
|
? {
|
|
37
|
-
type:
|
|
38
|
-
optional: isOptional(
|
|
40
|
+
type: typeSchemas.request?.name,
|
|
41
|
+
optional: isOptional(typeSchemas.request?.schema),
|
|
39
42
|
}
|
|
40
43
|
: undefined,
|
|
41
|
-
params:
|
|
44
|
+
params: typeSchemas.queryParams?.name
|
|
42
45
|
? {
|
|
43
|
-
type:
|
|
44
|
-
optional: isOptional(
|
|
46
|
+
type: typeSchemas.queryParams?.name,
|
|
47
|
+
optional: isOptional(typeSchemas.queryParams?.schema),
|
|
45
48
|
}
|
|
46
49
|
: undefined,
|
|
47
|
-
headers:
|
|
50
|
+
headers: typeSchemas.headerParams?.name
|
|
48
51
|
? {
|
|
49
|
-
type:
|
|
50
|
-
optional: isOptional(
|
|
52
|
+
type: typeSchemas.headerParams?.name,
|
|
53
|
+
optional: isOptional(typeSchemas.headerParams?.schema),
|
|
51
54
|
}
|
|
52
55
|
: undefined,
|
|
53
|
-
|
|
54
|
-
type: 'Partial<
|
|
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
|
|
60
|
-
|
|
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:
|
|
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
|
-
|
|
91
|
-
value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,
|
|
112
|
+
value: headers.length ? `{ ${headers.join(', ')}, ...config.headers }` : undefined,
|
|
92
113
|
}
|
|
93
114
|
: undefined,
|
|
94
|
-
|
|
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
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
+
}
|