@kubb/plugin-faker 5.1.0 → 5.1.1
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 +24 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +24 -22
- package/dist/index.js.map +1 -1
- package/package.json +5 -8
package/dist/index.js
CHANGED
|
@@ -609,33 +609,35 @@ function Faker({ node, description, name, typeName, printer, canOverride, typeMo
|
|
|
609
609
|
})
|
|
610
610
|
});
|
|
611
611
|
}
|
|
612
|
-
const jsdoc = description ? `/**\n * @description ${jsStringEscape(description)}\n */\n ` : "";
|
|
613
|
-
const functionSignature = typeMode === "schema" ? `${jsdoc}export function ${name}(data?: Partial<${typeName}>): ${typeName}` : `${jsdoc}export function ${name}<TData extends Partial<${typeName}> = object>(data?: TData)`;
|
|
614
612
|
const returnType = typeMode === "schema" ? typeName : "Omit<typeof defaultFakeData, keyof NoInfer<TData>> & NoInfer<TData>";
|
|
615
613
|
const { cyclicSchemas, schemaName } = printer.options;
|
|
616
614
|
const functionBody = node.type === "object" && !!cyclicSchemas && (node.properties ?? []).some((p) => containsCircularRef(p.schema, {
|
|
617
615
|
circularSchemas: cyclicSchemas,
|
|
618
616
|
excludeName: schemaName
|
|
619
|
-
})) ? `{
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
|
|
624
|
-
}
|
|
617
|
+
})) ? `const defaultFakeData = ${fakerText}
|
|
618
|
+
if (data) {
|
|
619
|
+
for (const [key, value] of Object.entries(data)) {
|
|
620
|
+
Object.defineProperty(defaultFakeData, key, { value, configurable: true, writable: true, enumerable: true })
|
|
625
621
|
}
|
|
626
|
-
|
|
627
|
-
}` : `{
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}`;
|
|
634
|
-
return /* @__PURE__ */ jsxs(File.Source, {
|
|
622
|
+
}
|
|
623
|
+
return defaultFakeData as ${returnType}` : `const defaultFakeData = ${fakerText}
|
|
624
|
+
return {
|
|
625
|
+
...defaultFakeData,
|
|
626
|
+
...(data || {}),
|
|
627
|
+
} as ${returnType}`;
|
|
628
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
635
629
|
name,
|
|
636
630
|
isExportable: true,
|
|
637
631
|
isIndexable: true,
|
|
638
|
-
children:
|
|
632
|
+
children: /* @__PURE__ */ jsx(Function, {
|
|
633
|
+
export: true,
|
|
634
|
+
name,
|
|
635
|
+
JSDoc: { comments: description ? [`@description ${jsStringEscape(description)}`] : [] },
|
|
636
|
+
generics: typeMode === "schema" ? void 0 : `TData extends Partial<${typeName}> = object`,
|
|
637
|
+
params: typeMode === "schema" ? `data?: Partial<${typeName}>` : "data?: TData",
|
|
638
|
+
returnType: typeMode === "schema" ? typeName : void 0,
|
|
639
|
+
children: functionBody
|
|
640
|
+
})
|
|
639
641
|
});
|
|
640
642
|
}
|
|
641
643
|
//#endregion
|
|
@@ -1149,8 +1151,8 @@ const fakerGenerator = defineGenerator({
|
|
|
1149
1151
|
schema(node, ctx) {
|
|
1150
1152
|
const { config, resolver, root } = ctx;
|
|
1151
1153
|
const { output, group, dateParser, regexGenerator, seed, locale, printer, typeMode } = ctx.options;
|
|
1152
|
-
const pluginTs = ctx.
|
|
1153
|
-
if (!node.name
|
|
1154
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
1155
|
+
if (!node.name) return;
|
|
1154
1156
|
const tsResolver = ctx.driver.getResolver(pluginTsName);
|
|
1155
1157
|
const schemaName = node.name;
|
|
1156
1158
|
const isEnumSchema = !!ast.narrowSchema(node, ast.schemaTypes.enum);
|
|
@@ -1271,8 +1273,7 @@ const fakerGenerator = defineGenerator({
|
|
|
1271
1273
|
operation(node, ctx) {
|
|
1272
1274
|
const { config, resolver, root } = ctx;
|
|
1273
1275
|
const { output, group, dateParser, regexGenerator, seed, locale, printer, typeMode } = ctx.options;
|
|
1274
|
-
const pluginTs = ctx.
|
|
1275
|
-
if (!pluginTs) return;
|
|
1276
|
+
const pluginTs = ctx.requirePlugin(pluginTsName);
|
|
1276
1277
|
const tsResolver = ctx.driver.getResolver(pluginTsName);
|
|
1277
1278
|
const { path: pathParams, query: queryParams, header: headerParams } = getOperationParameters(node);
|
|
1278
1279
|
const paramGroups = [
|
|
@@ -1556,6 +1557,7 @@ const pluginFaker = definePlugin((options) => {
|
|
|
1556
1557
|
options,
|
|
1557
1558
|
dependencies: [pluginTsName],
|
|
1558
1559
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1560
|
+
ctx.requirePlugin(pluginTsName);
|
|
1559
1561
|
ctx.setOptions({
|
|
1560
1562
|
output,
|
|
1561
1563
|
seed,
|