@kubb/plugin-client 3.0.0-alpha.9 → 3.0.0-beta.2

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 (71) hide show
  1. package/README.md +14 -5
  2. package/client.ts +2 -2
  3. package/dist/chunk-6W3SC7JK.cjs +228 -0
  4. package/dist/chunk-6W3SC7JK.cjs.map +1 -0
  5. package/dist/chunk-LI44LDXH.js +218 -0
  6. package/dist/chunk-LI44LDXH.js.map +1 -0
  7. package/dist/chunk-X73EA6RA.cjs +133 -0
  8. package/dist/chunk-X73EA6RA.cjs.map +1 -0
  9. package/dist/chunk-YYBNZBCI.js +130 -0
  10. package/dist/chunk-YYBNZBCI.js.map +1 -0
  11. package/dist/client.cjs +16 -7
  12. package/dist/client.cjs.map +1 -1
  13. package/dist/client.d.cts +2 -2
  14. package/dist/client.d.ts +2 -2
  15. package/dist/client.js +5 -6
  16. package/dist/client.js.map +1 -1
  17. package/dist/components.cjs +11 -5
  18. package/dist/components.cjs.map +1 -1
  19. package/dist/components.d.cts +37 -5
  20. package/dist/components.d.ts +37 -5
  21. package/dist/components.js +2 -9
  22. package/dist/components.js.map +1 -1
  23. package/dist/generators.cjs +17 -4
  24. package/dist/generators.cjs.map +1 -1
  25. package/dist/generators.d.cts +7 -6
  26. package/dist/generators.d.ts +7 -6
  27. package/dist/generators.js +3 -7
  28. package/dist/generators.js.map +1 -1
  29. package/dist/index.cjs +11 -109
  30. package/dist/index.cjs.map +1 -1
  31. package/dist/index.d.cts +1 -4
  32. package/dist/index.d.ts +1 -4
  33. package/dist/index.js +3 -114
  34. package/dist/index.js.map +1 -1
  35. package/dist/types-Bk_NZurp.d.cts +86 -0
  36. package/dist/types-Bk_NZurp.d.ts +86 -0
  37. package/package.json +14 -17
  38. package/src/components/Client.tsx +78 -58
  39. package/src/generators/__snapshots__/deletePet.ts +13 -0
  40. package/src/generators/__snapshots__/deletePetObject.ts +15 -0
  41. package/src/generators/__snapshots__/findByTags.ts +13 -0
  42. package/src/generators/__snapshots__/findByTagsFull.ts +13 -0
  43. package/src/generators/__snapshots__/findByTagsWithZod.ts +13 -0
  44. package/src/generators/__snapshots__/findByTagsWithZodFull.ts +13 -0
  45. package/src/generators/__snapshots__/importPath.ts +13 -0
  46. package/src/generators/__snapshots__/operations.ts +82 -0
  47. package/src/generators/__snapshots__/updatePetById.ts +12 -0
  48. package/src/generators/clientGenerator.tsx +66 -0
  49. package/src/generators/groupedClientGenerator.tsx +70 -0
  50. package/src/generators/index.ts +3 -1
  51. package/src/generators/operationsGenerator.tsx +26 -0
  52. package/src/plugin.ts +34 -45
  53. package/src/types.ts +33 -75
  54. package/dist/chunk-AZDWYBLW.cjs +0 -1
  55. package/dist/chunk-AZDWYBLW.cjs.map +0 -1
  56. package/dist/chunk-GHHJWXKQ.cjs +0 -61
  57. package/dist/chunk-GHHJWXKQ.cjs.map +0 -1
  58. package/dist/chunk-OODSLPAP.js +0 -61
  59. package/dist/chunk-OODSLPAP.js.map +0 -1
  60. package/dist/chunk-W256NILH.js +0 -128
  61. package/dist/chunk-W256NILH.js.map +0 -1
  62. package/dist/chunk-YGRM4AA5.cjs +0 -128
  63. package/dist/chunk-YGRM4AA5.cjs.map +0 -1
  64. package/dist/chunk-YJOVLRSC.js +0 -1
  65. package/dist/chunk-YJOVLRSC.js.map +0 -1
  66. package/dist/types-DETYKDFZ.d.cts +0 -139
  67. package/dist/types-DETYKDFZ.d.ts +0 -139
  68. package/src/components/__snapshots__/Client/showPetById.ts +0 -8
  69. package/src/components/__snapshots__/Operations/showPetById.ts +0 -6
  70. package/src/components/__snapshots__/Query/showPetById.ts +0 -15
  71. package/src/generators/axiosGenerator.tsx +0 -63
@@ -1,128 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/components/Client.tsx
2
- var _utils = require('@kubb/core/utils');
3
- var _oas = require('@kubb/oas');
4
- var _utils3 = require('@kubb/plugin-oas/utils');
5
- var _react = require('@kubb/react');
6
- var _jsxruntime = require('@kubb/react/jsx-runtime');
7
- function Client({ name, options, typedSchemas, operation }) {
8
- const contentType = operation.getContentType();
9
- const baseURL = options.client.importPath === "@kubb/plugin-client/client" ? options.baseURL : void 0;
10
- const path = new (0, _utils.URLPath)(operation.path);
11
- const isFormData = contentType === "multipart/form-data";
12
- const headers = [
13
- contentType !== "application/json" ? `'Content-Type': '${contentType}'` : void 0,
14
- _optionalChain([typedSchemas, 'access', _ => _.headerParams, 'optionalAccess', _2 => _2.name]) ? "...headers" : void 0
15
- ].filter(Boolean);
16
- const params = _react.createParams.call(void 0, {
17
- pathParams: {
18
- mode: options.pathParamsType === "object" ? "object" : "inlineSpread",
19
- children: _utils3.getPathParams.call(void 0, typedSchemas.pathParams, { typed: true })
20
- },
21
- data: _optionalChain([typedSchemas, 'access', _3 => _3.request, 'optionalAccess', _4 => _4.name]) ? {
22
- type: _optionalChain([typedSchemas, 'access', _5 => _5.request, 'optionalAccess', _6 => _6.name]),
23
- optional: _oas.isOptional.call(void 0, _optionalChain([typedSchemas, 'access', _7 => _7.request, 'optionalAccess', _8 => _8.schema]))
24
- } : void 0,
25
- params: _optionalChain([typedSchemas, 'access', _9 => _9.queryParams, 'optionalAccess', _10 => _10.name]) ? {
26
- type: _optionalChain([typedSchemas, 'access', _11 => _11.queryParams, 'optionalAccess', _12 => _12.name]),
27
- optional: _oas.isOptional.call(void 0, _optionalChain([typedSchemas, 'access', _13 => _13.queryParams, 'optionalAccess', _14 => _14.schema]))
28
- } : void 0,
29
- headers: _optionalChain([typedSchemas, 'access', _15 => _15.headerParams, 'optionalAccess', _16 => _16.name]) ? {
30
- type: _optionalChain([typedSchemas, 'access', _17 => _17.headerParams, 'optionalAccess', _18 => _18.name]),
31
- optional: _oas.isOptional.call(void 0, _optionalChain([typedSchemas, 'access', _19 => _19.headerParams, 'optionalAccess', _20 => _20.schema]))
32
- } : void 0,
33
- options: {
34
- type: "Partial<Parameters<typeof client>[0]>",
35
- default: "{}"
36
- }
37
- });
38
- const clientParams = _react.createParams.call(void 0, {
39
- data: {
40
- mode: "object",
41
- children: {
42
- method: {
43
- type: "string",
44
- value: JSON.stringify(operation.method)
45
- },
46
- url: {
47
- type: "string",
48
- value: path.template
49
- },
50
- baseURL: baseURL ? {
51
- type: "string",
52
- value: JSON.stringify(baseURL)
53
- } : void 0,
54
- params: _optionalChain([typedSchemas, 'access', _21 => _21.queryParams, 'optionalAccess', _22 => _22.name]) ? {
55
- type: "any"
56
- } : void 0,
57
- data: _optionalChain([typedSchemas, 'access', _23 => _23.request, 'optionalAccess', _24 => _24.name]) ? {
58
- type: "any",
59
- value: isFormData ? "formData" : void 0
60
- } : void 0,
61
- headers: headers.length ? {
62
- type: "any",
63
- value: headers.length ? `{ ${headers.join(", ")}, ...options.headers }` : void 0
64
- } : void 0,
65
- options: {
66
- type: "any",
67
- mode: "inlineSpread"
68
- }
69
- }
70
- }
71
- });
72
- const formData = isFormData ? `
73
- const formData = new FormData()
74
- if(data) {
75
- Object.keys(data).forEach((key) => {
76
- const value = data[key];
77
- if (typeof key === "string" && (typeof value === "string" || value instanceof Blob)) {
78
- formData.append(key, value);
79
- }
80
- })
81
- }
82
- ` : void 0;
83
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
84
- _react.Function,
85
- {
86
- name,
87
- async: true,
88
- export: true,
89
- returnType: options.dataReturnType === "data" ? `ResponseConfig<${typedSchemas.response.name}>["data"]` : `ResponseConfig<${typedSchemas.response.name}>`,
90
- params,
91
- JSDoc: {
92
- comments: _utils3.getComments.call(void 0, operation)
93
- },
94
- children: [
95
- formData || "",
96
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
97
- _react.Function.Call,
98
- {
99
- name: "res",
100
- to: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function, { name: "client", async: true, generics: [typedSchemas.response.name, _optionalChain([typedSchemas, 'access', _25 => _25.request, 'optionalAccess', _26 => _26.name])].filter(Boolean), params: clientParams })
101
- }
102
- ),
103
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Function.Return, { children: options.dataReturnType === "data" ? "res.data" : "res" })
104
- ]
105
- }
106
- ) });
107
- }
108
-
109
- // src/components/Operations.tsx
110
-
111
-
112
-
113
- function Operations({ name, operations }) {
114
- const operationsObject = {};
115
- operations.forEach((operation) => {
116
- operationsObject[operation.getOperationId()] = {
117
- path: new (0, _utils.URLPath)(operation.path).URL,
118
- method: operation.method
119
- };
120
- });
121
- return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.File.Source, { name, isExportable: true, isIndexable: true, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.Const, { name, export: true, asConst: true, children: JSON.stringify(operationsObject, void 0, 2) }) });
122
- }
123
-
124
-
125
-
126
-
127
- exports.Client = Client; exports.Operations = Operations;
128
- //# sourceMappingURL=chunk-YGRM4AA5.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/chunk-YGRM4AA5.cjs","../src/components/Client.tsx","../src/components/Operations.tsx"],"names":["URLPath","jsx","File"],"mappings":"AAAA;ACAA,yCAAwB;AAExB,gCAA2C;AAE3C,gDAA2C;AAC3C,oCAA6C;AAgHvC,qDAAA;AAlGC,SAAS,MAAA,CAAO,EAAE,IAAA,EAAM,OAAA,EAAS,YAAA,EAAc,UAAU,CAAA,EAAoB;AAClF,EAAA,MAAM,YAAA,EAAc,SAAA,CAAU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import { type Operation, isOptional } from '@kubb/oas'\nimport type { OperationSchemas } from '@kubb/plugin-oas'\nimport { getComments, getPathParams } from '@kubb/plugin-oas/utils'\nimport { File, Function, createParams } from '@kubb/react'\nimport type { KubbNode, Params } from '@kubb/react/types'\nimport type { PluginClient } from '../types.ts'\n\ntype Props = {\n /**\n * Name of the function\n */\n name: string\n options: PluginClient['resolvedOptions']\n typedSchemas: OperationSchemas\n operation: Operation\n}\n\nexport function Client({ name, options, typedSchemas, operation }: Props): KubbNode {\n const contentType = operation.getContentType()\n const baseURL = options.client.importPath === '@kubb/plugin-client/client' ? options.baseURL : undefined\n const path = new URLPath(operation.path)\n const isFormData = contentType === 'multipart/form-data'\n const headers = [\n contentType !== 'application/json' ? `'Content-Type': '${contentType}'` : undefined,\n typedSchemas.headerParams?.name ? '...headers' : undefined,\n ].filter(Boolean)\n\n const params = createParams({\n pathParams: {\n mode: options.pathParamsType === 'object' ? 'object' : 'inlineSpread',\n children: getPathParams(typedSchemas.pathParams, { typed: true }),\n },\n data: typedSchemas.request?.name\n ? {\n type: typedSchemas.request?.name,\n optional: isOptional(typedSchemas.request?.schema),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: typedSchemas.queryParams?.name,\n optional: isOptional(typedSchemas.queryParams?.schema),\n }\n : undefined,\n headers: typedSchemas.headerParams?.name\n ? {\n type: typedSchemas.headerParams?.name,\n optional: isOptional(typedSchemas.headerParams?.schema),\n }\n : undefined,\n options: {\n type: 'Partial<Parameters<typeof client>[0]>',\n default: '{}',\n },\n })\n\n const clientParams = createParams({\n data: {\n mode: 'object',\n children: {\n method: {\n type: 'string',\n value: JSON.stringify(operation.method),\n },\n url: {\n type: 'string',\n value: path.template,\n },\n baseURL: baseURL\n ? {\n type: 'string',\n value: JSON.stringify(baseURL),\n }\n : undefined,\n params: typedSchemas.queryParams?.name\n ? {\n type: 'any',\n }\n : undefined,\n data: typedSchemas.request?.name\n ? {\n type: 'any',\n value: isFormData ? 'formData' : undefined,\n }\n : undefined,\n headers: headers.length\n ? {\n type: 'any',\n value: headers.length ? `{ ${headers.join(', ')}, ...options.headers }` : undefined,\n }\n : undefined,\n options: {\n type: 'any',\n mode: 'inlineSpread',\n },\n },\n },\n })\n\n const formData = isFormData\n ? `\n const formData = new FormData()\n if(data) {\n Object.keys(data).forEach((key) => {\n const value = data[key];\n if (typeof key === \"string\" && (typeof value === \"string\" || value instanceof Blob)) {\n formData.append(key, value);\n }\n })\n }\n `\n : undefined\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Function\n name={name}\n async\n export\n returnType={\n options.dataReturnType === 'data' ? `ResponseConfig<${typedSchemas.response.name}>[\"data\"]` : `ResponseConfig<${typedSchemas.response.name}>`\n }\n params={params}\n JSDoc={{\n comments: getComments(operation),\n }}\n >\n {formData || ''}\n <Function.Call\n name=\"res\"\n to={<Function name=\"client\" async generics={[typedSchemas.response.name, typedSchemas.request?.name].filter(Boolean)} params={clientParams} />}\n />\n <Function.Return>{options.dataReturnType === 'data' ? 'res.data' : 'res'}</Function.Return>\n </Function>\n </File.Source>\n )\n}\n","import { URLPath } from '@kubb/core/utils'\nimport { Const, File } from '@kubb/react'\n\nimport type { HttpMethod, Operation } from '@kubb/oas'\n\ntype OperationsProps = {\n name: string\n operations: Array<Operation>\n}\n\nexport function Operations({ name, operations }: OperationsProps) {\n const operationsObject: Record<string, { path: string; method: HttpMethod }> = {}\n\n operations.forEach((operation) => {\n operationsObject[operation.getOperationId()] = {\n path: new URLPath(operation.path).URL,\n method: operation.method,\n }\n })\n\n return (\n <File.Source name={name} isExportable isIndexable>\n <Const name={name} export asConst>\n {JSON.stringify(operationsObject, undefined, 2)}\n </Const>\n </File.Source>\n )\n}\n"]}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=chunk-YJOVLRSC.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,139 +0,0 @@
1
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
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';
6
-
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
- type Options = {
29
- output?: {
30
- /**
31
- * Output to save the clients.
32
- * @default `"clients"``
33
- */
34
- path: string;
35
- /**
36
- * Name to be used for the `export * as {{exportAs}} from './'`
37
- */
38
- exportAs?: string;
39
- /**
40
- * Add an extension to the generated imports and exports, default it will not use an extension
41
- */
42
- extName?: KubbFile.Extname;
43
- /**
44
- * Define what needs to exported, here you can also disable the export of barrel files
45
- * @default `'barrelNamed'`
46
- */
47
- exportType?: 'barrel' | 'barrelNamed' | false;
48
- };
49
- /**
50
- * Group the clients based on the provided name.
51
- */
52
- group?: {
53
- /**
54
- * Tag will group based on the operation tag inside the Swagger file
55
- */
56
- type: 'tag';
57
- /**
58
- * Relative path to save the grouped clients.
59
- *
60
- * `{{tag}}` will be replaced by the current tagName.
61
- * @example `${output}/{{tag}}Controller` => `clients/PetController`
62
- * @default `${output}/{{tag}}Controller`
63
- */
64
- output?: string;
65
- /**
66
- * Name to be used for the `export * as {{exportAs}} from './`
67
- * @default `"{{tag}}Service"`
68
- */
69
- exportAs?: string;
70
- };
71
- /**
72
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
73
- */
74
- exclude?: Array<Exclude>;
75
- /**
76
- * Array containing include parameters to include tags/operations/methods/paths.
77
- */
78
- include?: Array<Include>;
79
- /**
80
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
81
- */
82
- 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
- };
98
- /**
99
- * ReturnType that needs to be used when calling client().
100
- *
101
- * `Data` will return ResponseConfig[data].
102
- *
103
- * `Full` will return ResponseConfig.
104
- * @default `'data'`
105
- * @private
106
- */
107
- dataReturnType?: 'data' | 'full';
108
- /**
109
- * How to pass your pathParams.
110
- *
111
- * `object` will return the pathParams as an object.
112
- *
113
- * `inline` will return the pathParams as comma separated params.
114
- * @default `'inline'`
115
- * @private
116
- */
117
- pathParamsType?: 'object' | 'inline';
118
- transformers?: {
119
- /**
120
- * Customize the names based on the type that is provided by the plugin.
121
- */
122
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
123
- };
124
- /**
125
- * Make it possible to override one of the templates
126
- */
127
- templates?: Partial<Templates>;
128
- };
129
- type ResolvedOptions = {
130
- extName: KubbFile.Extname | undefined;
131
- baseURL: string | undefined;
132
- client: Required<NonNullable<Options['client']>>;
133
- dataReturnType: NonNullable<Options['dataReturnType']>;
134
- pathParamsType: NonNullable<Options['pathParamsType']>;
135
- templates: NonNullable<Templates>;
136
- };
137
- type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
138
-
139
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
@@ -1,139 +0,0 @@
1
- import { PluginFactoryOptions, ResolveNameParams } from '@kubb/core';
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';
6
-
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
- type Options = {
29
- output?: {
30
- /**
31
- * Output to save the clients.
32
- * @default `"clients"``
33
- */
34
- path: string;
35
- /**
36
- * Name to be used for the `export * as {{exportAs}} from './'`
37
- */
38
- exportAs?: string;
39
- /**
40
- * Add an extension to the generated imports and exports, default it will not use an extension
41
- */
42
- extName?: KubbFile.Extname;
43
- /**
44
- * Define what needs to exported, here you can also disable the export of barrel files
45
- * @default `'barrelNamed'`
46
- */
47
- exportType?: 'barrel' | 'barrelNamed' | false;
48
- };
49
- /**
50
- * Group the clients based on the provided name.
51
- */
52
- group?: {
53
- /**
54
- * Tag will group based on the operation tag inside the Swagger file
55
- */
56
- type: 'tag';
57
- /**
58
- * Relative path to save the grouped clients.
59
- *
60
- * `{{tag}}` will be replaced by the current tagName.
61
- * @example `${output}/{{tag}}Controller` => `clients/PetController`
62
- * @default `${output}/{{tag}}Controller`
63
- */
64
- output?: string;
65
- /**
66
- * Name to be used for the `export * as {{exportAs}} from './`
67
- * @default `"{{tag}}Service"`
68
- */
69
- exportAs?: string;
70
- };
71
- /**
72
- * Array containing exclude parameters to exclude/skip tags/operations/methods/paths.
73
- */
74
- exclude?: Array<Exclude>;
75
- /**
76
- * Array containing include parameters to include tags/operations/methods/paths.
77
- */
78
- include?: Array<Include>;
79
- /**
80
- * Array containing override parameters to override `options` based on tags/operations/methods/paths.
81
- */
82
- 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
- };
98
- /**
99
- * ReturnType that needs to be used when calling client().
100
- *
101
- * `Data` will return ResponseConfig[data].
102
- *
103
- * `Full` will return ResponseConfig.
104
- * @default `'data'`
105
- * @private
106
- */
107
- dataReturnType?: 'data' | 'full';
108
- /**
109
- * How to pass your pathParams.
110
- *
111
- * `object` will return the pathParams as an object.
112
- *
113
- * `inline` will return the pathParams as comma separated params.
114
- * @default `'inline'`
115
- * @private
116
- */
117
- pathParamsType?: 'object' | 'inline';
118
- transformers?: {
119
- /**
120
- * Customize the names based on the type that is provided by the plugin.
121
- */
122
- name?: (name: ResolveNameParams['name'], type?: ResolveNameParams['type']) => string;
123
- };
124
- /**
125
- * Make it possible to override one of the templates
126
- */
127
- templates?: Partial<Templates>;
128
- };
129
- type ResolvedOptions = {
130
- extName: KubbFile.Extname | undefined;
131
- baseURL: string | undefined;
132
- client: Required<NonNullable<Options['client']>>;
133
- dataReturnType: NonNullable<Options['dataReturnType']>;
134
- pathParamsType: NonNullable<Options['pathParamsType']>;
135
- templates: NonNullable<Templates>;
136
- };
137
- type PluginClient = PluginFactoryOptions<'plugin-client', Options, ResolvedOptions, never, ResolvePathOptions>;
138
-
139
- export { Client as C, type Options as O, type PluginClient as P, Operations as a };
@@ -1,8 +0,0 @@
1
- /**
2
- * @summary Info for a specific pet
3
- * @link /pets/:pet_id
4
- */
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 })
7
- return res.data
8
- }
@@ -1,6 +0,0 @@
1
- export const operations = {
2
- "showPetById": {
3
- "path": "/pets/:pet_id",
4
- "method": "get"
5
- }
6
- } as const
@@ -1,15 +0,0 @@
1
- /**
2
- * @summary Info for a specific pet
3
- * @link /pets/:pet_id */
4
-
5
- export async function showPetById(
6
- { petId, testId }: ShowPetByIdPathParams,
7
- options: Partial<Parameters<typeof client>[0]> = {},
8
- ): Promise<ResponseConfig<ShowPetByIdQueryResponse>['data']> {
9
- const res = await client<ShowPetByIdQueryResponse>({
10
- method: 'get',
11
- url: `/pets/${petId}`,
12
- ...options,
13
- })
14
- return res.data
15
- }
@@ -1,63 +0,0 @@
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
- })