@kubb/plugin-faker 5.0.0-beta.87 → 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 +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -213,12 +213,6 @@ type PrinterFakerOptions = {
|
|
|
213
213
|
* the recursive faker call from ever executing (avoiding stack overflow).
|
|
214
214
|
*/
|
|
215
215
|
cyclicSchemas?: ReadonlySet<string>;
|
|
216
|
-
/**
|
|
217
|
-
* Maps a component `$ref` path to its collision-resolved name. When two components collide
|
|
218
|
-
* (across sections or by case), the adapter renames one of them; the `ref()` handler resolves
|
|
219
|
-
* the referenced name through this map so the emitted faker reference matches the renamed component.
|
|
220
|
-
*/
|
|
221
|
-
nameMapping?: ReadonlyMap<string, string>;
|
|
222
216
|
};
|
|
223
217
|
/**
|
|
224
218
|
* Factory options for the Faker printer, defining input/output types and configuration.
|
package/dist/index.js
CHANGED
|
@@ -724,22 +724,79 @@ function getOperationParameters(node, options = {}) {
|
|
|
724
724
|
};
|
|
725
725
|
}
|
|
726
726
|
//#endregion
|
|
727
|
-
//#region ../../internals/shared/src/
|
|
727
|
+
//#region ../../internals/shared/src/resolver.ts
|
|
728
728
|
/**
|
|
729
|
-
*
|
|
730
|
-
*
|
|
729
|
+
* Resolves a single operation parameter name with the
|
|
730
|
+
* `<operationId> <in> <name>` template.
|
|
731
731
|
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
732
|
+
* @example
|
|
733
|
+
* `operationParamName.call(resolver, node, param) // → 'DeletePetPathPetId'`
|
|
734
|
+
*/
|
|
735
|
+
function operationParamName(node, param) {
|
|
736
|
+
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
737
|
+
}
|
|
738
|
+
/**
|
|
739
|
+
* Builds the shared `param` namespace. Spread the result into `createResolver`
|
|
740
|
+
* and override individual methods next to it when a plugin deviates.
|
|
741
|
+
*
|
|
742
|
+
* @example
|
|
743
|
+
* ```ts
|
|
744
|
+
* createResolver<PluginTs>({ param: createOperationParamResolver(), ... })
|
|
745
|
+
* ```
|
|
746
|
+
*/
|
|
747
|
+
function createOperationParamResolver() {
|
|
748
|
+
return {
|
|
749
|
+
name: operationParamName,
|
|
750
|
+
path(node) {
|
|
751
|
+
return this.name(`${node.operationId} Path`);
|
|
752
|
+
},
|
|
753
|
+
query(node) {
|
|
754
|
+
return this.name(`${node.operationId} Query`);
|
|
755
|
+
},
|
|
756
|
+
headers(node) {
|
|
757
|
+
return this.name(`${node.operationId} Headers`);
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
/**
|
|
762
|
+
* Builds the shared `response` namespace. Spread the result into
|
|
763
|
+
* `createResolver` and add plugin-specific methods (`options`, `error`) next
|
|
764
|
+
* to it.
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```ts
|
|
768
|
+
* createResolver<PluginTs>({ response: { ...createOperationResponseResolver(), options(node) {...} }, ... })
|
|
769
|
+
* ```
|
|
770
|
+
*/
|
|
771
|
+
function createOperationResponseResolver() {
|
|
772
|
+
return {
|
|
773
|
+
status(node, statusCode) {
|
|
774
|
+
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
775
|
+
},
|
|
776
|
+
body(node) {
|
|
777
|
+
return this.name(`${node.operationId} Body`);
|
|
778
|
+
},
|
|
779
|
+
responses(node) {
|
|
780
|
+
return this.name(`${node.operationId} Responses`);
|
|
781
|
+
},
|
|
782
|
+
response(node) {
|
|
783
|
+
return this.name(`${node.operationId} Response`);
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
}
|
|
787
|
+
/**
|
|
788
|
+
* Builds a resolver `file` override whose base name runs every path segment
|
|
789
|
+
* through `toFilePath`, casing the final segment with `caseLast`.
|
|
734
790
|
*
|
|
735
791
|
* @example
|
|
736
792
|
* ```ts
|
|
737
|
-
*
|
|
793
|
+
* createResolver<PluginTs>({ file: createCasedFile(pascalCase), ... })
|
|
738
794
|
* ```
|
|
739
795
|
*/
|
|
740
|
-
function
|
|
741
|
-
|
|
742
|
-
|
|
796
|
+
function createCasedFile(caseLast) {
|
|
797
|
+
return { baseName({ name, extname }) {
|
|
798
|
+
return `${toFilePath(name, caseLast)}${extname}`;
|
|
799
|
+
} };
|
|
743
800
|
}
|
|
744
801
|
//#endregion
|
|
745
802
|
//#region ../../internals/shared/src/group.ts
|
|
@@ -911,7 +968,7 @@ const printerFaker = ast.createPrinter((options) => {
|
|
|
911
968
|
return fakerKeywordMapper.time(node.representation ?? "string", this.options.dateParser);
|
|
912
969
|
},
|
|
913
970
|
ref(node) {
|
|
914
|
-
const refName =
|
|
971
|
+
const refName = ast.resolveRefName(node);
|
|
915
972
|
if (!refName) throw new Error("Name not defined for ref node");
|
|
916
973
|
if (this.options.schemaName && refName === this.options.schemaName) return this.options.typeName ? `undefined as unknown as ${this.options.typeName}` : "undefined as unknown";
|
|
917
974
|
const resolvedName = node.ref ? this.options.resolver.name(refName) : refName;
|
|
@@ -989,7 +1046,7 @@ const fakerGenerator = defineGenerator({
|
|
|
989
1046
|
name: "faker",
|
|
990
1047
|
renderer: jsxRenderer,
|
|
991
1048
|
schema(node, ctx) {
|
|
992
|
-
const {
|
|
1049
|
+
const { config, resolver, root } = ctx;
|
|
993
1050
|
const { output, group, dateParser, regexGenerator, seed, locale, printer } = ctx.options;
|
|
994
1051
|
const pluginTs = ctx.driver.getPlugin(pluginTsName);
|
|
995
1052
|
if (!node.name || !pluginTs) return;
|
|
@@ -1026,8 +1083,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1026
1083
|
dateParser,
|
|
1027
1084
|
regexGenerator,
|
|
1028
1085
|
nodes: printer?.nodes,
|
|
1029
|
-
cyclicSchemas
|
|
1030
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1086
|
+
cyclicSchemas
|
|
1031
1087
|
});
|
|
1032
1088
|
const fakerText = printerInstance.print(node) ?? "undefined";
|
|
1033
1089
|
const typeReference = resolveTypeReference({
|
|
@@ -1038,16 +1094,12 @@ const fakerGenerator = defineGenerator({
|
|
|
1038
1094
|
filePath: meta.file.path,
|
|
1039
1095
|
typeFilePath: meta.typeFile.path
|
|
1040
1096
|
});
|
|
1041
|
-
const usedImports = filterUsedImports(
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
output,
|
|
1048
|
-
group: group ?? void 0
|
|
1049
|
-
}).path
|
|
1050
|
-
})), fakerText);
|
|
1097
|
+
const usedImports = filterUsedImports(resolver.imports({
|
|
1098
|
+
node,
|
|
1099
|
+
root,
|
|
1100
|
+
output,
|
|
1101
|
+
group: group ?? void 0
|
|
1102
|
+
}), fakerText);
|
|
1051
1103
|
return /* @__PURE__ */ jsxs(File, {
|
|
1052
1104
|
baseName: meta.file.baseName,
|
|
1053
1105
|
path: meta.file.path,
|
|
@@ -1112,7 +1164,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1112
1164
|
});
|
|
1113
1165
|
},
|
|
1114
1166
|
operation(node, ctx) {
|
|
1115
|
-
const {
|
|
1167
|
+
const { config, resolver, root } = ctx;
|
|
1116
1168
|
const { output, group, dateParser, regexGenerator, seed, locale, printer } = ctx.options;
|
|
1117
1169
|
const pluginTs = ctx.driver.getPlugin(pluginTsName);
|
|
1118
1170
|
if (!pluginTs) return;
|
|
@@ -1212,16 +1264,12 @@ const fakerGenerator = defineGenerator({
|
|
|
1212
1264
|
})
|
|
1213
1265
|
};
|
|
1214
1266
|
function resolveMockImports(schema) {
|
|
1215
|
-
return
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
output,
|
|
1222
|
-
group: group ?? void 0
|
|
1223
|
-
}).path
|
|
1224
|
-
})).filter((entry) => entry.path !== meta.file.path);
|
|
1267
|
+
return resolver.imports({
|
|
1268
|
+
node: schema,
|
|
1269
|
+
root,
|
|
1270
|
+
output,
|
|
1271
|
+
group: group ?? void 0
|
|
1272
|
+
}).filter((entry) => entry.path !== meta.file.path);
|
|
1225
1273
|
}
|
|
1226
1274
|
function renderEntry({ schema, name, typeName, description, skipImportNames = [] }) {
|
|
1227
1275
|
if (!schema) return null;
|
|
@@ -1233,8 +1281,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1233
1281
|
dateParser,
|
|
1234
1282
|
regexGenerator,
|
|
1235
1283
|
nodes: printer?.nodes,
|
|
1236
|
-
cyclicSchemas
|
|
1237
|
-
nameMapping: getOasAdapter(adapter).options.nameMapping
|
|
1284
|
+
cyclicSchemas
|
|
1238
1285
|
});
|
|
1239
1286
|
const fakerText = printerInstance.print(schema) ?? "undefined";
|
|
1240
1287
|
const { imports, aliases } = aliasConflictingImports(filterUsedImports(resolveMockImports(schema), fakerText, skipImportNames), localHelperNames);
|
|
@@ -1357,37 +1404,9 @@ const resolverFaker = createResolver({
|
|
|
1357
1404
|
name(name) {
|
|
1358
1405
|
return ensureValidVarName(camelCase(name, { prefix: "create" }));
|
|
1359
1406
|
},
|
|
1360
|
-
file:
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
param: {
|
|
1364
|
-
name(node, param) {
|
|
1365
|
-
return this.name(`${node.operationId} ${param.in} ${param.name}`);
|
|
1366
|
-
},
|
|
1367
|
-
path(node) {
|
|
1368
|
-
return this.name(`${node.operationId} Path`);
|
|
1369
|
-
},
|
|
1370
|
-
query(node) {
|
|
1371
|
-
return this.name(`${node.operationId} Query`);
|
|
1372
|
-
},
|
|
1373
|
-
headers(node) {
|
|
1374
|
-
return this.name(`${node.operationId} Headers`);
|
|
1375
|
-
}
|
|
1376
|
-
},
|
|
1377
|
-
response: {
|
|
1378
|
-
status(node, statusCode) {
|
|
1379
|
-
return this.name(`${node.operationId} Status ${statusCode}`);
|
|
1380
|
-
},
|
|
1381
|
-
body(node) {
|
|
1382
|
-
return this.name(`${node.operationId} Body`);
|
|
1383
|
-
},
|
|
1384
|
-
response(node) {
|
|
1385
|
-
return this.name(`${node.operationId} Response`);
|
|
1386
|
-
},
|
|
1387
|
-
responses(node) {
|
|
1388
|
-
return this.name(`${node.operationId} Responses`);
|
|
1389
|
-
}
|
|
1390
|
-
}
|
|
1407
|
+
file: createCasedFile((part) => camelCase(part, { prefix: "create" })),
|
|
1408
|
+
param: createOperationParamResolver(),
|
|
1409
|
+
response: createOperationResponseResolver()
|
|
1391
1410
|
});
|
|
1392
1411
|
//#endregion
|
|
1393
1412
|
//#region src/plugin.ts
|