@kubb/plugin-faker 5.0.0-beta.94 → 5.0.0-beta.95
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 +86 -67
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.js +86 -67
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -728,22 +728,79 @@ function getOperationParameters(node, options = {}) {
|
|
|
728
728
|
};
|
|
729
729
|
}
|
|
730
730
|
//#endregion
|
|
731
|
-
//#region ../../internals/shared/src/
|
|
731
|
+
//#region ../../internals/shared/src/resolver.ts
|
|
732
732
|
/**
|
|
733
|
-
*
|
|
734
|
-
*
|
|
733
|
+
* Resolves a single operation parameter name with the
|
|
734
|
+
* `<operationId> <in> <name>` template.
|
|
735
735
|
*
|
|
736
|
-
*
|
|
737
|
-
*
|
|
736
|
+
* @example
|
|
737
|
+
* `operationParamName.call(resolver, node, param) // → 'DeletePetPathPetId'`
|
|
738
|
+
*/
|
|
739
|
+
function operationParamName(node, param) {
|
|
740
|
+
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Builds the shared `param` namespace. Spread the result into `createResolver`
|
|
744
|
+
* and override individual methods next to it when a plugin deviates.
|
|
745
|
+
*
|
|
746
|
+
* @example
|
|
747
|
+
* ```ts
|
|
748
|
+
* createResolver<PluginTs>({ param: createOperationParamResolver(), ... })
|
|
749
|
+
* ```
|
|
750
|
+
*/
|
|
751
|
+
function createOperationParamResolver() {
|
|
752
|
+
return {
|
|
753
|
+
name: operationParamName,
|
|
754
|
+
path(node) {
|
|
755
|
+
return this.name(`${node.operationId} Path`);
|
|
756
|
+
},
|
|
757
|
+
query(node) {
|
|
758
|
+
return this.name(`${node.operationId} Query`);
|
|
759
|
+
},
|
|
760
|
+
headers(node) {
|
|
761
|
+
return this.name(`${node.operationId} Headers`);
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
}
|
|
765
|
+
/**
|
|
766
|
+
* Builds the shared `response` namespace. Spread the result into
|
|
767
|
+
* `createResolver` and add plugin-specific methods (`options`, `error`) next
|
|
768
|
+
* to it.
|
|
769
|
+
*
|
|
770
|
+
* @example
|
|
771
|
+
* ```ts
|
|
772
|
+
* createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })
|
|
773
|
+
* ```
|
|
774
|
+
*/
|
|
775
|
+
function createOperationResponseResolver() {
|
|
776
|
+
return {
|
|
777
|
+
status(node, statusCode) {
|
|
778
|
+
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
779
|
+
},
|
|
780
|
+
body(node) {
|
|
781
|
+
return this.name(`${node.operationId} Body`);
|
|
782
|
+
},
|
|
783
|
+
responses(node) {
|
|
784
|
+
return this.name(`${node.operationId} Responses`);
|
|
785
|
+
},
|
|
786
|
+
response(node) {
|
|
787
|
+
return this.name(`${node.operationId} Response`);
|
|
788
|
+
}
|
|
789
|
+
};
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Builds a resolver `file` override whose base name runs every path segment
|
|
793
|
+
* through `toFilePath`, casing the final segment with `caseLast`.
|
|
738
794
|
*
|
|
739
795
|
* @example
|
|
740
796
|
* ```ts
|
|
741
|
-
*
|
|
797
|
+
* createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })
|
|
742
798
|
* ```
|
|
743
799
|
*/
|
|
744
|
-
function
|
|
745
|
-
|
|
746
|
-
|
|
800
|
+
function createCasedFile(caseLast) {
|
|
801
|
+
return { baseName({ name, extname }) {
|
|
802
|
+
return `${toFilePath(name, caseLast)}${extname}`;
|
|
803
|
+
} };
|
|
747
804
|
}
|
|
748
805
|
//#endregion
|
|
749
806
|
//#region ../../internals/shared/src/group.ts
|
|
@@ -915,7 +972,7 @@ const printerFaker = kubb_kit.ast.createPrinter((options) => {
|
|
|
915
972
|
return fakerKeywordMapper.time(node.representation ?? "string", this.options.dateParser);
|
|
916
973
|
},
|
|
917
974
|
ref(node) {
|
|
918
|
-
const refName =
|
|
975
|
+
const refName = kubb_kit.ast.resolveRefName(node);
|
|
919
976
|
if (!refName) throw new Error("Name not defined for ref node");
|
|
920
977
|
if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
|
|
921
978
|
const resolvedName = node.ref ? this.options.resolver.name(refName) : refName;
|
|
@@ -993,7 +1050,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
993
1050
|
name: "faker",
|
|
994
1051
|
renderer: kubb_jsx.jsxRenderer,
|
|
995
1052
|
schema(node, ctx) {
|
|
996
|
-
const {
|
|
1053
|
+
const { config, resolver, root } = ctx;
|
|
997
1054
|
const { output, group, dateParser, regexGenerator, seed, locale, printer } = ctx.options;
|
|
998
1055
|
const pluginTs = ctx.driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
999
1056
|
if (!node.name || !pluginTs) return;
|
|
@@ -1030,8 +1087,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1030
1087
|
dateParser,
|
|
1031
1088
|
regexGenerator,
|
|
1032
1089
|
nodes: printer?.nodes,
|
|
1033
|
-
cyclicSchemas
|
|
1034
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1090
|
+
cyclicSchemas
|
|
1035
1091
|
});
|
|
1036
1092
|
const fakerText = printerInstance.print(node) ?? "undefined";
|
|
1037
1093
|
const typeReference = resolveTypeReference({
|
|
@@ -1042,16 +1098,12 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1042
1098
|
filePath: meta.file.path,
|
|
1043
1099
|
typeFilePath: meta.typeFile.path
|
|
1044
1100
|
});
|
|
1045
|
-
const usedImports = filterUsedImports(
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
output,
|
|
1052
|
-
group: group ?? void 0
|
|
1053
|
-
}).path
|
|
1054
|
-
})), fakerText);
|
|
1101
|
+
const usedImports = filterUsedImports(resolver.imports({
|
|
1102
|
+
node,
|
|
1103
|
+
root,
|
|
1104
|
+
output,
|
|
1105
|
+
group: group ?? void 0
|
|
1106
|
+
}), fakerText);
|
|
1055
1107
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx.File, {
|
|
1056
1108
|
baseName: meta.file.baseName,
|
|
1057
1109
|
path: meta.file.path,
|
|
@@ -1116,7 +1168,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1116
1168
|
});
|
|
1117
1169
|
},
|
|
1118
1170
|
operation(node, ctx) {
|
|
1119
|
-
const {
|
|
1171
|
+
const { config, resolver, root } = ctx;
|
|
1120
1172
|
const { output, group, dateParser, regexGenerator, seed, locale, printer } = ctx.options;
|
|
1121
1173
|
const pluginTs = ctx.driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1122
1174
|
if (!pluginTs) return;
|
|
@@ -1216,16 +1268,12 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1216
1268
|
})
|
|
1217
1269
|
};
|
|
1218
1270
|
function resolveMockImports(schema) {
|
|
1219
|
-
return
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
output,
|
|
1226
|
-
group: group ?? void 0
|
|
1227
|
-
}).path
|
|
1228
|
-
})).filter((entry) => entry.path !== meta.file.path);
|
|
1271
|
+
return resolver.imports({
|
|
1272
|
+
node: schema,
|
|
1273
|
+
root,
|
|
1274
|
+
output,
|
|
1275
|
+
group: group ?? void 0
|
|
1276
|
+
}).filter((entry) => entry.path !== meta.file.path);
|
|
1229
1277
|
}
|
|
1230
1278
|
function renderEntry({ schema, name, typeName, description, skipImportNames = [] }) {
|
|
1231
1279
|
if (!schema) return null;
|
|
@@ -1237,8 +1285,7 @@ const fakerGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1237
1285
|
dateParser,
|
|
1238
1286
|
regexGenerator,
|
|
1239
1287
|
nodes: printer?.nodes,
|
|
1240
|
-
cyclicSchemas
|
|
1241
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1288
|
+
cyclicSchemas
|
|
1242
1289
|
});
|
|
1243
1290
|
const fakerText = printerInstance.print(schema) ?? "undefined";
|
|
1244
1291
|
const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);
|
|
@@ -1361,37 +1408,9 @@ const resolverFaker = (0, kubb_kit.createResolver)({
|
|
|
1361
1408
|
name(name) {
|
|
1362
1409
|
return ensureValidVarName(camelCase(name, { prefix: "create" }));
|
|
1363
1410
|
},
|
|
1364
|
-
file:
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
param: {
|
|
1368
|
-
name(node, param) {
|
|
1369
|
-
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1370
|
-
},
|
|
1371
|
-
path(node) {
|
|
1372
|
-
return this.name(`${node.operationId} Path`);
|
|
1373
|
-
},
|
|
1374
|
-
query(node) {
|
|
1375
|
-
return this.name(`${node.operationId} Query`);
|
|
1376
|
-
},
|
|
1377
|
-
headers(node) {
|
|
1378
|
-
return this.name(`${node.operationId} Headers`);
|
|
1379
|
-
}
|
|
1380
|
-
},
|
|
1381
|
-
response: {
|
|
1382
|
-
status(node, statusCode) {
|
|
1383
|
-
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1384
|
-
},
|
|
1385
|
-
body(node) {
|
|
1386
|
-
return this.name(`${node.operationId} Body`);
|
|
1387
|
-
},
|
|
1388
|
-
response(node) {
|
|
1389
|
-
return this.name(`${node.operationId} Response`);
|
|
1390
|
-
},
|
|
1391
|
-
responses(node) {
|
|
1392
|
-
return this.name(`${node.operationId} Responses`);
|
|
1393
|
-
}
|
|
1394
|
-
}
|
|
1411
|
+
file: createCasedFile((part) => camelCase(part, { prefix: "create" })),
|
|
1412
|
+
param: createOperationParamResolver(),
|
|
1413
|
+
response: createOperationResponseResolver()
|
|
1395
1414
|
});
|
|
1396
1415
|
//#endregion
|
|
1397
1416
|
//#region src/plugin.ts
|