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

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.
@@ -1,4 +1,4 @@
1
- export { C as Client, a as Operations } from './types-xK4X9e5d.cjs';
1
+ export { C as Client, a as Operations } from './types-C14AAtNX.cjs';
2
2
  import '@kubb/core';
3
3
  import '@kubb/fs/types';
4
4
  import '@kubb/plugin-oas';
@@ -1,4 +1,4 @@
1
- export { C as Client, a as Operations } from './types-xK4X9e5d.js';
1
+ export { C as Client, a as Operations } from './types-C14AAtNX.js';
2
2
  import '@kubb/core';
3
3
  import '@kubb/fs/types';
4
4
  import '@kubb/plugin-oas';
package/dist/index.cjs CHANGED
@@ -13,44 +13,25 @@ var _utils3 = require('@kubb/plugin-oas/utils');
13
13
 
14
14
  // src/OperationGenerator.tsx
15
15
 
16
- var _components = require('@kubb/plugin-oas/components');
17
- var _react = require('@kubb/react');
16
+ require('@kubb/plugin-oas/components');
17
+ require('@kubb/react');
18
18
  var _jsxruntime = require('@kubb/react/jsx-runtime');
19
- var OperationGenerator = class extends _pluginoas.OperationGenerator {
20
- async all(operations, _operationsByMethod) {
21
- const { pluginManager, oas, plugin, mode } = this.context;
22
- const root = _react.createRoot.call(void 0, {
23
- logger: pluginManager.logger
24
- });
25
- const templates = {
26
- operations: _chunkW7F5CMU6cjs.Operations.templates,
27
- client: _chunkW7F5CMU6cjs.Client.templates,
28
- ...this.options.templates
29
- };
30
- root.render(
31
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkW7F5CMU6cjs.Operations.File, { baseURL: this.options.baseURL, templates: templates.operations }) }) })
32
- );
33
- return root.files;
34
- }
35
- async operation(operation, options) {
36
- const { oas, pluginManager, plugin, mode } = this.context;
37
- const root = _react.createRoot.call(void 0, {
38
- logger: pluginManager.logger
39
- });
40
- const templates = {
41
- operations: _chunkW7F5CMU6cjs.Operations.templates,
42
- client: _chunkW7F5CMU6cjs.Client.templates,
43
- ...options.templates
44
- };
45
- if (!templates.client) {
46
- return [];
19
+ var clientParser = _pluginoas.createReactParser.call(void 0, {
20
+ name: "plugin-client",
21
+ Operations({ options }) {
22
+ if (!options.templates.operations) {
23
+ return null;
24
+ }
25
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkW7F5CMU6cjs.Operations.File, { baseURL: options.baseURL, templates: options.templates.operations });
26
+ },
27
+ Operation({ options, operation }) {
28
+ const isEnabled = options.client.methods.some((method) => operation.method === method);
29
+ if (!options.templates.client || !isEnabled) {
30
+ return null;
47
31
  }
48
- root.render(
49
- /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _react.App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _components.Oas.Operation, { operation, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkW7F5CMU6cjs.Client.File, { baseURL: this.options.baseURL, templates: templates.client }) }) }) })
50
- );
51
- return root.files;
32
+ return /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkW7F5CMU6cjs.Client.File, { baseURL: options.baseURL, templates: options.templates.client });
52
33
  }
53
- };
34
+ });
54
35
 
55
36
  // src/plugin.ts
56
37
  var pluginClientName = "plugin-client";
@@ -74,6 +55,7 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
74
55
  dataReturnType,
75
56
  client: {
76
57
  importPath: "@kubb/plugin-client/client",
58
+ methods: ["get", "post", "delete", "put"],
77
59
  ...options.client
78
60
  },
79
61
  pathParamsType,
@@ -104,19 +86,13 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
104
86
  }
105
87
  return resolvedName;
106
88
  },
107
- async writeFile(path2, source) {
108
- if (!source) {
109
- return;
110
- }
111
- return this.fileManager.write(path2, source, { sanity: false });
112
- },
113
89
  async buildStart() {
114
90
  const [swaggerPlugin] = _core.PluginManager.getDependedPlugins(this.plugins, [_pluginoas.pluginOasName]);
115
- const oas = await swaggerPlugin.api.getOas();
91
+ const oas = await swaggerPlugin.context.getOas();
116
92
  const root = _path2.default.resolve(this.config.root, this.config.output.path);
117
93
  const mode = _core.FileManager.getMode(_path2.default.resolve(root, output.path));
118
- const baseURL = await swaggerPlugin.api.getBaseURL();
119
- const operationGenerator = new OperationGenerator(
94
+ const baseURL = await swaggerPlugin.context.getBaseURL();
95
+ const operationGenerator = new (0, _pluginoas.OperationGenerator)(
120
96
  {
121
97
  ...this.plugin.options,
122
98
  baseURL
@@ -125,14 +101,14 @@ var pluginClient = _core.createPlugin.call(void 0, (options) => {
125
101
  oas,
126
102
  pluginManager: this.pluginManager,
127
103
  plugin: this.plugin,
128
- contentType: swaggerPlugin.api.contentType,
104
+ contentType: swaggerPlugin.context.contentType,
129
105
  exclude,
130
106
  include,
131
107
  override,
132
108
  mode
133
109
  }
134
110
  );
135
- const files = await operationGenerator.build();
111
+ const files = await operationGenerator.build(clientParser);
136
112
  await this.addFile(...files);
137
113
  },
138
114
  async buildEnd() {
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAA8B;AAC9B,gDAAqC;ADMrC;AACA;AEbA;AACA,yDAAoB;AACpB,oCAAgC;AAyBG,qDAAA;AAjB5B,IAAM,mBAAA,EAAN,MAAA,QAAiC,8BAAyD;AAAA,EAC/F,MAAM,GAAA,CAAI,UAAA,EAAyB,mBAAA,EAA0E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;AAChB,MAAA;AACQ,MAAA;AACM,QAAA;AACD,QAAA;AACb,MAAA;AACA,MAAA;AACW,MAAA;AACc,QAAA;AACR,QAAA;AACZ,QAAA;AACL,MAAA;AACS,MAAA;AACX,IAAA;AACmB,IAAA;AACsB,IAAA;AACK,MAAA;AACC,MAAA;AAEtB,MAAA;AAKgB,QAAA;AACvC,MAAA;AAE2C,MAAA;AACR,QAAA;AAEQ,QAAA;AAC3C,MAAA;AAEuC,MAAA;AACzC,IAAA;AACwB,IAAA;AACiB,MAAA;AAE7B,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AAC8B,IAAA;AACf,MAAA;AACX,QAAA;AACF,MAAA;AAE4C,MAAA;AAC9C,IAAA;AACmB,IAAA;AACqD,MAAA;AAE3B,MAAA;AACC,MAAA;AACN,MAAA;AACE,MAAA;AAET,MAAA;AAC7B,QAAA;AACiB,UAAA;AACf,UAAA;AACF,QAAA;AACA,QAAA;AACE,UAAA;AACoB,UAAA;AACP,UAAA;AACkB,UAAA;AAC/B,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AAE6C,MAAA;AAElB,MAAA;AAC7B,IAAA;AACiB,IAAA;AACyB,MAAA;AACtC,QAAA;AACF,MAAA;AAE4C,MAAA;AAEjB,MAAA;AACD,QAAA;AACT,UAAA;AACW,UAAA;AACX,UAAA;AACb,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACA,UAAA;AACD,QAAA;AAE8B,QAAA;AACjC,MAAA;AAEkC,MAAA;AAChC,QAAA;AACA,QAAA;AACmC,QAAA;AACtB,QAAA;AACd,MAAA;AACH,IAAA;AACF,EAAA;AACD;ADmBkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","sourcesContent":[null,"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 { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations.templates,\n client: Client.templates,\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 writeFile(path, source) {\n if (!source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build()\n\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Service',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {\n async all(operations: Operation[], _operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { pluginManager, oas, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n client: Client.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates.operations && <Operations.File baseURL={this.options.baseURL} templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginClient['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n client: Client.templates,\n ...options.templates,\n }\n\n if (!templates.client) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Client.File baseURL={this.options.baseURL} templates={templates.client} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","../src/plugin.ts","../src/OperationGenerator.tsx"],"names":[],"mappings":"AAAA;AACE;AACA;AACF,wDAA6B;AAC7B;AACA;ACLA,wEAAiB;AAEjB,kCAAyD;AACzD,uDAA0B;AAC1B,yCAA+B;AAC/B,6CAAkD;AAClD,gDAAqC;ADMrC;AACA;AEbA;AACA,uCAAoB;AACpB,uBAAgC;AAerB,qDAAA;AAPJ,IAAM,aAAA,EAAe,0CAAA;AAAgC,EAC1D,IAAA,EAAM,eAAA;AAAA,EACN,UAAA,CAAW,EAAE,QAAQ,CAAA,EAAG;AACtB,IAAA,GAAA,CAAI,CAAC,OAAA,CAAQ,SAAA,CAAU,UAAA,EAAY;AACjC,MAAA,OAAO,IAAA;AAAA,IACT;AAEA,IAAA,uBAAO,6BAAA,4BAAC,CAAW,IAAA,EAAX,EAAgB,OAAA,EAAS,OAAA,CAAQ,OAAA,EAAS,SAAA,EAAW,OAAA,CAAQ,SAAA,CAAU,WAAA,CAAY,CAAA;AAAA,EAC7F,CAAA;AAAA,EACA,SAAA,CAAU,EAAE,OAAA,EAAS,UAAU,CAAA,EAAG;AAChC,IAAA,MAAM,UAAA,EAAY,OAAA,CAAQ,MAAA,CAAO,OAAA,CAAQ,IAAA,CA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;AACzC,IAAA;AACwB,IAAA;AACiB,MAAA;AAE7B,MAAA;AACkC,QAAA;AAC5C,MAAA;AAEO,MAAA;AACT,IAAA;AACmB,IAAA;AACqD,MAAA;AAE9B,MAAA;AACI,MAAA;AACN,MAAA;AACM,MAAA;AAEb,MAAA;AAC7B,QAAA;AACiB,UAAA;AACf,UAAA;AACF,QAAA;AACA,QAAA;AACE,UAAA;AACoB,UAAA;AACP,UAAA;AACsB,UAAA;AACnC,UAAA;AACA,UAAA;AACA,UAAA;AACA,UAAA;AACF,QAAA;AACF,MAAA;AAE6C,MAAA;AAElB,MAAA;AAC7B,IAAA;AACiB,IAAA;AACyB,MAAA;AACtC,QAAA;AACF,MAAA;AAE4C,MAAA;AAEjB,MAAA;AACD,QAAA;AACT,UAAA;AACW,UAAA;AACX,UAAA;AACb,UAAA;AAC4B,UAAA;AAC5B,UAAA;AACA,UAAA;AACD,QAAA;AAE8B,QAAA;AACjC,MAAA;AAEkC,MAAA;AAChC,QAAA;AACA,QAAA;AACmC,QAAA;AACtB,QAAA;AACd,MAAA;AACH,IAAA;AACF,EAAA;AACD;ADCkD;AACA;AACA;AACA","file":"/home/runner/work/kubb/kubb/packages/plugin-client/dist/index.cjs","sourcesContent":[null,"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'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { clientParser } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 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.templates,\n client: Client.templates,\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(clientParser)\n\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Service',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { createReactParser, OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport const clientParser = createReactParser<PluginClient>({\n name: 'plugin-client',\n Operations({ options }) {\n if (!options.templates.operations) {\n return null\n }\n\n return <Operations.File baseURL={options.baseURL} templates={options.templates.operations} />\n },\n Operation({ options, operation }) {\n const isEnabled = options.client.methods.some((method) => operation.method === method)\n\n if (!options.templates.client || !isEnabled) {\n return null\n }\n\n return <Client.File baseURL={options.baseURL} templates={options.templates.client} />\n },\n})\n"]}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-xK4X9e5d.cjs';
2
+ import { O as Options, P as PluginClient } from './types-C14AAtNX.cjs';
3
3
  import '@kubb/fs/types';
4
4
  import '@kubb/plugin-oas';
5
5
  import '@kubb/core/utils';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _kubb_core from '@kubb/core';
2
- import { O as Options, P as PluginClient } from './types-xK4X9e5d.js';
2
+ import { O as Options, P as PluginClient } from './types-C14AAtNX.js';
3
3
  import '@kubb/fs/types';
4
4
  import '@kubb/plugin-oas';
5
5
  import '@kubb/core/utils';
package/dist/index.js CHANGED
@@ -8,49 +8,30 @@ import path from "path";
8
8
  import { FileManager, PluginManager, createPlugin } from "@kubb/core";
9
9
  import { camelCase } from "@kubb/core/transformers";
10
10
  import { renderTemplate } from "@kubb/core/utils";
11
- import { pluginOasName } from "@kubb/plugin-oas";
11
+ import { OperationGenerator, pluginOasName } from "@kubb/plugin-oas";
12
12
  import { getGroupedByTagFiles } from "@kubb/plugin-oas/utils";
13
13
 
14
14
  // src/OperationGenerator.tsx
15
- import { OperationGenerator as Generator } from "@kubb/plugin-oas";
16
- import { Oas } from "@kubb/plugin-oas/components";
17
- import { App, createRoot } from "@kubb/react";
15
+ import { createReactParser } from "@kubb/plugin-oas";
16
+ import "@kubb/plugin-oas/components";
17
+ import "@kubb/react";
18
18
  import { jsx } from "@kubb/react/jsx-runtime";
19
- var OperationGenerator = class extends Generator {
20
- async all(operations, _operationsByMethod) {
21
- const { pluginManager, oas, plugin, mode } = this.context;
22
- const root = createRoot({
23
- logger: pluginManager.logger
24
- });
25
- const templates = {
26
- operations: Operations.templates,
27
- client: Client.templates,
28
- ...this.options.templates
29
- };
30
- root.render(
31
- /* @__PURE__ */ jsx(App, { pluginManager, plugin, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations, generator: this, children: templates.operations && /* @__PURE__ */ jsx(Operations.File, { baseURL: this.options.baseURL, templates: templates.operations }) }) })
32
- );
33
- return root.files;
34
- }
35
- async operation(operation, options) {
36
- const { oas, pluginManager, plugin, mode } = this.context;
37
- const root = createRoot({
38
- logger: pluginManager.logger
39
- });
40
- const templates = {
41
- operations: Operations.templates,
42
- client: Client.templates,
43
- ...options.templates
44
- };
45
- if (!templates.client) {
46
- return [];
19
+ var clientParser = createReactParser({
20
+ name: "plugin-client",
21
+ Operations({ options }) {
22
+ if (!options.templates.operations) {
23
+ return null;
24
+ }
25
+ return /* @__PURE__ */ jsx(Operations.File, { baseURL: options.baseURL, templates: options.templates.operations });
26
+ },
27
+ Operation({ options, operation }) {
28
+ const isEnabled = options.client.methods.some((method) => operation.method === method);
29
+ if (!options.templates.client || !isEnabled) {
30
+ return null;
47
31
  }
48
- root.render(
49
- /* @__PURE__ */ jsx(App, { pluginManager, plugin: { ...plugin, options }, mode, children: /* @__PURE__ */ jsx(Oas, { oas, operations: [operation], generator: this, children: /* @__PURE__ */ jsx(Oas.Operation, { operation, children: /* @__PURE__ */ jsx(Client.File, { baseURL: this.options.baseURL, templates: templates.client }) }) }) })
50
- );
51
- return root.files;
32
+ return /* @__PURE__ */ jsx(Client.File, { baseURL: options.baseURL, templates: options.templates.client });
52
33
  }
53
- };
34
+ });
54
35
 
55
36
  // src/plugin.ts
56
37
  var pluginClientName = "plugin-client";
@@ -74,6 +55,7 @@ var pluginClient = createPlugin((options) => {
74
55
  dataReturnType,
75
56
  client: {
76
57
  importPath: "@kubb/plugin-client/client",
58
+ methods: ["get", "post", "delete", "put"],
77
59
  ...options.client
78
60
  },
79
61
  pathParamsType,
@@ -104,18 +86,12 @@ var pluginClient = createPlugin((options) => {
104
86
  }
105
87
  return resolvedName;
106
88
  },
107
- async writeFile(path2, source) {
108
- if (!source) {
109
- return;
110
- }
111
- return this.fileManager.write(path2, source, { sanity: false });
112
- },
113
89
  async buildStart() {
114
90
  const [swaggerPlugin] = PluginManager.getDependedPlugins(this.plugins, [pluginOasName]);
115
- const oas = await swaggerPlugin.api.getOas();
91
+ const oas = await swaggerPlugin.context.getOas();
116
92
  const root = path.resolve(this.config.root, this.config.output.path);
117
93
  const mode = FileManager.getMode(path.resolve(root, output.path));
118
- const baseURL = await swaggerPlugin.api.getBaseURL();
94
+ const baseURL = await swaggerPlugin.context.getBaseURL();
119
95
  const operationGenerator = new OperationGenerator(
120
96
  {
121
97
  ...this.plugin.options,
@@ -125,14 +101,14 @@ var pluginClient = createPlugin((options) => {
125
101
  oas,
126
102
  pluginManager: this.pluginManager,
127
103
  plugin: this.plugin,
128
- contentType: swaggerPlugin.api.contentType,
104
+ contentType: swaggerPlugin.context.contentType,
129
105
  exclude,
130
106
  include,
131
107
  override,
132
108
  mode
133
109
  }
134
110
  );
135
- const files = await operationGenerator.build();
111
+ const files = await operationGenerator.build(clientParser);
136
112
  await this.addFile(...files);
137
113
  },
138
114
  async buildEnd() {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/plugin.ts","../src/OperationGenerator.tsx"],"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 { pluginOasName } from '@kubb/plugin-oas'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { OperationGenerator } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 options: {\n extName: output.extName,\n dataReturnType,\n client: {\n importPath: '@kubb/plugin-client/client',\n ...options.client,\n },\n pathParamsType,\n templates: {\n operations: Operations.templates,\n client: Client.templates,\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 writeFile(path, source) {\n if (!source) {\n return\n }\n\n return this.fileManager.write(path, source, { sanity: false })\n },\n async buildStart() {\n const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])\n\n const oas = await swaggerPlugin.api.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.api.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.api.contentType,\n exclude,\n include,\n override,\n mode,\n },\n )\n\n const files = await operationGenerator.build()\n\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Service',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {\n async all(operations: Operation[], _operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {\n const { pluginManager, oas, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n client: Client.templates,\n ...this.options.templates,\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={plugin} mode={mode}>\n <Oas oas={oas} operations={operations} generator={this}>\n {templates.operations && <Operations.File baseURL={this.options.baseURL} templates={templates.operations} />}\n </Oas>\n </App>,\n )\n\n return root.files\n }\n\n async operation(operation: Operation, options: PluginClient['resolvedOptions']): OperationMethodResult<FileMeta> {\n const { oas, pluginManager, plugin, mode } = this.context\n\n const root = createRoot({\n logger: pluginManager.logger,\n })\n\n const templates = {\n operations: Operations.templates,\n client: Client.templates,\n ...options.templates,\n }\n\n if (!templates.client) {\n return []\n }\n\n root.render(\n <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>\n <Oas oas={oas} operations={[operation]} generator={this}>\n <Oas.Operation operation={operation}>\n <Client.File baseURL={this.options.baseURL} templates={templates.client} />\n </Oas.Operation>\n </Oas>\n </App>,\n )\n\n return root.files\n }\n}\n"],"mappings":";;;;;;AAAA,OAAO,UAAU;AAEjB,SAAS,aAAa,eAAe,oBAAoB;AACzD,SAAS,iBAAiB;AAC1B,SAAS,sBAAsB;AAC/B,SAAS,qBAAqB;AAC9B,SAAS,4BAA4B;;;ACNrC,SAAS,sBAAsB,iBAAiB;AAChD,SAAS,WAAW;AACpB,SAAS,KAAK,kBAAkB;AAyBG;AAjB5B,IAAM,qBAAN,cAAiC,UAAyD;AAAA,EAC/F,MAAM,IAAI,YAAyB,qBAA0E;AAC3G,UAAM,EAAE,eAAe,KAAK,QAAQ,KAAK,IAAI,KAAK;AAElD,UAAM,OAAO,WAAW;AAAA,MACtB,QAAQ,cAAc;AAAA,IACxB,CAAC;AAED,UAAM,YAAY;AAAA,MAChB,YAAY,WAAW;AAAA,MACvB,QAAQ,OAAO;AAAA,MACf,GAAG,K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in.ts","../src/OperationGenerator.tsx"],"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'\nimport { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'\n\nimport { clientParser } from './OperationGenerator.tsx'\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\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 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.templates,\n client: Client.templates,\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(clientParser)\n\n await this.addFile(...files)\n },\n async buildEnd() {\n if (this.config.output.write === false) {\n return\n }\n\n const root = path.resolve(this.config.root, this.config.output.path)\n\n if (group?.type === 'tag') {\n const rootFiles = await getGroupedByTagFiles({\n logger: this.logger,\n files: this.fileManager.files,\n plugin: this.plugin,\n template,\n exportAs: group.exportAs || '{{tag}}Service',\n root,\n output,\n })\n\n await this.addFile(...rootFiles)\n }\n\n await this.fileManager.addIndexes({\n root,\n output,\n meta: { pluginKey: this.plugin.key },\n logger: this.logger,\n })\n },\n }\n})\n","import { createReactParser, OperationGenerator as Generator } from '@kubb/plugin-oas'\nimport { Oas } from '@kubb/plugin-oas/components'\nimport { App, createRoot } from '@kubb/react'\n\nimport { Client, Operations } from './components/index.ts'\n\nimport type { Operation } from '@kubb/oas'\nimport type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'\nimport type { FileMeta, PluginClient } from './types.ts'\n\nexport const clientParser = createReactParser<PluginClient>({\n name: 'plugin-client',\n Operations({ options }) {\n if (!options.templates.operations) {\n return null\n }\n\n return <Operations.File baseURL={options.baseURL} templates={options.templates.operations} />\n },\n Operation({ options, operation }) {\n const isEnabled = options.client.methods.some((method) => operation.method === method)\n\n if (!options.templates.client || !isEnabled) {\n return null\n }\n\n return <Client.File baseURL={options.baseURL} templates={options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c,QAAQ,WAAW;AAEvD,YAAM,qBAAqB,IAAI;AAAA,QAC7B;AAAA,UACE,GAAG,KAAK,OAAO;AAAA,UACf;AAAA,QACF;AAAA,QACA;AAAA,UACE;AAAA,UACA,eAAe,KAAK;AAAA,UACpB,QAAQ,KAAK;AAAA,UACb,aAAa,cAAc,QAAQ;AAAA,UACnC;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAEA,YAAM,QAAQ,MAAM,mBAAmB,MAAM,YAAY;AAEzD,YAAM,KAAK,QAAQ,GAAG,KAAK;AAAA,IAC7B;AAAA,IACA,MAAM,WAAW;AACf,UAAI,KAAK,OAAO,OAAO,UAAU,OAAO;AACtC;AAAA,MACF;AAEA,YAAM,OAAO,KAAK,QAAQ,KAAK,OAAO,MAAM,KAAK,OAAO,OAAO,IAAI;AAEnE,UAAI,OAAO,SAAS,OAAO;AACzB,cAAM,YAAY,MAAM,qBAAqB;AAAA,UAC3C,QAAQ,KAAK;AAAA,UACb,OAAO,KAAK,YAAY;AAAA,UACxB,QAAQ,KAAK;AAAA,UACb;AAAA,UACA,UAAU,MAAM,YAAY;AAAA,UAC5B;AAAA,UACA;AAAA,QACF,CAAC;AAED,cAAM,KAAK,QAAQ,GAAG,SAAS;AAAA,MACjC;AAEA,YAAM,KAAK,YAAY,WAAW;AAAA,QAChC;AAAA,QACA;AAAA,QACA,MAAM,EAAE,WAAW,KAAK,OAAO,IAAI;AAAA,QACnC,QAAQ,KAAK;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;","names":["options"]}
@@ -183,6 +183,11 @@ type Options = {
183
183
  * @default '@kubb/plugin-client/client'
184
184
  */
185
185
  importPath?: string;
186
+ /**
187
+ * Define which HttpMethods can be used for queries
188
+ * @default ['get', 'post', 'put', 'delete']
189
+ */
190
+ methods: Array<HttpMethod>;
186
191
  };
187
192
  /**
188
193
  * ReturnType that needs to be used when calling client().
@@ -183,6 +183,11 @@ type Options = {
183
183
  * @default '@kubb/plugin-client/client'
184
184
  */
185
185
  importPath?: string;
186
+ /**
187
+ * Define which HttpMethods can be used for queries
188
+ * @default ['get', 'post', 'put', 'delete']
189
+ */
190
+ methods: Array<HttpMethod>;
186
191
  };
187
192
  /**
188
193
  * ReturnType that needs to be used when calling client().
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kubb/plugin-client",
3
- "version": "3.0.0-alpha.1",
3
+ "version": "3.0.0-alpha.3",
4
4
  "description": "Generator plugin-client",
5
5
  "keywords": [
6
6
  "typescript",
@@ -64,13 +64,13 @@
64
64
  "!/**/__tests__/**"
65
65
  ],
66
66
  "dependencies": {
67
- "@kubb/core": "3.0.0-alpha.1",
68
- "@kubb/fs": "3.0.0-alpha.1",
69
- "@kubb/oas": "3.0.0-alpha.1",
70
- "@kubb/parser-ts": "3.0.0-alpha.1",
71
- "@kubb/plugin-oas": "3.0.0-alpha.1",
72
- "@kubb/plugin-ts": "3.0.0-alpha.1",
73
- "@kubb/react": "3.0.0-alpha.1"
67
+ "@kubb/core": "3.0.0-alpha.3",
68
+ "@kubb/fs": "3.0.0-alpha.3",
69
+ "@kubb/oas": "3.0.0-alpha.3",
70
+ "@kubb/parser-ts": "3.0.0-alpha.3",
71
+ "@kubb/plugin-oas": "3.0.0-alpha.3",
72
+ "@kubb/plugin-ts": "3.0.0-alpha.3",
73
+ "@kubb/react": "3.0.0-alpha.3"
74
74
  },
75
75
  "devDependencies": {
76
76
  "@types/react": "^18.3.4",
@@ -78,13 +78,13 @@
78
78
  "react": "^18.3.1",
79
79
  "tsup": "^8.2.4",
80
80
  "typescript": "^5.5.4",
81
- "@kubb/config-biome": "3.0.0-alpha.1",
82
- "@kubb/config-ts": "3.0.0-alpha.1",
83
- "@kubb/config-tsup": "3.0.0-alpha.1"
81
+ "@kubb/config-biome": "3.0.0-alpha.3",
82
+ "@kubb/config-ts": "3.0.0-alpha.3",
83
+ "@kubb/config-tsup": "3.0.0-alpha.3"
84
84
  },
85
85
  "peerDependencies": {
86
86
  "axios": "^1.7.2",
87
- "@kubb/react": "3.0.0-alpha.1"
87
+ "@kubb/react": "3.0.0-alpha.3"
88
88
  },
89
89
  "peerDependenciesMeta": {
90
90
  "axios": {
@@ -1,4 +1,4 @@
1
- import { OperationGenerator as Generator } from '@kubb/plugin-oas'
1
+ import { createReactParser, OperationGenerator as Generator } from '@kubb/plugin-oas'
2
2
  import { Oas } from '@kubb/plugin-oas/components'
3
3
  import { App, createRoot } from '@kubb/react'
4
4
 
@@ -8,58 +8,22 @@ import type { Operation } from '@kubb/oas'
8
8
  import type { OperationMethodResult, OperationsByMethod } from '@kubb/plugin-oas'
9
9
  import type { FileMeta, PluginClient } from './types.ts'
10
10
 
11
- export class OperationGenerator extends Generator<PluginClient['resolvedOptions'], PluginClient> {
12
- async all(operations: Operation[], _operationsByMethod: OperationsByMethod): OperationMethodResult<FileMeta> {
13
- const { pluginManager, oas, plugin, mode } = this.context
14
-
15
- const root = createRoot({
16
- logger: pluginManager.logger,
17
- })
18
-
19
- const templates = {
20
- operations: Operations.templates,
21
- client: Client.templates,
22
- ...this.options.templates,
11
+ export const clientParser = createReactParser<PluginClient>({
12
+ name: 'plugin-client',
13
+ Operations({ options }) {
14
+ if (!options.templates.operations) {
15
+ return null
23
16
  }
24
17
 
25
- root.render(
26
- <App pluginManager={pluginManager} plugin={plugin} mode={mode}>
27
- <Oas oas={oas} operations={operations} generator={this}>
28
- {templates.operations && <Operations.File baseURL={this.options.baseURL} templates={templates.operations} />}
29
- </Oas>
30
- </App>,
31
- )
32
-
33
- return root.files
34
- }
35
-
36
- async operation(operation: Operation, options: PluginClient['resolvedOptions']): OperationMethodResult<FileMeta> {
37
- const { oas, pluginManager, plugin, mode } = this.context
18
+ return <Operations.File baseURL={options.baseURL} templates={options.templates.operations} />
19
+ },
20
+ Operation({ options, operation }) {
21
+ const isEnabled = options.client.methods.some((method) => operation.method === method)
38
22
 
39
- const root = createRoot({
40
- logger: pluginManager.logger,
41
- })
42
-
43
- const templates = {
44
- operations: Operations.templates,
45
- client: Client.templates,
46
- ...options.templates,
47
- }
48
-
49
- if (!templates.client) {
50
- return []
23
+ if (!options.templates.client || !isEnabled) {
24
+ return null
51
25
  }
52
26
 
53
- root.render(
54
- <App pluginManager={pluginManager} plugin={{ ...plugin, options }} mode={mode}>
55
- <Oas oas={oas} operations={[operation]} generator={this}>
56
- <Oas.Operation operation={operation}>
57
- <Client.File baseURL={this.options.baseURL} templates={templates.client} />
58
- </Oas.Operation>
59
- </Oas>
60
- </App>,
61
- )
62
-
63
- return root.files
64
- }
65
- }
27
+ return <Client.File baseURL={options.baseURL} templates={options.templates.client} />
28
+ },
29
+ })
package/src/plugin.ts CHANGED
@@ -3,10 +3,10 @@ import path from 'node:path'
3
3
  import { FileManager, PluginManager, createPlugin } from '@kubb/core'
4
4
  import { camelCase } from '@kubb/core/transformers'
5
5
  import { renderTemplate } from '@kubb/core/utils'
6
- import { pluginOasName } from '@kubb/plugin-oas'
6
+ import { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'
7
7
  import { getGroupedByTagFiles } from '@kubb/plugin-oas/utils'
8
8
 
9
- import { OperationGenerator } from './OperationGenerator.tsx'
9
+ import { clientParser } from './OperationGenerator.tsx'
10
10
  import { Client, Operations } from './components/index.ts'
11
11
 
12
12
  import type { Plugin } from '@kubb/core'
@@ -37,6 +37,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
37
37
  dataReturnType,
38
38
  client: {
39
39
  importPath: '@kubb/plugin-client/client',
40
+ methods: ['get', 'post', 'delete', 'put'],
40
41
  ...options.client,
41
42
  },
42
43
  pathParamsType,
@@ -77,20 +78,13 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
77
78
 
78
79
  return resolvedName
79
80
  },
80
- async writeFile(path, source) {
81
- if (!source) {
82
- return
83
- }
84
-
85
- return this.fileManager.write(path, source, { sanity: false })
86
- },
87
81
  async buildStart() {
88
82
  const [swaggerPlugin]: [Plugin<SwaggerPluginOptions>] = PluginManager.getDependedPlugins<SwaggerPluginOptions>(this.plugins, [pluginOasName])
89
83
 
90
- const oas = await swaggerPlugin.api.getOas()
84
+ const oas = await swaggerPlugin.context.getOas()
91
85
  const root = path.resolve(this.config.root, this.config.output.path)
92
86
  const mode = FileManager.getMode(path.resolve(root, output.path))
93
- const baseURL = await swaggerPlugin.api.getBaseURL()
87
+ const baseURL = await swaggerPlugin.context.getBaseURL()
94
88
 
95
89
  const operationGenerator = new OperationGenerator(
96
90
  {
@@ -101,7 +95,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
101
95
  oas,
102
96
  pluginManager: this.pluginManager,
103
97
  plugin: this.plugin,
104
- contentType: swaggerPlugin.api.contentType,
98
+ contentType: swaggerPlugin.context.contentType,
105
99
  exclude,
106
100
  include,
107
101
  override,
@@ -109,7 +103,7 @@ export const pluginClient = createPlugin<PluginClient>((options) => {
109
103
  },
110
104
  )
111
105
 
112
- const files = await operationGenerator.build()
106
+ const files = await operationGenerator.build(clientParser)
113
107
 
114
108
  await this.addFile(...files)
115
109
  },
package/src/types.ts CHANGED
@@ -3,6 +3,7 @@ import type * as KubbFile from '@kubb/fs/types'
3
3
 
4
4
  import type { Exclude, Include, Override, ResolvePathOptions } from '@kubb/plugin-oas'
5
5
  import type { Client, Operations } from './components/index.ts'
6
+ import type { HttpMethod } from '@kubb/oas'
6
7
 
7
8
  type Templates = {
8
9
  operations?: typeof Operations.templates | false
@@ -73,6 +74,11 @@ export type Options = {
73
74
  * @default '@kubb/plugin-client/client'
74
75
  */
75
76
  importPath?: string
77
+ /**
78
+ * Define which HttpMethods can be used for queries
79
+ * @default ['get', 'post', 'put', 'delete']
80
+ */
81
+ methods: Array<HttpMethod>
76
82
  }
77
83
  /**
78
84
  * ReturnType that needs to be used when calling client().