@kubb/plugin-fetch 5.0.0-beta.85 → 5.0.0-beta.86
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/index.cjs +74 -94
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +8 -19
- package/dist/index.js +75 -95
- package/dist/index.js.map +1 -1
- package/package.json +6 -7
- package/src/generators/clientGenerator.tsx +11 -9
- package/src/plugin.ts +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __name } from "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ast } from "kubb/kit";
|
|
2
|
+
import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
|
|
3
3
|
//#region ../../internals/client/src/types.d.ts
|
|
4
4
|
/**
|
|
5
5
|
* Validator applied to request and response bodies using schemas from `@kubb/plugin-zod`.
|
|
@@ -21,39 +21,28 @@ type ValidatorOptions = false | 'zod' | {
|
|
|
21
21
|
*/
|
|
22
22
|
type Mode = 'tag' | 'flat';
|
|
23
23
|
/**
|
|
24
|
-
* The resolver shared by the client plugins.
|
|
25
|
-
* a `
|
|
24
|
+
* The resolver shared by the client plugins. Inherits the built-in camelCase `name` and `file`;
|
|
25
|
+
* classes and tag groups use PascalCase (with a `Client` suffix for groups).
|
|
26
26
|
*/
|
|
27
27
|
type ResolverClient = Resolver & {
|
|
28
|
-
/**
|
|
29
|
-
* Resolves the function name for a raw operation name.
|
|
30
|
-
*
|
|
31
|
-
* @example
|
|
32
|
-
* `resolver.resolveName('show pet by id') // -> 'showPetById'`
|
|
33
|
-
*/
|
|
34
|
-
resolveName(this: ResolverClient, name: string): string;
|
|
35
|
-
/**
|
|
36
|
-
* Resolves the output file name for a generated client module.
|
|
37
|
-
*/
|
|
38
|
-
resolvePathName(this: ResolverClient, name: string, type?: 'file' | 'function' | 'type' | 'const'): string;
|
|
39
28
|
/**
|
|
40
29
|
* Resolves the generated class name for class-based clients.
|
|
41
30
|
*/
|
|
42
|
-
|
|
31
|
+
className(this: ResolverClient, name: string): string;
|
|
43
32
|
/**
|
|
44
33
|
* Resolves the generated class name for a tag-based client group. The default appends a
|
|
45
34
|
* `Client` suffix (tag `pet` becomes `PetClient`) so the class never collides with the schema
|
|
46
35
|
* model of the same name in the barrel.
|
|
47
36
|
*
|
|
48
37
|
* @example
|
|
49
|
-
* `resolver.
|
|
38
|
+
* `resolver.groupName('pet') // -> 'PetClient'`
|
|
50
39
|
*/
|
|
51
|
-
|
|
40
|
+
groupName(this: ResolverClient, name: string): string;
|
|
52
41
|
/**
|
|
53
42
|
* Resolves the property name a tag client is exposed under on the composed root SDK
|
|
54
43
|
* (`new PetStore(config).pet`).
|
|
55
44
|
*/
|
|
56
|
-
|
|
45
|
+
propertyName(this: ResolverClient, name: string): string;
|
|
57
46
|
};
|
|
58
47
|
/**
|
|
59
48
|
* The shared options surface for the client plugins. Deliberately small: there is one
|
|
@@ -134,7 +123,7 @@ type Options = OutputOptions & {
|
|
|
134
123
|
/**
|
|
135
124
|
* Override how names and file paths are built. Methods you omit fall back to the default resolver.
|
|
136
125
|
*/
|
|
137
|
-
resolver?:
|
|
126
|
+
resolver?: ResolverPatch<ResolverClient>;
|
|
138
127
|
/**
|
|
139
128
|
* Macros applied to each operation node before code is printed.
|
|
140
129
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { ast, defineGenerator, definePlugin
|
|
3
|
+
import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
|
|
4
4
|
import { File, Function, jsxRenderer } from "kubb/jsx";
|
|
5
5
|
import { createFunctionParameter, createFunctionParameters, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
@@ -45,31 +45,6 @@ function pascalCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
45
45
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
46
46
|
}
|
|
47
47
|
//#endregion
|
|
48
|
-
//#region ../../internals/utils/src/fs.ts
|
|
49
|
-
/**
|
|
50
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
51
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
52
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
53
|
-
*
|
|
54
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
55
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
56
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
57
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
58
|
-
*
|
|
59
|
-
* @example Nested path from a dotted name
|
|
60
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
61
|
-
*
|
|
62
|
-
* @example PascalCase the final segment
|
|
63
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
64
|
-
*
|
|
65
|
-
* @example Suffix applied to the final segment only
|
|
66
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
67
|
-
*/
|
|
68
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
69
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
70
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
71
|
-
}
|
|
72
|
-
//#endregion
|
|
73
48
|
//#region ../../internals/utils/src/reserved.ts
|
|
74
49
|
/**
|
|
75
50
|
* JavaScript and Java reserved words.
|
|
@@ -193,6 +168,23 @@ function ensureValidVarName(name) {
|
|
|
193
168
|
return `_${name}`;
|
|
194
169
|
}
|
|
195
170
|
//#endregion
|
|
171
|
+
//#region ../../internals/utils/src/codegen.ts
|
|
172
|
+
/**
|
|
173
|
+
* Builds a JSDoc comment block from an array of lines. Returns `fallback` when there are no
|
|
174
|
+
* comments.
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```ts
|
|
178
|
+
* buildJSDoc(['@type string', '@example hello'])
|
|
179
|
+
* // '/**\n * @type string\n * @example hello\n *\/\n '
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
function buildJSDoc(comments, options = {}) {
|
|
183
|
+
const { indent = " * ", suffix = "\n ", fallback = " " } = options;
|
|
184
|
+
if (comments.length === 0) return fallback;
|
|
185
|
+
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
196
188
|
//#region ../../internals/utils/src/url.ts
|
|
197
189
|
function transformParam(raw, casing) {
|
|
198
190
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -373,13 +365,13 @@ function buildParamsRemapExpression({ source, mapping }) {
|
|
|
373
365
|
//#region ../../internals/shared/src/operation.ts
|
|
374
366
|
/**
|
|
375
367
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
376
|
-
* `resolver.
|
|
368
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
377
369
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
378
370
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
379
371
|
*
|
|
380
372
|
* @example
|
|
381
373
|
* ```ts
|
|
382
|
-
* resolver.
|
|
374
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
383
375
|
* ```
|
|
384
376
|
*/
|
|
385
377
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -602,7 +594,7 @@ function resolveResponseValidator(validator) {
|
|
|
602
594
|
* `<operation>ResponseSchema` is used; error bodies are never zod-parsed.
|
|
603
595
|
*/
|
|
604
596
|
function buildZodResponseParse(node, zodResolver) {
|
|
605
|
-
const name = zodResolver.
|
|
597
|
+
const name = zodResolver.response.response(node);
|
|
606
598
|
return name ? {
|
|
607
599
|
expression: name,
|
|
608
600
|
importNames: [name]
|
|
@@ -615,7 +607,7 @@ function buildZodResponseParse(node, zodResolver) {
|
|
|
615
607
|
*/
|
|
616
608
|
function buildZodErrorParse(node, zodResolver) {
|
|
617
609
|
if (!node.responses.some((res) => !isSuccessStatusCode(res.statusCode) && res.content?.some((entry) => entry.schema))) return null;
|
|
618
|
-
const name = zodResolver.
|
|
610
|
+
const name = zodResolver.response.error?.(node);
|
|
619
611
|
return name ? {
|
|
620
612
|
expression: name,
|
|
621
613
|
importNames: [name]
|
|
@@ -732,7 +724,7 @@ function buildParamsRemap({ node }) {
|
|
|
732
724
|
* `buildRequestResultGenerics({ node, tsResolver }) // 'AddPetResponses, ThrowOnError'`
|
|
733
725
|
*/
|
|
734
726
|
function buildRequestResultGenerics({ node, tsResolver }) {
|
|
735
|
-
return `${tsResolver.
|
|
727
|
+
return `${tsResolver.response.responses(node)}, ThrowOnError`;
|
|
736
728
|
}
|
|
737
729
|
//#endregion
|
|
738
730
|
//#region ../../internals/client/src/builders/returnStatement.ts
|
|
@@ -755,30 +747,30 @@ function buildReturnStatement({ node, tsResolver, callConfig }) {
|
|
|
755
747
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
756
748
|
/**
|
|
757
749
|
* Builds the grouped-options signature for one operation: a single `options` object whose `TData`
|
|
758
|
-
* is the plugin-ts `<Name>
|
|
750
|
+
* is the plugin-ts `<Name>Options` (carrying a literal `url`), and a `RequestResult` return type
|
|
759
751
|
* keyed to the plugin-ts per-status responses record. There are no positional arguments.
|
|
760
752
|
*
|
|
761
|
-
* The generated file imports `<Name>
|
|
753
|
+
* The generated file imports `<Name>Options` and `<Name>Responses` and uses them directly, so no
|
|
762
754
|
* per-operation input type has to be emitted.
|
|
763
755
|
*/
|
|
764
756
|
function buildGroupedOptionsSignature({ node, tsResolver }) {
|
|
765
|
-
const
|
|
766
|
-
const responsesName = tsResolver.
|
|
757
|
+
const optionsName = tsResolver.response.options(node);
|
|
758
|
+
const responsesName = tsResolver.response.responses(node);
|
|
767
759
|
const resultGenerics = buildRequestResultGenerics({
|
|
768
760
|
node,
|
|
769
761
|
tsResolver
|
|
770
762
|
});
|
|
771
763
|
const { isOptional } = getRequestGroupOptionality(node);
|
|
772
764
|
return {
|
|
773
|
-
dataTypeName:
|
|
765
|
+
dataTypeName: optionsName,
|
|
774
766
|
paramsSignature: declarationPrinter.print(createFunctionParameters({ params: [createFunctionParameter({
|
|
775
767
|
name: "options",
|
|
776
|
-
type: `Options<${
|
|
768
|
+
type: `Options<${optionsName}, ThrowOnError>`,
|
|
777
769
|
...isOptional ? { default: "{}" } : {}
|
|
778
770
|
})] })) ?? "",
|
|
779
771
|
returnType: `Promise<RequestResult<${resultGenerics}>>`,
|
|
780
772
|
generics: ["ThrowOnError extends boolean = true"],
|
|
781
|
-
importedTypeNames: [
|
|
773
|
+
importedTypeNames: [optionsName, responsesName]
|
|
782
774
|
};
|
|
783
775
|
}
|
|
784
776
|
//#endregion
|
|
@@ -844,7 +836,7 @@ function buildStyles({ node }) {
|
|
|
844
836
|
function buildValidatorHooks({ node, validator, zodResolver }) {
|
|
845
837
|
const importedZodNames = [];
|
|
846
838
|
const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
|
|
847
|
-
const zodRequestName = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.
|
|
839
|
+
const zodRequestName = zodResolver && resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body(node) : null;
|
|
848
840
|
const request = zodRequestName ?? null;
|
|
849
841
|
if (zodRequestName) importedZodNames.push(zodRequestName);
|
|
850
842
|
const responseParse = zodResolver && resolveResponseValidator(validator) === "zod" ? buildZodResponseParse(node, zodResolver) : null;
|
|
@@ -904,7 +896,7 @@ function Operation({ name, node, tsResolver, zodResolver, validator, security, i
|
|
|
904
896
|
"...config",
|
|
905
897
|
...buildParamsRemap({ node })
|
|
906
898
|
].filter(Boolean).join(", ")} }`;
|
|
907
|
-
const eventType = `SuccessOf<${tsResolver.
|
|
899
|
+
const eventType = `SuccessOf<${tsResolver.response.responses(node)}>`;
|
|
908
900
|
const returnType = eventStream ? `Promise<EventStreamResult<${eventType}>>` : signature.returnType;
|
|
909
901
|
const returnStatement = eventStream ? `return toEventStream<${eventType}>(request(${callConfig}))` : buildReturnStatement({
|
|
910
902
|
node,
|
|
@@ -982,7 +974,7 @@ function buildSdkMethod({ node, name, tsResolver, zodResolver, validator, securi
|
|
|
982
974
|
})
|
|
983
975
|
});
|
|
984
976
|
const generics = signature.generics.length ? `<${signature.generics.join(", ")}>` : "";
|
|
985
|
-
const jsdoc =
|
|
977
|
+
const jsdoc = buildJSDoc(buildOperationComments(node, {
|
|
986
978
|
link: "urlPath",
|
|
987
979
|
linkPosition: "beforeDeprecated",
|
|
988
980
|
splitLines: true
|
|
@@ -1052,15 +1044,15 @@ function SdkFacade({ name, isExportable = true, isIndexable = true, members, chi
|
|
|
1052
1044
|
//#endregion
|
|
1053
1045
|
//#region ../../internals/client/src/generators/sdkGenerator.tsx
|
|
1054
1046
|
function resolveTypeImportNames(node, tsResolver) {
|
|
1055
|
-
return [tsResolver.
|
|
1047
|
+
return [tsResolver.response.options(node), tsResolver.response.responses(node)];
|
|
1056
1048
|
}
|
|
1057
1049
|
function resolveZodImportNames(node, zodResolver, validator) {
|
|
1058
1050
|
const { query: queryParams } = getOperationParameters(node, { paramsCasing: "original" });
|
|
1059
1051
|
return [
|
|
1060
|
-
resolveResponseValidator(validator) === "zod" ? zodResolver.
|
|
1052
|
+
resolveResponseValidator(validator) === "zod" ? zodResolver.response.response(node) : null,
|
|
1061
1053
|
resolveResponseValidator(validator) === "zod" ? buildZodErrorParse(node, zodResolver)?.expression ?? null : null,
|
|
1062
|
-
resolveRequestValidator(validator) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.
|
|
1063
|
-
resolveQueryParamsValidator(validator) === "zod" && queryParams.length > 0 ? zodResolver.
|
|
1054
|
+
resolveRequestValidator(validator) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.response.body(node) : null,
|
|
1055
|
+
resolveQueryParamsValidator(validator) === "zod" && queryParams.length > 0 ? zodResolver.param.query(node, queryParams[0]) : null
|
|
1064
1056
|
].filter((n) => Boolean(n));
|
|
1065
1057
|
}
|
|
1066
1058
|
/**
|
|
@@ -1077,12 +1069,14 @@ function buildControllers(nodes, ctx) {
|
|
|
1077
1069
|
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1078
1070
|
const document = ctx.adapter.document;
|
|
1079
1071
|
function buildOperationData(node) {
|
|
1080
|
-
const typeFile = tsResolver.
|
|
1072
|
+
const typeFile = tsResolver.file({
|
|
1073
|
+
...operationFileEntry(node, node.operationId),
|
|
1081
1074
|
root,
|
|
1082
1075
|
output: tsPluginOptions?.output ?? output,
|
|
1083
1076
|
group: tsPluginOptions?.group
|
|
1084
1077
|
});
|
|
1085
|
-
const zodFile = zodResolver && pluginZod?.options ? zodResolver.
|
|
1078
|
+
const zodFile = zodResolver && pluginZod?.options ? zodResolver.file({
|
|
1079
|
+
...operationFileEntry(node, node.operationId),
|
|
1086
1080
|
root,
|
|
1087
1081
|
output: pluginZod.options?.output ?? output,
|
|
1088
1082
|
group: pluginZod.options?.group ?? void 0
|
|
@@ -1094,7 +1088,7 @@ function buildControllers(nodes, ctx) {
|
|
|
1094
1088
|
}) : void 0;
|
|
1095
1089
|
return {
|
|
1096
1090
|
node,
|
|
1097
|
-
name: resolver.
|
|
1091
|
+
name: resolver.name(node.operationId),
|
|
1098
1092
|
tsResolver,
|
|
1099
1093
|
zodResolver,
|
|
1100
1094
|
typeFile,
|
|
@@ -1105,12 +1099,11 @@ function buildControllers(nodes, ctx) {
|
|
|
1105
1099
|
return nodes.reduce((acc, operationNode) => {
|
|
1106
1100
|
if (!ast.isHttpOperationNode(operationNode)) return acc;
|
|
1107
1101
|
const tag = operationNode.tags[0];
|
|
1108
|
-
const name = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.
|
|
1109
|
-
const file = resolver.
|
|
1102
|
+
const name = tag ? group?.name?.({ group: camelCase(tag) }) ?? resolver.groupName(tag) : resolver.className("ApiClient");
|
|
1103
|
+
const file = resolver.file({
|
|
1110
1104
|
name,
|
|
1111
1105
|
extname: ".ts",
|
|
1112
|
-
tag
|
|
1113
|
-
}, {
|
|
1106
|
+
tag,
|
|
1114
1107
|
root,
|
|
1115
1108
|
output,
|
|
1116
1109
|
group: group ?? void 0
|
|
@@ -1164,7 +1157,7 @@ function createSdkGenerator() {
|
|
|
1164
1157
|
if (!ctx.driver.getPlugin(pluginTsName) || !sdk) return null;
|
|
1165
1158
|
const controllers = buildControllers(nodes, ctx);
|
|
1166
1159
|
const clientPath = path.resolve(root, ".kubb/client.ts");
|
|
1167
|
-
const banner = (file) => resolver.
|
|
1160
|
+
const banner = (file) => resolver.default.banner(ctx.meta, {
|
|
1168
1161
|
output,
|
|
1169
1162
|
config,
|
|
1170
1163
|
file: {
|
|
@@ -1172,7 +1165,7 @@ function createSdkGenerator() {
|
|
|
1172
1165
|
baseName: file.baseName
|
|
1173
1166
|
}
|
|
1174
1167
|
});
|
|
1175
|
-
const footer = (file) => resolver.
|
|
1168
|
+
const footer = (file) => resolver.default.footer(ctx.meta, {
|
|
1176
1169
|
output,
|
|
1177
1170
|
config,
|
|
1178
1171
|
file: {
|
|
@@ -1239,28 +1232,26 @@ function createSdkGenerator() {
|
|
|
1239
1232
|
]
|
|
1240
1233
|
}, file.path);
|
|
1241
1234
|
};
|
|
1242
|
-
if (sdk.mode === "flat") return renderClassFile(resolver.
|
|
1235
|
+
if (sdk.mode === "flat") return renderClassFile(resolver.className(sdk.name ?? "sdk"), resolver.file({
|
|
1243
1236
|
name: sdk.name ?? "sdk",
|
|
1244
|
-
extname: ".ts"
|
|
1245
|
-
}, {
|
|
1237
|
+
extname: ".ts",
|
|
1246
1238
|
root,
|
|
1247
1239
|
output,
|
|
1248
1240
|
group: group ?? void 0
|
|
1249
1241
|
}), controllers.flatMap((controller) => controller.operations));
|
|
1250
1242
|
const classFiles = controllers.map(({ name, file, operations: ops }) => renderClassFile(name, file, ops));
|
|
1251
1243
|
if (!sdk.name) return /* @__PURE__ */ jsx(Fragment, { children: classFiles });
|
|
1252
|
-
const sdkFile = resolver.
|
|
1244
|
+
const sdkFile = resolver.file({
|
|
1253
1245
|
name: sdk.name,
|
|
1254
|
-
extname: ".ts"
|
|
1255
|
-
}, {
|
|
1246
|
+
extname: ".ts",
|
|
1256
1247
|
root,
|
|
1257
1248
|
output,
|
|
1258
1249
|
group: group ?? void 0
|
|
1259
1250
|
});
|
|
1260
|
-
const facadeName = resolver.
|
|
1251
|
+
const facadeName = resolver.className(sdk.name);
|
|
1261
1252
|
const members = controllers.map(({ name, tag }) => ({
|
|
1262
1253
|
className: name,
|
|
1263
|
-
propName: resolver.
|
|
1254
|
+
propName: resolver.propertyName(tag ?? name)
|
|
1264
1255
|
}));
|
|
1265
1256
|
return /* @__PURE__ */ jsxs(Fragment, { children: [classFiles, /* @__PURE__ */ jsxs(File, {
|
|
1266
1257
|
baseName: sdkFile.baseName,
|
|
@@ -1300,38 +1291,27 @@ const defaultMacros = [ast.macroSimplifyUnion];
|
|
|
1300
1291
|
//#endregion
|
|
1301
1292
|
//#region ../../internals/client/src/resolver.ts
|
|
1302
1293
|
/**
|
|
1303
|
-
* Default resolver shared by the client plugins. Functions and files
|
|
1304
|
-
* tag groups use PascalCase.
|
|
1294
|
+
* Default resolver shared by the client plugins. Functions and files inherit the built-in camelCase
|
|
1295
|
+
* `name` and `file`; classes and tag groups use PascalCase.
|
|
1305
1296
|
*
|
|
1306
1297
|
* @example
|
|
1307
1298
|
* ```ts
|
|
1308
|
-
* resolverClient.
|
|
1309
|
-
* resolverClient.
|
|
1299
|
+
* resolverClient.name('show pet by id') // 'showPetById'
|
|
1300
|
+
* resolverClient.groupName('pet') // 'PetClient'
|
|
1310
1301
|
* ```
|
|
1311
1302
|
*/
|
|
1312
|
-
const resolverClient =
|
|
1313
|
-
name: "default",
|
|
1303
|
+
const resolverClient = createResolver({
|
|
1314
1304
|
pluginName: "plugin-contract-client",
|
|
1315
|
-
|
|
1316
|
-
if (type === "file") return toFilePath(name);
|
|
1317
|
-
return ensureValidVarName(camelCase(name));
|
|
1318
|
-
},
|
|
1319
|
-
resolveName(name) {
|
|
1320
|
-
return this.default(name, "function");
|
|
1321
|
-
},
|
|
1322
|
-
resolvePathName(name, type) {
|
|
1323
|
-
return this.default(name, type);
|
|
1324
|
-
},
|
|
1325
|
-
resolveClassName(name) {
|
|
1305
|
+
className(name) {
|
|
1326
1306
|
return ensureValidVarName(pascalCase(name));
|
|
1327
1307
|
},
|
|
1328
|
-
|
|
1308
|
+
groupName(name) {
|
|
1329
1309
|
return ensureValidVarName(pascalCase(`${name} Client`));
|
|
1330
1310
|
},
|
|
1331
|
-
|
|
1311
|
+
propertyName(name) {
|
|
1332
1312
|
return ensureValidVarName(camelCase(name));
|
|
1333
1313
|
}
|
|
1334
|
-
})
|
|
1314
|
+
});
|
|
1335
1315
|
//#endregion
|
|
1336
1316
|
//#region src/generators/clientGenerator.tsx
|
|
1337
1317
|
/**
|
|
@@ -1352,25 +1332,28 @@ const clientGenerator = defineGenerator({
|
|
|
1352
1332
|
const pluginZod = resolveResponseValidator(validator) === "zod" || resolveRequestValidator(validator) === "zod" ? driver.getPlugin(pluginZodName) : null;
|
|
1353
1333
|
const zodResolver = pluginZod ? driver.getResolver(pluginZodName) : null;
|
|
1354
1334
|
const hasRequestBody = Boolean(node.requestBody?.content?.[0]?.schema);
|
|
1355
|
-
const importedTypeNames = [tsResolver.
|
|
1335
|
+
const importedTypeNames = [tsResolver.response.options(node), tsResolver.response.responses(node)];
|
|
1356
1336
|
const importedZodNames = zodResolver ? [
|
|
1357
|
-
resolveResponseValidator(validator) === "zod" ? zodResolver.
|
|
1337
|
+
resolveResponseValidator(validator) === "zod" ? zodResolver.response.response?.(node) : null,
|
|
1358
1338
|
resolveResponseValidator(validator) === "zod" ? buildZodErrorParse(node, zodResolver)?.expression ?? null : null,
|
|
1359
|
-
resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.
|
|
1339
|
+
resolveRequestValidator(validator) === "zod" && hasRequestBody ? zodResolver.response.body?.(node) : null
|
|
1360
1340
|
].filter((name) => Boolean(name)) : [];
|
|
1361
1341
|
const meta = {
|
|
1362
|
-
name: resolver.
|
|
1363
|
-
file: resolver.
|
|
1342
|
+
name: resolver.name(node.operationId),
|
|
1343
|
+
file: resolver.file({
|
|
1344
|
+
...operationFileEntry(node, node.operationId),
|
|
1364
1345
|
root,
|
|
1365
1346
|
output,
|
|
1366
1347
|
group: group ?? void 0
|
|
1367
1348
|
}),
|
|
1368
|
-
fileTs: tsResolver.
|
|
1349
|
+
fileTs: tsResolver.file({
|
|
1350
|
+
...operationFileEntry(node, node.operationId),
|
|
1369
1351
|
root,
|
|
1370
1352
|
output: pluginTs.options?.output ?? output,
|
|
1371
1353
|
group: pluginTs.options?.group ?? void 0
|
|
1372
1354
|
}),
|
|
1373
|
-
fileZod: zodResolver && pluginZod?.options ? zodResolver.
|
|
1355
|
+
fileZod: zodResolver && pluginZod?.options ? zodResolver.file({
|
|
1356
|
+
...operationFileEntry(node, node.operationId),
|
|
1374
1357
|
root,
|
|
1375
1358
|
output: pluginZod.options.output ?? output,
|
|
1376
1359
|
group: pluginZod.options?.group ?? void 0
|
|
@@ -1387,7 +1370,7 @@ const clientGenerator = defineGenerator({
|
|
|
1387
1370
|
baseName: meta.file.baseName,
|
|
1388
1371
|
path: meta.file.path,
|
|
1389
1372
|
meta: meta.file.meta,
|
|
1390
|
-
banner: resolver.
|
|
1373
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1391
1374
|
output,
|
|
1392
1375
|
config,
|
|
1393
1376
|
file: {
|
|
@@ -1395,7 +1378,7 @@ const clientGenerator = defineGenerator({
|
|
|
1395
1378
|
baseName: meta.file.baseName
|
|
1396
1379
|
}
|
|
1397
1380
|
}),
|
|
1398
|
-
footer: resolver.
|
|
1381
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1399
1382
|
output,
|
|
1400
1383
|
config,
|
|
1401
1384
|
file: {
|
|
@@ -1499,10 +1482,7 @@ const pluginFetch = definePlugin((options) => {
|
|
|
1499
1482
|
mode: sdk.mode ?? "tag",
|
|
1500
1483
|
name: sdk.name
|
|
1501
1484
|
} : void 0,
|
|
1502
|
-
resolver: userResolver ?
|
|
1503
|
-
...resolverClient,
|
|
1504
|
-
...userResolver
|
|
1505
|
-
} : resolverClient
|
|
1485
|
+
resolver: userResolver ? Resolver.merge(resolverClient, userResolver) : resolverClient
|
|
1506
1486
|
};
|
|
1507
1487
|
const selectedGenerators = resolved.sdk ? [createSdkGenerator()] : [clientGenerator];
|
|
1508
1488
|
return {
|