@kubb/plugin-ts 5.0.0-alpha.26 → 5.0.0-alpha.27
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 +139 -115
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +145 -118
- package/dist/index.js +140 -116
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Type.tsx +8 -39
- package/src/generators/typeGenerator.tsx +40 -19
- package/src/generators/typeGeneratorLegacy.tsx +36 -18
- package/src/index.ts +1 -0
- package/src/plugin.ts +9 -5
- package/src/presets.ts +5 -2
- package/src/printers/printerTs.ts +33 -4
- package/src/resolvers/resolverTs.ts +11 -15
- package/src/resolvers/resolverTsLegacy.ts +8 -8
- package/src/types.ts +31 -18
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import "./chunk--u3MIqq1.js";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { safePrint } from "@kubb/fabric-core/parsers/typescript";
|
|
4
4
|
import { File } from "@kubb/react-fabric";
|
|
5
|
-
import { caseParams, collect,
|
|
5
|
+
import { caseParams, collect, createPrinterFactory, createProperty, createSchema, extractRefName, isStringType, narrowSchema, schemaTypes, syncSchemaRef, transform, walk } from "@kubb/ast";
|
|
6
6
|
import { isNumber } from "remeda";
|
|
7
7
|
import ts from "typescript";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
@@ -532,6 +532,42 @@ function Enum({ node, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
|
|
|
532
532
|
})] });
|
|
533
533
|
}
|
|
534
534
|
//#endregion
|
|
535
|
+
//#region src/components/Type.tsx
|
|
536
|
+
function Type({ name, node, printer, enumType, enumTypeSuffix, enumKeyCasing, resolver }) {
|
|
537
|
+
const enumSchemaNodes = collect(node, { schema(n) {
|
|
538
|
+
const enumNode = narrowSchema(n, schemaTypes.enum);
|
|
539
|
+
if (enumNode?.name) return enumNode;
|
|
540
|
+
} });
|
|
541
|
+
const output = printer.print(node);
|
|
542
|
+
if (!output) return;
|
|
543
|
+
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
544
|
+
return {
|
|
545
|
+
node,
|
|
546
|
+
...getEnumNames({
|
|
547
|
+
node,
|
|
548
|
+
enumType,
|
|
549
|
+
enumTypeSuffix,
|
|
550
|
+
resolver
|
|
551
|
+
})
|
|
552
|
+
};
|
|
553
|
+
});
|
|
554
|
+
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
555
|
+
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
556
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
|
|
557
|
+
node,
|
|
558
|
+
enumType,
|
|
559
|
+
enumTypeSuffix,
|
|
560
|
+
enumKeyCasing,
|
|
561
|
+
resolver
|
|
562
|
+
})), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
|
|
563
|
+
name,
|
|
564
|
+
isTypeOnly: true,
|
|
565
|
+
isExportable: true,
|
|
566
|
+
isIndexable: true,
|
|
567
|
+
children: output
|
|
568
|
+
})] });
|
|
569
|
+
}
|
|
570
|
+
//#endregion
|
|
535
571
|
//#region src/utils.ts
|
|
536
572
|
/**
|
|
537
573
|
* Collects JSDoc annotation strings for a schema node.
|
|
@@ -784,7 +820,8 @@ const printerTs = definePrinter((options) => {
|
|
|
784
820
|
const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, transform)];
|
|
785
821
|
if (!allElements.length) return keywordTypeNodes.object;
|
|
786
822
|
return createTypeLiteralNode(allElements);
|
|
787
|
-
}
|
|
823
|
+
},
|
|
824
|
+
...options.nodes
|
|
788
825
|
},
|
|
789
826
|
print(node) {
|
|
790
827
|
const { name, syntaxType = "type", description, keysToOmit } = this.options;
|
|
@@ -818,68 +855,20 @@ const printerTs = definePrinter((options) => {
|
|
|
818
855
|
};
|
|
819
856
|
});
|
|
820
857
|
//#endregion
|
|
821
|
-
//#region src/components/Type.tsx
|
|
822
|
-
function Type({ name, node, keysToOmit, optionalType, arrayType, syntaxType, enumType, enumTypeSuffix, enumKeyCasing, description, resolver, enumSchemaNames }) {
|
|
823
|
-
const resolvedDescription = description || node?.description;
|
|
824
|
-
const enumSchemaNodes = collect(node, { schema(n) {
|
|
825
|
-
const enumNode = narrowSchema(n, schemaTypes.enum);
|
|
826
|
-
if (enumNode?.name) return enumNode;
|
|
827
|
-
} });
|
|
828
|
-
const output = printerTs({
|
|
829
|
-
optionalType,
|
|
830
|
-
arrayType,
|
|
831
|
-
enumType,
|
|
832
|
-
enumTypeSuffix,
|
|
833
|
-
name,
|
|
834
|
-
syntaxType,
|
|
835
|
-
description: resolvedDescription,
|
|
836
|
-
keysToOmit,
|
|
837
|
-
resolver,
|
|
838
|
-
enumSchemaNames
|
|
839
|
-
}).print(node);
|
|
840
|
-
if (!output) return;
|
|
841
|
-
const enums = [...new Map(enumSchemaNodes.map((n) => [n.name, n])).values()].map((node) => {
|
|
842
|
-
return {
|
|
843
|
-
node,
|
|
844
|
-
...getEnumNames({
|
|
845
|
-
node,
|
|
846
|
-
enumType,
|
|
847
|
-
enumTypeSuffix,
|
|
848
|
-
resolver
|
|
849
|
-
})
|
|
850
|
-
};
|
|
851
|
-
});
|
|
852
|
-
const shouldExportEnums = enumType !== "inlineLiteral";
|
|
853
|
-
const shouldExportType = enumType === "inlineLiteral" || enums.every((item) => item.typeName !== name);
|
|
854
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [shouldExportEnums && enums.map(({ node }) => /* @__PURE__ */ jsx(Enum, {
|
|
855
|
-
node,
|
|
856
|
-
enumType,
|
|
857
|
-
enumTypeSuffix,
|
|
858
|
-
enumKeyCasing,
|
|
859
|
-
resolver
|
|
860
|
-
})), shouldExportType && /* @__PURE__ */ jsx(File.Source, {
|
|
861
|
-
name,
|
|
862
|
-
isTypeOnly: true,
|
|
863
|
-
isExportable: true,
|
|
864
|
-
isIndexable: true,
|
|
865
|
-
children: output
|
|
866
|
-
})] });
|
|
867
|
-
}
|
|
868
|
-
//#endregion
|
|
869
858
|
//#region src/generators/typeGenerator.tsx
|
|
870
859
|
const typeGenerator = defineGenerator({
|
|
871
860
|
name: "typescript",
|
|
872
861
|
type: "react",
|
|
873
|
-
Schema({ node, adapter, options, config, resolver }) {
|
|
874
|
-
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group,
|
|
875
|
-
const transformedNode = transform(node,
|
|
862
|
+
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
863
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group, printer } = options;
|
|
864
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
876
865
|
if (!transformedNode.name) return;
|
|
877
866
|
const root = path.resolve(config.root, config.output.path);
|
|
878
867
|
const mode = getMode(path.resolve(root, output.path));
|
|
879
868
|
const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name));
|
|
880
869
|
function resolveImportName(schemaName) {
|
|
881
870
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
|
|
882
|
-
return resolver.
|
|
871
|
+
return resolver.resolveTypeName(schemaName);
|
|
883
872
|
}
|
|
884
873
|
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
885
874
|
name: resolveImportName(schemaName),
|
|
@@ -894,7 +883,7 @@ const typeGenerator = defineGenerator({
|
|
|
894
883
|
}));
|
|
895
884
|
const isEnumSchema = !!narrowSchema(transformedNode, schemaTypes.enum);
|
|
896
885
|
const meta = {
|
|
897
|
-
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(transformedNode, enumTypeSuffix) : resolver.
|
|
886
|
+
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(transformedNode, enumTypeSuffix) : resolver.resolveTypeName(transformedNode.name),
|
|
898
887
|
file: resolver.resolveFile({
|
|
899
888
|
name: transformedNode.name,
|
|
900
889
|
extname: ".ts"
|
|
@@ -904,6 +893,18 @@ const typeGenerator = defineGenerator({
|
|
|
904
893
|
group
|
|
905
894
|
})
|
|
906
895
|
};
|
|
896
|
+
const schemaPrinter = printerTs({
|
|
897
|
+
optionalType,
|
|
898
|
+
arrayType,
|
|
899
|
+
enumType,
|
|
900
|
+
enumTypeSuffix,
|
|
901
|
+
name: meta.name,
|
|
902
|
+
syntaxType,
|
|
903
|
+
description: transformedNode.description,
|
|
904
|
+
resolver,
|
|
905
|
+
enumSchemaNames,
|
|
906
|
+
nodes: printer?.nodes
|
|
907
|
+
});
|
|
907
908
|
return /* @__PURE__ */ jsxs(File, {
|
|
908
909
|
baseName: meta.file.baseName,
|
|
909
910
|
path: meta.file.path,
|
|
@@ -931,17 +932,14 @@ const typeGenerator = defineGenerator({
|
|
|
931
932
|
enumType,
|
|
932
933
|
enumTypeSuffix,
|
|
933
934
|
enumKeyCasing,
|
|
934
|
-
optionalType,
|
|
935
|
-
arrayType,
|
|
936
|
-
syntaxType,
|
|
937
935
|
resolver,
|
|
938
|
-
|
|
936
|
+
printer: schemaPrinter
|
|
939
937
|
})]
|
|
940
938
|
});
|
|
941
939
|
},
|
|
942
|
-
Operation({ node, adapter, options, config, resolver }) {
|
|
943
|
-
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output,
|
|
944
|
-
const transformedNode = transform(node,
|
|
940
|
+
Operation({ node, adapter, options, config, resolver, plugin }) {
|
|
941
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output, printer } = options;
|
|
942
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
945
943
|
const root = path.resolve(config.root, config.output.path);
|
|
946
944
|
const mode = getMode(path.resolve(root, output.path));
|
|
947
945
|
const params = caseParams(transformedNode.parameters, paramsCasing);
|
|
@@ -958,7 +956,7 @@ const typeGenerator = defineGenerator({
|
|
|
958
956
|
const enumSchemaNames = new Set((adapter.rootNode?.schemas ?? []).filter((s) => narrowSchema(s, schemaTypes.enum) && s.name).map((s) => s.name));
|
|
959
957
|
function resolveImportName(schemaName) {
|
|
960
958
|
if (ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && enumTypeSuffix && enumSchemaNames.has(schemaName)) return resolver.resolveEnumKeyName({ name: schemaName }, enumTypeSuffix);
|
|
961
|
-
return resolver.
|
|
959
|
+
return resolver.resolveTypeName(schemaName);
|
|
962
960
|
}
|
|
963
961
|
function renderSchemaType({ schema, name, keysToOmit }) {
|
|
964
962
|
if (!schema) return null;
|
|
@@ -973,6 +971,19 @@ const typeGenerator = defineGenerator({
|
|
|
973
971
|
group
|
|
974
972
|
}).path
|
|
975
973
|
}));
|
|
974
|
+
const schemaPrinter = printerTs({
|
|
975
|
+
optionalType,
|
|
976
|
+
arrayType,
|
|
977
|
+
enumType,
|
|
978
|
+
enumTypeSuffix,
|
|
979
|
+
name,
|
|
980
|
+
syntaxType,
|
|
981
|
+
description: schema.description,
|
|
982
|
+
keysToOmit,
|
|
983
|
+
resolver,
|
|
984
|
+
enumSchemaNames,
|
|
985
|
+
nodes: printer?.nodes
|
|
986
|
+
});
|
|
976
987
|
return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
977
988
|
root: meta.file.path,
|
|
978
989
|
path: imp.path,
|
|
@@ -988,12 +999,8 @@ const typeGenerator = defineGenerator({
|
|
|
988
999
|
enumType,
|
|
989
1000
|
enumTypeSuffix,
|
|
990
1001
|
enumKeyCasing,
|
|
991
|
-
optionalType,
|
|
992
|
-
arrayType,
|
|
993
|
-
syntaxType,
|
|
994
1002
|
resolver,
|
|
995
|
-
|
|
996
|
-
enumSchemaNames
|
|
1003
|
+
printer: schemaPrinter
|
|
997
1004
|
})] });
|
|
998
1005
|
}
|
|
999
1006
|
const paramTypes = params.map((param) => renderSchemaType({
|
|
@@ -1056,9 +1063,6 @@ const typeGenerator = defineGenerator({
|
|
|
1056
1063
|
});
|
|
1057
1064
|
//#endregion
|
|
1058
1065
|
//#region src/resolvers/resolverTs.ts
|
|
1059
|
-
function toTypeName(name, type) {
|
|
1060
|
-
return pascalCase(name, { isFile: type === "file" });
|
|
1061
|
-
}
|
|
1062
1066
|
/**
|
|
1063
1067
|
* Resolver for `@kubb/plugin-ts` that provides the default naming and path-resolution
|
|
1064
1068
|
* helpers used by the plugin. Import this in other plugins to resolve the exact names and
|
|
@@ -1081,34 +1085,34 @@ const resolverTs = defineResolver(() => {
|
|
|
1081
1085
|
name: "default",
|
|
1082
1086
|
pluginName: "plugin-ts",
|
|
1083
1087
|
default(name, type) {
|
|
1084
|
-
return
|
|
1088
|
+
return pascalCase(name, { isFile: type === "file" });
|
|
1085
1089
|
},
|
|
1086
|
-
|
|
1087
|
-
return
|
|
1090
|
+
resolveTypeName(name) {
|
|
1091
|
+
return pascalCase(name);
|
|
1088
1092
|
},
|
|
1089
1093
|
resolvePathName(name, type) {
|
|
1090
|
-
return
|
|
1094
|
+
return pascalCase(name, { isFile: type === "file" });
|
|
1091
1095
|
},
|
|
1092
1096
|
resolveParamName(node, param) {
|
|
1093
|
-
return this.
|
|
1097
|
+
return this.resolveTypeName(`${node.operationId} ${param.in} ${param.name}`);
|
|
1094
1098
|
},
|
|
1095
1099
|
resolveResponseStatusName(node, statusCode) {
|
|
1096
|
-
return this.
|
|
1100
|
+
return this.resolveTypeName(`${node.operationId} Status ${statusCode}`);
|
|
1097
1101
|
},
|
|
1098
1102
|
resolveDataName(node) {
|
|
1099
|
-
return this.
|
|
1103
|
+
return this.resolveTypeName(`${node.operationId} Data`);
|
|
1100
1104
|
},
|
|
1101
1105
|
resolveRequestConfigName(node) {
|
|
1102
|
-
return this.
|
|
1106
|
+
return this.resolveTypeName(`${node.operationId} RequestConfig`);
|
|
1103
1107
|
},
|
|
1104
1108
|
resolveResponsesName(node) {
|
|
1105
|
-
return this.
|
|
1109
|
+
return this.resolveTypeName(`${node.operationId} Responses`);
|
|
1106
1110
|
},
|
|
1107
1111
|
resolveResponseName(node) {
|
|
1108
|
-
return this.
|
|
1112
|
+
return this.resolveTypeName(`${node.operationId} Response`);
|
|
1109
1113
|
},
|
|
1110
1114
|
resolveEnumKeyName(node, enumTypeSuffix = "key") {
|
|
1111
|
-
return `${this.
|
|
1115
|
+
return `${this.resolveTypeName(node.name ?? "")}${enumTypeSuffix}`;
|
|
1112
1116
|
},
|
|
1113
1117
|
resolvePathParamsName(node, param) {
|
|
1114
1118
|
return this.resolveParamName(node, param);
|
|
@@ -1151,29 +1155,29 @@ const resolverTsLegacy = defineResolver(() => {
|
|
|
1151
1155
|
...resolverTs,
|
|
1152
1156
|
pluginName: "plugin-ts",
|
|
1153
1157
|
resolveResponseStatusName(node, statusCode) {
|
|
1154
|
-
if (statusCode === "default") return this.
|
|
1155
|
-
return this.
|
|
1158
|
+
if (statusCode === "default") return this.resolveTypeName(`${node.operationId} Error`);
|
|
1159
|
+
return this.resolveTypeName(`${node.operationId} ${statusCode}`);
|
|
1156
1160
|
},
|
|
1157
1161
|
resolveDataName(node) {
|
|
1158
1162
|
const suffix = node.method === "GET" ? "QueryRequest" : "MutationRequest";
|
|
1159
|
-
return this.
|
|
1163
|
+
return this.resolveTypeName(`${node.operationId} ${suffix}`);
|
|
1160
1164
|
},
|
|
1161
1165
|
resolveResponsesName(node) {
|
|
1162
1166
|
const suffix = node.method === "GET" ? "Query" : "Mutation";
|
|
1163
|
-
return this.
|
|
1167
|
+
return this.resolveTypeName(`${node.operationId} ${suffix}`);
|
|
1164
1168
|
},
|
|
1165
1169
|
resolveResponseName(node) {
|
|
1166
1170
|
const suffix = node.method === "GET" ? "QueryResponse" : "MutationResponse";
|
|
1167
|
-
return this.
|
|
1171
|
+
return this.resolveTypeName(`${node.operationId} ${suffix}`);
|
|
1168
1172
|
},
|
|
1169
1173
|
resolvePathParamsName(node, _param) {
|
|
1170
|
-
return this.
|
|
1174
|
+
return this.resolveTypeName(`${node.operationId} PathParams`);
|
|
1171
1175
|
},
|
|
1172
1176
|
resolveQueryParamsName(node, _param) {
|
|
1173
|
-
return this.
|
|
1177
|
+
return this.resolveTypeName(`${node.operationId} QueryParams`);
|
|
1174
1178
|
},
|
|
1175
1179
|
resolveHeaderParamsName(node, _param) {
|
|
1176
|
-
return this.
|
|
1180
|
+
return this.resolveTypeName(`${node.operationId} HeaderParams`);
|
|
1177
1181
|
}
|
|
1178
1182
|
};
|
|
1179
1183
|
});
|
|
@@ -1332,14 +1336,14 @@ function nameUnnamedEnums(node, parentName) {
|
|
|
1332
1336
|
const typeGeneratorLegacy = defineGenerator({
|
|
1333
1337
|
name: "typescript-legacy",
|
|
1334
1338
|
type: "react",
|
|
1335
|
-
Schema({ node, adapter, options, config, resolver }) {
|
|
1336
|
-
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group
|
|
1337
|
-
const transformedNode = transform(node,
|
|
1339
|
+
Schema({ node, adapter, options, config, resolver, plugin }) {
|
|
1340
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, syntaxType, optionalType, arrayType, output, group } = options;
|
|
1341
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
1338
1342
|
if (!transformedNode.name) return;
|
|
1339
1343
|
const root = path.resolve(config.root, config.output.path);
|
|
1340
1344
|
const mode = getMode(path.resolve(root, output.path));
|
|
1341
1345
|
const imports = adapter.getImports(transformedNode, (schemaName) => ({
|
|
1342
|
-
name: resolver.
|
|
1346
|
+
name: resolver.resolveTypeName(schemaName),
|
|
1343
1347
|
path: resolver.resolveFile({
|
|
1344
1348
|
name: schemaName,
|
|
1345
1349
|
extname: ".ts"
|
|
@@ -1351,7 +1355,7 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1351
1355
|
}));
|
|
1352
1356
|
const isEnumSchema = !!narrowSchema(transformedNode, schemaTypes.enum);
|
|
1353
1357
|
const meta = {
|
|
1354
|
-
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(transformedNode, enumTypeSuffix) : resolver.
|
|
1358
|
+
name: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumType) && isEnumSchema ? resolver.resolveEnumKeyName(transformedNode, enumTypeSuffix) : resolver.resolveTypeName(transformedNode.name),
|
|
1355
1359
|
file: resolver.resolveFile({
|
|
1356
1360
|
name: transformedNode.name,
|
|
1357
1361
|
extname: ".ts"
|
|
@@ -1361,6 +1365,16 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1361
1365
|
group
|
|
1362
1366
|
})
|
|
1363
1367
|
};
|
|
1368
|
+
const schemaPrinter = printerTs({
|
|
1369
|
+
optionalType,
|
|
1370
|
+
arrayType,
|
|
1371
|
+
enumType,
|
|
1372
|
+
enumTypeSuffix,
|
|
1373
|
+
name: meta.name,
|
|
1374
|
+
syntaxType,
|
|
1375
|
+
description: transformedNode.description,
|
|
1376
|
+
resolver
|
|
1377
|
+
});
|
|
1364
1378
|
return /* @__PURE__ */ jsxs(File, {
|
|
1365
1379
|
baseName: meta.file.baseName,
|
|
1366
1380
|
path: meta.file.path,
|
|
@@ -1388,16 +1402,14 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1388
1402
|
enumType,
|
|
1389
1403
|
enumTypeSuffix,
|
|
1390
1404
|
enumKeyCasing,
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
syntaxType,
|
|
1394
|
-
resolver
|
|
1405
|
+
resolver,
|
|
1406
|
+
printer: schemaPrinter
|
|
1395
1407
|
})]
|
|
1396
1408
|
});
|
|
1397
1409
|
},
|
|
1398
|
-
Operation({ node, adapter, options, config, resolver }) {
|
|
1399
|
-
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output
|
|
1400
|
-
const transformedNode = transform(node,
|
|
1410
|
+
Operation({ node, adapter, options, config, resolver, plugin }) {
|
|
1411
|
+
const { enumType, enumTypeSuffix, enumKeyCasing, optionalType, arrayType, syntaxType, paramsCasing, group, output } = options;
|
|
1412
|
+
const transformedNode = plugin.transformer ? transform(node, plugin.transformer) : node;
|
|
1401
1413
|
const root = path.resolve(config.root, config.output.path);
|
|
1402
1414
|
const mode = getMode(path.resolve(root, output.path));
|
|
1403
1415
|
const params = caseParams(node.parameters, paramsCasing);
|
|
@@ -1414,7 +1426,7 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1414
1426
|
function renderSchemaType({ schema, name, description, keysToOmit }) {
|
|
1415
1427
|
if (!schema) return null;
|
|
1416
1428
|
const imports = adapter.getImports(schema, (schemaName) => ({
|
|
1417
|
-
name: resolver.
|
|
1429
|
+
name: resolver.resolveTypeName(schemaName),
|
|
1418
1430
|
path: resolver.resolveFile({
|
|
1419
1431
|
name: schemaName,
|
|
1420
1432
|
extname: ".ts"
|
|
@@ -1424,6 +1436,17 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1424
1436
|
group
|
|
1425
1437
|
}).path
|
|
1426
1438
|
}));
|
|
1439
|
+
const opPrinter = printerTs({
|
|
1440
|
+
optionalType,
|
|
1441
|
+
arrayType,
|
|
1442
|
+
enumType,
|
|
1443
|
+
enumTypeSuffix,
|
|
1444
|
+
name,
|
|
1445
|
+
syntaxType,
|
|
1446
|
+
description,
|
|
1447
|
+
keysToOmit,
|
|
1448
|
+
resolver
|
|
1449
|
+
});
|
|
1427
1450
|
return /* @__PURE__ */ jsxs(Fragment, { children: [mode === "split" && imports.map((imp) => /* @__PURE__ */ jsx(File.Import, {
|
|
1428
1451
|
root: meta.file.path,
|
|
1429
1452
|
path: imp.path,
|
|
@@ -1436,15 +1459,11 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1436
1459
|
].join("-"))), /* @__PURE__ */ jsx(Type, {
|
|
1437
1460
|
name,
|
|
1438
1461
|
node: schema,
|
|
1439
|
-
description,
|
|
1440
1462
|
enumType,
|
|
1441
1463
|
enumTypeSuffix,
|
|
1442
1464
|
enumKeyCasing,
|
|
1443
|
-
optionalType,
|
|
1444
|
-
arrayType,
|
|
1445
|
-
syntaxType,
|
|
1446
1465
|
resolver,
|
|
1447
|
-
|
|
1466
|
+
printer: opPrinter
|
|
1448
1467
|
})] });
|
|
1449
1468
|
}
|
|
1450
1469
|
const pathParams = params.filter((p) => p.in === "path");
|
|
@@ -1530,13 +1549,15 @@ const typeGeneratorLegacy = defineGenerator({
|
|
|
1530
1549
|
const presets = definePresets({
|
|
1531
1550
|
default: {
|
|
1532
1551
|
name: "default",
|
|
1533
|
-
|
|
1534
|
-
generators: [typeGenerator]
|
|
1552
|
+
resolver: resolverTs,
|
|
1553
|
+
generators: [typeGenerator],
|
|
1554
|
+
printer: printerTs
|
|
1535
1555
|
},
|
|
1536
1556
|
kubbV4: {
|
|
1537
1557
|
name: "kubbV4",
|
|
1538
|
-
|
|
1539
|
-
generators: [typeGeneratorLegacy]
|
|
1558
|
+
resolver: resolverTsLegacy,
|
|
1559
|
+
generators: [typeGeneratorLegacy],
|
|
1560
|
+
printer: printerTs
|
|
1540
1561
|
}
|
|
1541
1562
|
});
|
|
1542
1563
|
//#endregion
|
|
@@ -1565,12 +1586,12 @@ const pluginTs = createPlugin((options) => {
|
|
|
1565
1586
|
const { output = {
|
|
1566
1587
|
path: "types",
|
|
1567
1588
|
barrelType: "named"
|
|
1568
|
-
}, group, exclude = [], include, override = [], enumType = "asConst", enumTypeSuffix = "Key", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, compatibilityPreset = "default",
|
|
1589
|
+
}, group, exclude = [], include, override = [], enumType = "asConst", enumTypeSuffix = "Key", enumKeyCasing = "none", optionalType = "questionToken", arrayType = "array", syntaxType = "type", paramsCasing, printer, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer, generators: userGenerators = [] } = options;
|
|
1569
1590
|
const preset = getPreset({
|
|
1570
1591
|
preset: compatibilityPreset,
|
|
1571
1592
|
presets,
|
|
1572
|
-
|
|
1573
|
-
|
|
1593
|
+
resolver: userResolver,
|
|
1594
|
+
transformer: userTransformer,
|
|
1574
1595
|
generators: userGenerators
|
|
1575
1596
|
});
|
|
1576
1597
|
let resolveNameWarning = false;
|
|
@@ -1580,6 +1601,9 @@ const pluginTs = createPlugin((options) => {
|
|
|
1580
1601
|
get resolver() {
|
|
1581
1602
|
return preset.resolver;
|
|
1582
1603
|
},
|
|
1604
|
+
get transformer() {
|
|
1605
|
+
return preset.transformer;
|
|
1606
|
+
},
|
|
1583
1607
|
get options() {
|
|
1584
1608
|
return {
|
|
1585
1609
|
output,
|
|
@@ -1597,7 +1621,7 @@ const pluginTs = createPlugin((options) => {
|
|
|
1597
1621
|
enumKeyCasing,
|
|
1598
1622
|
syntaxType,
|
|
1599
1623
|
paramsCasing,
|
|
1600
|
-
|
|
1624
|
+
printer
|
|
1601
1625
|
};
|
|
1602
1626
|
},
|
|
1603
1627
|
resolvePath(baseName, pathMode, options) {
|