@kubb/plugin-faker 5.0.10 → 5.0.11

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 CHANGED
@@ -532,15 +532,23 @@ function getScalarType(node, typeName) {
532
532
  }
533
533
  }
534
534
  /**
535
+ * A nullable scalar inlines its primitive instead of naming the generated type, so the
536
+ * nullability the type plugin emitted has to be reapplied here. Non-scalars keep `typeName`,
537
+ * which already carries it.
538
+ */
539
+ function withNullability(type, node) {
540
+ return node.nullable ? `${type} | null` : type;
541
+ }
542
+ /**
535
543
  * Resolves faker type usage information for a schema.
536
544
  * Determines the data type, return type, and whether it uses the type name.
537
545
  */
538
546
  function resolveFakerTypeUsage(node, typeName, canOverride) {
539
547
  const isScalar = SCALAR_TYPES$1.has(node.type);
540
548
  let dataType = `Partial<${typeName}>`;
541
- if (isScalar) dataType = getScalarType(node, typeName);
549
+ if (isScalar) dataType = withNullability(getScalarType(node, typeName), node);
542
550
  let returnType = canOverride ? typeName : null;
543
- if (isScalar) returnType = getScalarType(node, typeName);
551
+ if (isScalar) returnType = withNullability(getScalarType(node, typeName), node);
544
552
  return {
545
553
  dataType,
546
554
  returnType,
@@ -577,7 +585,7 @@ function Faker({ node, description, name, typeName, printer, canOverride }) {
577
585
  const fakerTextWithOverride = (() => {
578
586
  if (canOverride && node.type === "tuple") return `data && data.length === ${node.items?.length ?? 0} && !data.includes(undefined) ? data : ${fakerText}`;
579
587
  if (canOverride && isArray) return `[\n ...${fakerText},\n ...(data || []).filter((item) => item !== undefined),\n]`;
580
- if (canOverride && (isScalar || isUnion)) return `data ?? ${fakerText}`;
588
+ if (canOverride && (isScalar || isUnion)) return node.nullable ? `data !== undefined ? data : ${fakerText}` : `data ?? ${fakerText}`;
581
589
  return fakerText;
582
590
  })();
583
591
  const { dataType, returnType: resolvedReturnType } = resolveFakerTypeUsage(node, typeName, canOverride);