@kubb/plugin-swr 3.0.14 → 3.2.0
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/dist/{chunk-23A6KPTG.js → chunk-4EFF327C.js} +10 -3
- package/dist/chunk-4EFF327C.js.map +1 -0
- package/dist/{chunk-ZO4CRCE6.cjs → chunk-4ZIGOWYH.cjs} +15 -8
- package/dist/chunk-4ZIGOWYH.cjs.map +1 -0
- package/dist/{chunk-HOCARL2F.js → chunk-7ELDJ4IB.js} +33 -24
- package/dist/chunk-7ELDJ4IB.js.map +1 -0
- package/dist/{chunk-442Q5BKM.cjs → chunk-DJ57MWSH.cjs} +33 -24
- package/dist/chunk-DJ57MWSH.cjs.map +1 -0
- package/dist/components.cjs +6 -6
- package/dist/components.d.cts +15 -8
- package/dist/components.d.ts +15 -8
- package/dist/components.js +1 -1
- package/dist/generators.cjs +4 -4
- package/dist/generators.d.cts +1 -1
- package/dist/generators.d.ts +1 -1
- package/dist/generators.js +2 -2
- package/dist/index.cjs +18 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/{types-AhGZx7jH.d.cts → types-CwvU4w1t.d.cts} +16 -0
- package/dist/{types-AhGZx7jH.d.ts → types-CwvU4w1t.d.ts} +16 -0
- package/package.json +12 -12
- package/src/components/Mutation.tsx +7 -2
- package/src/components/MutationKey.tsx +5 -4
- package/src/components/Query.tsx +9 -3
- package/src/components/QueryKey.tsx +9 -6
- package/src/components/QueryOptions.tsx +8 -5
- package/src/generators/mutationGenerator.tsx +3 -0
- package/src/generators/queryGenerator.tsx +4 -0
- package/src/plugin.ts +16 -6
- package/src/types.ts +8 -0
- package/dist/chunk-23A6KPTG.js.map +0 -1
- package/dist/chunk-442Q5BKM.cjs.map +0 -1
- package/dist/chunk-HOCARL2F.js.map +0 -1
- package/dist/chunk-ZO4CRCE6.cjs.map +0 -1
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OAAA;AAAA,IACA,WAAW,EAAC;AAAA,IACZ,MAAS,GAAA,QAAA;AAAA,kBACTC,iBAAe,EAAC;AAAA,IAChB,KAAA;AAAA,IACA,QAAA;AAAA,IACA,MAAA;AAAA,IACA,UAAa,GAAA,QAAA;AAAA,IACb,cAAiB,GAAA,QAAA;AAAA,IACjB,cAAcC,6BAAY,CAAA,cAAA;AAAA,IAC1B,WAAWC,0BAAS,CAAA,cAAA;AAAA,IACpB,aAAa,CAACC,gCAAA,EAAgBC,mCAAiB,CAAA,CAAE,OAAO,OAAO;AAAA,
|
|
1
|
+
{"version":3,"sources":["../src/plugin.ts"],"names":["createPlugin","transformers","MutationKey","QueryKey","queryGenerator","mutationGenerator","pluginOasName","pluginTsName","pluginZodName","options","path","FileManager","camelCase","pascalCase","PluginManager","OperationGenerator"],"mappings":";;;;;;;;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAYA,iBAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAAU,EAAC;AAAA,IACX,OA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,WAAA;AAAA,QACnC,OAAA;AAAA,QACA,OAAA;AAAA,QACA,QAAA;AAAA,QACA;AAAA,OACD,CAAA;AAED,MAAA,MAAM,KAAQ,GAAA,MAAM,kBAAmB,CAAA,KAAA,CAAM,GAAG,UAAU,CAAA;AAC1D,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,KAAK,CAAA;AAE3B,MAAA,MAAM,WAAc,GAAA,MAAM,IAAK,CAAA,WAAA,CAAY,cAAe,CAAA;AAAA,QACxD,IAAA,EAAM,OAAO,UAAc,IAAA,OAAA;AAAA,QAC3B,IAAA;AAAA,QACA,MAAA;AAAA,QACA,KAAA,EAAO,KAAK,WAAY,CAAA,KAAA;AAAA,QACxB,IAAM,EAAA;AAAA,UACJ,SAAA,EAAW,KAAK,MAAO,CAAA;AAAA,SACzB;AAAA,QACA,QAAQ,IAAK,CAAA;AAAA,OACd,CAAA;AAED,MAAM,MAAA,IAAA,CAAK,OAAQ,CAAA,GAAG,WAAW,CAAA;AAAA;AACnC,GACF;AACF,CAAC","file":"index.cjs","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\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?.group && group) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(root, output.path, groupName({ group: options.group }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
package/dist/index.d.cts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { queryGenerator, mutationGenerator } from './chunk-
|
|
2
|
-
import { MutationKey, QueryKey } from './chunk-
|
|
1
|
+
import { queryGenerator, mutationGenerator } from './chunk-4EFF327C.js';
|
|
2
|
+
import { MutationKey, QueryKey } from './chunk-7ELDJ4IB.js';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { createPlugin, FileManager, PluginManager } from '@kubb/core';
|
|
5
5
|
import { camelCase, pascalCase } from '@kubb/core/transformers';
|
|
@@ -24,7 +24,8 @@ var pluginSwr = createPlugin((options) => {
|
|
|
24
24
|
pathParamsType = "inline",
|
|
25
25
|
mutationKey = MutationKey.getTransformer,
|
|
26
26
|
queryKey = QueryKey.getTransformer,
|
|
27
|
-
generators = [queryGenerator, mutationGenerator].filter(Boolean)
|
|
27
|
+
generators = [queryGenerator, mutationGenerator].filter(Boolean),
|
|
28
|
+
paramsCasing
|
|
28
29
|
} = options;
|
|
29
30
|
return {
|
|
30
31
|
name: pluginSwrName,
|
|
@@ -49,19 +50,26 @@ var pluginSwr = createPlugin((options) => {
|
|
|
49
50
|
},
|
|
50
51
|
parser,
|
|
51
52
|
paramsType,
|
|
52
|
-
pathParamsType: paramsType === "object" ? "object" : pathParamsType
|
|
53
|
+
pathParamsType: paramsType === "object" ? "object" : pathParamsType,
|
|
54
|
+
paramsCasing,
|
|
55
|
+
group
|
|
53
56
|
},
|
|
54
57
|
pre: [pluginOasName, pluginTsName, parser === "zod" ? pluginZodName : void 0].filter(Boolean),
|
|
55
58
|
resolvePath(baseName, pathMode, options2) {
|
|
56
59
|
const root = path.resolve(this.config.root, this.config.output.path);
|
|
57
60
|
const mode = pathMode ?? FileManager.getMode(path.resolve(root, output.path));
|
|
58
|
-
if (options2?.tag && group?.type === "tag") {
|
|
59
|
-
const groupName = group?.name ? group.name : (ctx) => `${ctx.group}Controller`;
|
|
60
|
-
return path.resolve(root, output.path, groupName({ group: camelCase(options2.tag) }), baseName);
|
|
61
|
-
}
|
|
62
61
|
if (mode === "single") {
|
|
63
62
|
return path.resolve(root, output.path);
|
|
64
63
|
}
|
|
64
|
+
if (options2?.group && group) {
|
|
65
|
+
const groupName = group?.name ? group.name : (ctx) => {
|
|
66
|
+
if (group?.type === "path") {
|
|
67
|
+
return `${ctx.group.split("/")[1]}`;
|
|
68
|
+
}
|
|
69
|
+
return `${camelCase(ctx.group)}Controller`;
|
|
70
|
+
};
|
|
71
|
+
return path.resolve(root, output.path, groupName({ group: options2.group }), baseName);
|
|
72
|
+
}
|
|
65
73
|
return path.resolve(root, output.path, baseName);
|
|
66
74
|
},
|
|
67
75
|
resolveName(name, type) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/plugin.ts"],"names":["options"],"mappings":";;;;;;;;;AAeO,IAAM,aAAgB,GAAA;AAEhB,IAAA,SAAA,GAAY,YAAwB,CAAA,CAAC,OAAY,KAAA;AAC5D,EAAM,MAAA;AAAA,IACJ,MAAS,GAAA,EAAE,IAAM,EAAA,OAAA,EAAS,YAAY,OAAQ,EAAA;AAAA,IAC9C,KAAA;AAAA,IACA,UAA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nC,GACF;AACF,CAAC","file":"index.js","sourcesContent":["import path from 'node:path'\n\nimport { FileManager, type Group, PluginManager, createPlugin } from '@kubb/core'\nimport { camelCase, pascalCase } from '@kubb/core/transformers'\nimport { OperationGenerator, pluginOasName } from '@kubb/plugin-oas'\n\nimport { pluginTsName } from '@kubb/plugin-ts'\nimport { pluginZodName } from '@kubb/plugin-zod'\n\nimport type { Plugin } from '@kubb/core'\nimport type { PluginOas as SwaggerPluginOptions } from '@kubb/plugin-oas'\nimport { MutationKey, QueryKey } from './components'\nimport { mutationGenerator, queryGenerator } from './generators'\nimport type { PluginSwr } from './types.ts'\n\nexport const pluginSwrName = 'plugin-swr' satisfies PluginSwr['name']\n\nexport const pluginSwr = createPlugin<PluginSwr>((options) => {\n const {\n output = { path: 'hooks', barrelType: 'named' },\n group,\n exclude = [],\n include,\n override = [],\n parser = 'client',\n transformers = {},\n query,\n mutation,\n client,\n paramsType = 'inline',\n pathParamsType = 'inline',\n mutationKey = MutationKey.getTransformer,\n queryKey = QueryKey.getTransformer,\n generators = [queryGenerator, mutationGenerator].filter(Boolean),\n paramsCasing,\n } = options\n\n return {\n name: pluginSwrName,\n options: {\n output,\n client: {\n importPath: '@kubb/plugin-client/client',\n dataReturnType: 'data',\n ...client,\n },\n queryKey,\n query:\n query === false\n ? false\n : {\n importPath: 'swr',\n methods: ['get'],\n ...query,\n },\n mutationKey,\n mutation: {\n importPath: 'swr/mutation',\n methods: ['post', 'put', 'delete', 'patch'],\n ...mutation,\n },\n parser,\n paramsType,\n pathParamsType: paramsType === 'object' ? 'object' : pathParamsType,\n paramsCasing,\n group,\n },\n pre: [pluginOasName, pluginTsName, parser === 'zod' ? pluginZodName : undefined].filter(Boolean),\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?.group && group) {\n const groupName: Group['name'] = group?.name\n ? group.name\n : (ctx) => {\n if (group?.type === 'path') {\n return `${ctx.group.split('/')[1]}`\n }\n return `${camelCase(ctx.group)}Controller`\n }\n\n return path.resolve(root, output.path, groupName({ group: options.group }), baseName)\n }\n\n return path.resolve(root, output.path, baseName)\n },\n resolveName(name, type) {\n let resolvedName = camelCase(name)\n\n if (type === 'file' || type === 'function') {\n resolvedName = camelCase(name, {\n isFile: type === 'file',\n })\n }\n\n if (type === 'type') {\n resolvedName = pascalCase(name)\n }\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 if (baseURL) {\n this.plugin.options.client.baseURL = baseURL\n }\n const operationGenerator = new OperationGenerator(this.plugin.options, {\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 const files = await operationGenerator.build(...generators)\n await this.addFile(...files)\n\n const barrelFiles = await this.fileManager.getBarrelFiles({\n type: output.barrelType ?? 'named',\n root,\n output,\n files: this.fileManager.files,\n meta: {\n pluginKey: this.plugin.key,\n },\n logger: this.logger,\n })\n\n await this.addFile(...barrelFiles)\n },\n }\n})\n"]}
|
|
@@ -6,6 +6,7 @@ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSch
|
|
|
6
6
|
type TransformerProps$1 = {
|
|
7
7
|
operation: Operation;
|
|
8
8
|
schemas: OperationSchemas;
|
|
9
|
+
casing: 'camelcase' | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
11
12
|
type Suspense = object;
|
|
@@ -86,6 +87,11 @@ type Options$1 = {
|
|
|
86
87
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
87
88
|
*/
|
|
88
89
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
90
|
+
/**
|
|
91
|
+
* How to style your params, by default no casing is applied
|
|
92
|
+
* - 'camelcase' will use camelcase for the params names
|
|
93
|
+
*/
|
|
94
|
+
paramsCasing?: 'camelcase';
|
|
89
95
|
/**
|
|
90
96
|
* How to pass your params
|
|
91
97
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -136,11 +142,13 @@ type Options$1 = {
|
|
|
136
142
|
};
|
|
137
143
|
type ResolvedOptions$1 = {
|
|
138
144
|
output: Output;
|
|
145
|
+
group: Options$1['group'];
|
|
139
146
|
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
140
147
|
baseURL?: string;
|
|
141
148
|
};
|
|
142
149
|
parser: Required<NonNullable<Options$1['parser']>>;
|
|
143
150
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
151
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
144
152
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
145
153
|
/**
|
|
146
154
|
* Only used of infinite
|
|
@@ -157,6 +165,7 @@ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, Re
|
|
|
157
165
|
type TransformerProps = {
|
|
158
166
|
operation: Operation;
|
|
159
167
|
schemas: OperationSchemas;
|
|
168
|
+
casing: 'camelcase' | undefined;
|
|
160
169
|
};
|
|
161
170
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
162
171
|
/**
|
|
@@ -224,6 +233,11 @@ type Options = {
|
|
|
224
233
|
query?: Query | false;
|
|
225
234
|
mutationKey?: MutationKey;
|
|
226
235
|
mutation?: Mutation | false;
|
|
236
|
+
/**
|
|
237
|
+
* How to style your params, by default no casing is applied
|
|
238
|
+
* - 'camelcase' will use camelcase for the params names
|
|
239
|
+
*/
|
|
240
|
+
paramsCasing?: 'camelcase';
|
|
227
241
|
/**
|
|
228
242
|
* How to pass your params
|
|
229
243
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -264,8 +278,10 @@ type ResolvedOptions = {
|
|
|
264
278
|
query: NonNullable<Required<Query>> | false;
|
|
265
279
|
mutationKey: MutationKey | undefined;
|
|
266
280
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
281
|
+
paramsCasing: Options['paramsCasing'];
|
|
267
282
|
paramsType: NonNullable<Options['paramsType']>;
|
|
268
283
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
284
|
+
group: Options['group'];
|
|
269
285
|
};
|
|
270
286
|
type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
271
287
|
|
|
@@ -6,6 +6,7 @@ import { ResolvePathOptions, Exclude, Include, Override, Generator, OperationSch
|
|
|
6
6
|
type TransformerProps$1 = {
|
|
7
7
|
operation: Operation;
|
|
8
8
|
schemas: OperationSchemas;
|
|
9
|
+
casing: 'camelcase' | undefined;
|
|
9
10
|
};
|
|
10
11
|
type Transformer$1 = (props: TransformerProps$1) => unknown[];
|
|
11
12
|
type Suspense = object;
|
|
@@ -86,6 +87,11 @@ type Options$1 = {
|
|
|
86
87
|
* Array containing override parameters to override `options` based on tags/operations/methods/paths.
|
|
87
88
|
*/
|
|
88
89
|
override?: Array<Override<ResolvedOptions$1>>;
|
|
90
|
+
/**
|
|
91
|
+
* How to style your params, by default no casing is applied
|
|
92
|
+
* - 'camelcase' will use camelcase for the params names
|
|
93
|
+
*/
|
|
94
|
+
paramsCasing?: 'camelcase';
|
|
89
95
|
/**
|
|
90
96
|
* How to pass your params
|
|
91
97
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -136,11 +142,13 @@ type Options$1 = {
|
|
|
136
142
|
};
|
|
137
143
|
type ResolvedOptions$1 = {
|
|
138
144
|
output: Output;
|
|
145
|
+
group: Options$1['group'];
|
|
139
146
|
client: Required<Omit<NonNullable<PluginReactQuery['options']['client']>, 'baseURL'>> & {
|
|
140
147
|
baseURL?: string;
|
|
141
148
|
};
|
|
142
149
|
parser: Required<NonNullable<Options$1['parser']>>;
|
|
143
150
|
pathParamsType: NonNullable<Options$1['pathParamsType']>;
|
|
151
|
+
paramsCasing: Options$1['paramsCasing'];
|
|
144
152
|
paramsType: NonNullable<Options$1['paramsType']>;
|
|
145
153
|
/**
|
|
146
154
|
* Only used of infinite
|
|
@@ -157,6 +165,7 @@ type PluginReactQuery = PluginFactoryOptions<'plugin-react-query', Options$1, Re
|
|
|
157
165
|
type TransformerProps = {
|
|
158
166
|
operation: Operation;
|
|
159
167
|
schemas: OperationSchemas;
|
|
168
|
+
casing: 'camelcase' | undefined;
|
|
160
169
|
};
|
|
161
170
|
type Transformer = (props: TransformerProps) => unknown[];
|
|
162
171
|
/**
|
|
@@ -224,6 +233,11 @@ type Options = {
|
|
|
224
233
|
query?: Query | false;
|
|
225
234
|
mutationKey?: MutationKey;
|
|
226
235
|
mutation?: Mutation | false;
|
|
236
|
+
/**
|
|
237
|
+
* How to style your params, by default no casing is applied
|
|
238
|
+
* - 'camelcase' will use camelcase for the params names
|
|
239
|
+
*/
|
|
240
|
+
paramsCasing?: 'camelcase';
|
|
227
241
|
/**
|
|
228
242
|
* How to pass your params
|
|
229
243
|
* - 'object' will return the params and pathParams as an object.
|
|
@@ -264,8 +278,10 @@ type ResolvedOptions = {
|
|
|
264
278
|
query: NonNullable<Required<Query>> | false;
|
|
265
279
|
mutationKey: MutationKey | undefined;
|
|
266
280
|
mutation: NonNullable<Required<Mutation>> | false;
|
|
281
|
+
paramsCasing: Options['paramsCasing'];
|
|
267
282
|
paramsType: NonNullable<Options['paramsType']>;
|
|
268
283
|
pathParamsType: NonNullable<Options['pathParamsType']>;
|
|
284
|
+
group: Options['group'];
|
|
269
285
|
};
|
|
270
286
|
type PluginSwr = PluginFactoryOptions<'plugin-swr', Options, ResolvedOptions, never, ResolvePathOptions>;
|
|
271
287
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kubb/plugin-swr",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0",
|
|
4
4
|
"description": "Generator plugin-swr",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -64,22 +64,22 @@
|
|
|
64
64
|
],
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"remeda": "^2.17.4",
|
|
67
|
-
"@kubb/core": "3.0
|
|
68
|
-
"@kubb/fs": "3.0
|
|
69
|
-
"@kubb/oas": "3.0
|
|
70
|
-
"@kubb/plugin-client": "3.0
|
|
71
|
-
"@kubb/plugin-oas": "3.0
|
|
72
|
-
"@kubb/plugin-ts": "3.0
|
|
73
|
-
"@kubb/plugin-zod": "3.0
|
|
74
|
-
"@kubb/react": "3.0
|
|
67
|
+
"@kubb/core": "3.2.0",
|
|
68
|
+
"@kubb/fs": "3.2.0",
|
|
69
|
+
"@kubb/oas": "3.2.0",
|
|
70
|
+
"@kubb/plugin-client": "3.2.0",
|
|
71
|
+
"@kubb/plugin-oas": "3.2.0",
|
|
72
|
+
"@kubb/plugin-ts": "3.2.0",
|
|
73
|
+
"@kubb/plugin-zod": "3.2.0",
|
|
74
|
+
"@kubb/react": "3.2.0"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@types/react": "^18.3.
|
|
77
|
+
"@types/react": "^18.3.16",
|
|
78
78
|
"react": "^18.3.1",
|
|
79
79
|
"tsup": "^8.3.5",
|
|
80
80
|
"typescript": "^5.7.2",
|
|
81
|
-
"@kubb/config-ts": "3.0
|
|
82
|
-
"@kubb/config-tsup": "3.0
|
|
81
|
+
"@kubb/config-ts": "3.2.0",
|
|
82
|
+
"@kubb/config-tsup": "3.2.0"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
85
|
"@kubb/react": "^3.0.0"
|
|
@@ -19,25 +19,27 @@ type Props = {
|
|
|
19
19
|
mutationKeyTypeName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
21
|
operation: Operation
|
|
22
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
22
23
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
23
24
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
24
25
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type GetParamsProps = {
|
|
29
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
28
30
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
29
31
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
30
32
|
typeSchemas: OperationSchemas
|
|
31
33
|
mutationKeyTypeName: string
|
|
32
34
|
}
|
|
33
35
|
// TODO add same logic as being done for react-query mutations
|
|
34
|
-
function getParams({ pathParamsType, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
|
|
36
|
+
function getParams({ pathParamsType, paramsCasing, dataReturnType, typeSchemas, mutationKeyTypeName }: GetParamsProps) {
|
|
35
37
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
36
38
|
|
|
37
39
|
return FunctionParams.factory({
|
|
38
40
|
pathParams: {
|
|
39
41
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
40
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
42
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
41
43
|
},
|
|
42
44
|
params: typeSchemas.queryParams?.name
|
|
43
45
|
? {
|
|
@@ -70,6 +72,7 @@ export function Mutation({
|
|
|
70
72
|
mutationKeyName,
|
|
71
73
|
mutationKeyTypeName,
|
|
72
74
|
paramsType,
|
|
75
|
+
paramsCasing,
|
|
73
76
|
pathParamsType,
|
|
74
77
|
dataReturnType,
|
|
75
78
|
typeSchemas,
|
|
@@ -89,6 +92,7 @@ export function Mutation({
|
|
|
89
92
|
})
|
|
90
93
|
|
|
91
94
|
const params = getParams({
|
|
95
|
+
paramsCasing,
|
|
92
96
|
pathParamsType,
|
|
93
97
|
dataReturnType,
|
|
94
98
|
typeSchemas,
|
|
@@ -96,6 +100,7 @@ export function Mutation({
|
|
|
96
100
|
})
|
|
97
101
|
|
|
98
102
|
const clientParams = Client.getParams({
|
|
103
|
+
paramsCasing,
|
|
99
104
|
paramsType,
|
|
100
105
|
typeSchemas,
|
|
101
106
|
pathParamsType,
|
|
@@ -11,6 +11,7 @@ type Props = {
|
|
|
11
11
|
typeName: string
|
|
12
12
|
typeSchemas: OperationSchemas
|
|
13
13
|
operation: Operation
|
|
14
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
14
15
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
15
16
|
transformer: Transformer | undefined
|
|
16
17
|
}
|
|
@@ -24,15 +25,15 @@ function getParams({}: GetParamsProps) {
|
|
|
24
25
|
return FunctionParams.factory({})
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
const getTransformer: Transformer = ({ operation }) => {
|
|
28
|
-
const path = new URLPath(operation.path)
|
|
28
|
+
const getTransformer: Transformer = ({ operation, casing }) => {
|
|
29
|
+
const path = new URLPath(operation.path, { casing })
|
|
29
30
|
|
|
30
31
|
return [JSON.stringify({ url: path.path })].filter(Boolean)
|
|
31
32
|
}
|
|
32
33
|
|
|
33
|
-
export function MutationKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
|
+
export function MutationKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
34
35
|
const params = getParams({ pathParamsType, typeSchemas })
|
|
35
|
-
const keys = transformer({ operation, schemas: typeSchemas })
|
|
36
|
+
const keys = transformer({ operation, schemas: typeSchemas, casing: paramsCasing })
|
|
36
37
|
|
|
37
38
|
return (
|
|
38
39
|
<>
|
package/src/components/Query.tsx
CHANGED
|
@@ -18,6 +18,7 @@ type Props = {
|
|
|
18
18
|
queryKeyName: string
|
|
19
19
|
queryKeyTypeName: string
|
|
20
20
|
typeSchemas: OperationSchemas
|
|
21
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
21
22
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
22
23
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
23
24
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
@@ -25,6 +26,7 @@ type Props = {
|
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
type GetParamsProps = {
|
|
29
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
28
30
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
29
31
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
30
32
|
dataReturnType: PluginSwr['resolvedOptions']['client']['dataReturnType']
|
|
@@ -32,7 +34,7 @@ type GetParamsProps = {
|
|
|
32
34
|
typeSchemas: OperationSchemas
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, queryKeyTypeName }: GetParamsProps) {
|
|
37
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, dataReturnType, typeSchemas, queryKeyTypeName }: GetParamsProps) {
|
|
36
38
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
37
39
|
|
|
38
40
|
if (paramsType === 'object') {
|
|
@@ -40,7 +42,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, qu
|
|
|
40
42
|
data: {
|
|
41
43
|
mode: 'object',
|
|
42
44
|
children: {
|
|
43
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
45
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
44
46
|
data: typeSchemas.request?.name
|
|
45
47
|
? {
|
|
46
48
|
type: typeSchemas.request?.name,
|
|
@@ -78,7 +80,7 @@ function getParams({ paramsType, pathParamsType, dataReturnType, typeSchemas, qu
|
|
|
78
80
|
pathParams: typeSchemas.pathParams?.name
|
|
79
81
|
? {
|
|
80
82
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
81
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
83
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
82
84
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
83
85
|
}
|
|
84
86
|
: undefined,
|
|
@@ -122,6 +124,7 @@ export function Query({
|
|
|
122
124
|
operation,
|
|
123
125
|
dataReturnType,
|
|
124
126
|
paramsType,
|
|
127
|
+
paramsCasing,
|
|
125
128
|
pathParamsType,
|
|
126
129
|
}: Props): ReactNode {
|
|
127
130
|
const TData = dataReturnType === 'data' ? typeSchemas.response.name : `ResponseConfig<${typeSchemas.response.name}>`
|
|
@@ -130,8 +133,10 @@ export function Query({
|
|
|
130
133
|
const queryKeyParams = QueryKey.getParams({
|
|
131
134
|
pathParamsType,
|
|
132
135
|
typeSchemas,
|
|
136
|
+
paramsCasing,
|
|
133
137
|
})
|
|
134
138
|
const params = getParams({
|
|
139
|
+
paramsCasing,
|
|
135
140
|
paramsType,
|
|
136
141
|
pathParamsType,
|
|
137
142
|
dataReturnType,
|
|
@@ -140,6 +145,7 @@ export function Query({
|
|
|
140
145
|
})
|
|
141
146
|
|
|
142
147
|
const queryOptionsParams = QueryOptions.getParams({
|
|
148
|
+
paramsCasing,
|
|
143
149
|
paramsType,
|
|
144
150
|
pathParamsType,
|
|
145
151
|
typeSchemas,
|
|
@@ -12,20 +12,22 @@ type Props = {
|
|
|
12
12
|
typeName: string
|
|
13
13
|
typeSchemas: OperationSchemas
|
|
14
14
|
operation: Operation
|
|
15
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
15
16
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
16
17
|
transformer: Transformer | undefined
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
type GetParamsProps = {
|
|
21
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
20
22
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
21
23
|
typeSchemas: OperationSchemas
|
|
22
24
|
}
|
|
23
25
|
|
|
24
|
-
function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
26
|
+
function getParams({ pathParamsType, paramsCasing, typeSchemas }: GetParamsProps) {
|
|
25
27
|
return FunctionParams.factory({
|
|
26
28
|
pathParams: {
|
|
27
29
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
28
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
30
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
29
31
|
},
|
|
30
32
|
data: typeSchemas.request?.name
|
|
31
33
|
? {
|
|
@@ -42,8 +44,8 @@ function getParams({ pathParamsType, typeSchemas }: GetParamsProps) {
|
|
|
42
44
|
})
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
46
|
-
const path = new URLPath(operation.path)
|
|
47
|
+
const getTransformer: Transformer = ({ operation, schemas, casing }) => {
|
|
48
|
+
const path = new URLPath(operation.path, { casing })
|
|
47
49
|
const keys = [
|
|
48
50
|
path.toObject({
|
|
49
51
|
type: 'path',
|
|
@@ -56,11 +58,12 @@ const getTransformer: Transformer = ({ operation, schemas }) => {
|
|
|
56
58
|
return keys
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export function QueryKey({ name, typeSchemas, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
60
|
-
const params = getParams({ pathParamsType, typeSchemas })
|
|
61
|
+
export function QueryKey({ name, typeSchemas, paramsCasing, pathParamsType, operation, typeName, transformer = getTransformer }: Props): ReactNode {
|
|
62
|
+
const params = getParams({ pathParamsType, paramsCasing, typeSchemas })
|
|
61
63
|
const keys = transformer({
|
|
62
64
|
operation,
|
|
63
65
|
schemas: typeSchemas,
|
|
66
|
+
casing: paramsCasing,
|
|
64
67
|
})
|
|
65
68
|
|
|
66
69
|
return (
|
|
@@ -12,23 +12,25 @@ type Props = {
|
|
|
12
12
|
name: string
|
|
13
13
|
clientName: string
|
|
14
14
|
typeSchemas: OperationSchemas
|
|
15
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
15
16
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
16
17
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
type GetParamsProps = {
|
|
20
21
|
paramsType: PluginSwr['resolvedOptions']['paramsType']
|
|
22
|
+
paramsCasing: PluginSwr['resolvedOptions']['paramsCasing']
|
|
21
23
|
pathParamsType: PluginSwr['resolvedOptions']['pathParamsType']
|
|
22
24
|
typeSchemas: OperationSchemas
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
27
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }: GetParamsProps) {
|
|
26
28
|
if (paramsType === 'object') {
|
|
27
29
|
return FunctionParams.factory({
|
|
28
30
|
data: {
|
|
29
31
|
mode: 'object',
|
|
30
32
|
children: {
|
|
31
|
-
...getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
33
|
+
...getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
32
34
|
data: typeSchemas.request?.name
|
|
33
35
|
? {
|
|
34
36
|
type: typeSchemas.request?.name,
|
|
@@ -60,7 +62,7 @@ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps)
|
|
|
60
62
|
pathParams: typeSchemas.pathParams?.name
|
|
61
63
|
? {
|
|
62
64
|
mode: pathParamsType === 'object' ? 'object' : 'inlineSpread',
|
|
63
|
-
children: getPathParams(typeSchemas.pathParams, { typed: true }),
|
|
65
|
+
children: getPathParams(typeSchemas.pathParams, { typed: true, casing: paramsCasing }),
|
|
64
66
|
optional: isOptional(typeSchemas.pathParams?.schema),
|
|
65
67
|
}
|
|
66
68
|
: undefined,
|
|
@@ -89,9 +91,10 @@ function getParams({ paramsType, pathParamsType, typeSchemas }: GetParamsProps)
|
|
|
89
91
|
})
|
|
90
92
|
}
|
|
91
93
|
|
|
92
|
-
export function QueryOptions({ name, clientName, typeSchemas, paramsType, pathParamsType }: Props): ReactNode {
|
|
93
|
-
const params = getParams({ paramsType, pathParamsType, typeSchemas })
|
|
94
|
+
export function QueryOptions({ name, clientName, typeSchemas, paramsCasing, paramsType, pathParamsType }: Props): ReactNode {
|
|
95
|
+
const params = getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas })
|
|
94
96
|
const clientParams = Client.getParams({
|
|
97
|
+
paramsCasing,
|
|
95
98
|
paramsType,
|
|
96
99
|
typeSchemas,
|
|
97
100
|
pathParamsType,
|
|
@@ -84,6 +84,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
84
84
|
operation={operation}
|
|
85
85
|
pathParamsType={options.pathParamsType}
|
|
86
86
|
typeSchemas={type.schemas}
|
|
87
|
+
paramsCasing={options.paramsCasing}
|
|
87
88
|
transformer={options.mutationKey}
|
|
88
89
|
/>
|
|
89
90
|
|
|
@@ -96,6 +97,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
96
97
|
typeSchemas={type.schemas}
|
|
97
98
|
zodSchemas={zod.schemas}
|
|
98
99
|
dataReturnType={options.client.dataReturnType}
|
|
100
|
+
paramsCasing={options.paramsCasing}
|
|
99
101
|
paramsType={options.paramsType}
|
|
100
102
|
pathParamsType={options.pathParamsType}
|
|
101
103
|
parser={options.parser}
|
|
@@ -109,6 +111,7 @@ export const mutationGenerator = createReactGenerator<PluginSwr>({
|
|
|
109
111
|
operation={operation}
|
|
110
112
|
dataReturnType={options.client.dataReturnType}
|
|
111
113
|
paramsType={options.paramsType}
|
|
114
|
+
paramsCasing={options.paramsCasing}
|
|
112
115
|
pathParamsType={options.pathParamsType}
|
|
113
116
|
mutationKeyName={mutationKey.name}
|
|
114
117
|
mutationKeyTypeName={mutationKey.typeName}
|
|
@@ -86,6 +86,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
86
86
|
operation={operation}
|
|
87
87
|
pathParamsType={options.pathParamsType}
|
|
88
88
|
typeSchemas={type.schemas}
|
|
89
|
+
paramsCasing={options.paramsCasing}
|
|
89
90
|
transformer={options.queryKey}
|
|
90
91
|
/>
|
|
91
92
|
<Client
|
|
@@ -97,6 +98,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
97
98
|
typeSchemas={type.schemas}
|
|
98
99
|
zodSchemas={zod.schemas}
|
|
99
100
|
dataReturnType={options.client.dataReturnType}
|
|
101
|
+
paramsCasing={options.paramsCasing}
|
|
100
102
|
paramsType={options.paramsType}
|
|
101
103
|
pathParamsType={options.pathParamsType}
|
|
102
104
|
parser={options.parser}
|
|
@@ -106,6 +108,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
106
108
|
clientName={client.name}
|
|
107
109
|
typeSchemas={type.schemas}
|
|
108
110
|
paramsType={options.paramsType}
|
|
111
|
+
paramsCasing={options.paramsCasing}
|
|
109
112
|
pathParamsType={options.pathParamsType}
|
|
110
113
|
/>
|
|
111
114
|
{options.query && (
|
|
@@ -121,6 +124,7 @@ export const queryGenerator = createReactGenerator<PluginSwr>({
|
|
|
121
124
|
operation={operation}
|
|
122
125
|
dataReturnType={options.client.dataReturnType}
|
|
123
126
|
queryKeyName={queryKey.name}
|
|
127
|
+
paramsCasing={options.paramsCasing}
|
|
124
128
|
queryKeyTypeName={queryKey.typeName}
|
|
125
129
|
/>
|
|
126
130
|
</>
|