@cerios/openapi-to-zod 1.3.1 → 1.3.2

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.js CHANGED
@@ -456,7 +456,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
456
456
  );
457
457
  }
458
458
  if (schemas.length === 1) {
459
- let singleSchema = context.generatePropertySchema(schemas[0], currentSchema);
459
+ let singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
460
460
  if ((options == null ? void 0 : options.passthrough) && !singleSchema.includes(".catchall(")) {
461
461
  singleSchema = `${singleSchema}.catchall(z.unknown())`;
462
462
  }
@@ -472,7 +472,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
472
472
  console.warn(
473
473
  `[openapi-to-zod] Warning: Discriminator "${discriminator}" is not required in schemas: ${discriminatorCheck.invalidSchemas.join(", ")}. Falling back to z.union() instead of z.discriminatedUnion().`
474
474
  );
475
- let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
475
+ let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
476
476
  if (options == null ? void 0 : options.passthrough) {
477
477
  schemaStrings3 = schemaStrings3.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
478
478
  }
@@ -480,14 +480,14 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
480
480
  const union3 = `z.union([${schemaStrings3.join(", ")}]).describe("${fallbackDescription}")`;
481
481
  return wrapNullable(union3, isNullable2);
482
482
  }
483
- let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
483
+ let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
484
484
  if (options == null ? void 0 : options.passthrough) {
485
485
  schemaStrings2 = schemaStrings2.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
486
486
  }
487
487
  const union2 = `z.discriminatedUnion("${discriminator}", [${schemaStrings2.join(", ")}])`;
488
488
  return wrapNullable(union2, isNullable2);
489
489
  }
490
- let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema));
490
+ let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
491
491
  if (options == null ? void 0 : options.passthrough) {
492
492
  schemaStrings = schemaStrings.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
493
493
  }
@@ -547,9 +547,9 @@ function detectConflictingProperties(schemas, context) {
547
547
  }
548
548
  return conflicts;
549
549
  }
550
- function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNullableFalse = false) {
550
+ function generateAllOf(schemas, isNullable2, context, currentSchema) {
551
551
  if (schemas.length === 1) {
552
- const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
552
+ const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
553
553
  return wrapNullable(singleSchema, isNullable2);
554
554
  }
555
555
  const conflicts = detectConflictingProperties(schemas, context);
@@ -563,23 +563,23 @@ function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNul
563
563
  const allObjects = schemas.every((s) => s.type === "object" || s.properties || s.$ref || s.allOf);
564
564
  let result;
565
565
  if (allObjects) {
566
- let merged = context.generatePropertySchema(schemas[0], currentSchema, false);
566
+ let merged = context.generatePropertySchema(schemas[0], currentSchema, false, true);
567
567
  for (let i = 1; i < schemas.length; i++) {
568
568
  const schema = schemas[i];
569
569
  if (schema.$ref) {
570
- const refSchema = context.generatePropertySchema(schema, currentSchema, false);
570
+ const refSchema = context.generatePropertySchema(schema, currentSchema, false, true);
571
571
  merged = `${merged}.extend(${refSchema}.shape)`;
572
572
  } else if (context.generateInlineObjectShape && (schema.properties || schema.type === "object")) {
573
573
  const inlineShape = context.generateInlineObjectShape(schema, currentSchema);
574
574
  merged = `${merged}.extend(${inlineShape})`;
575
575
  } else {
576
- const schemaString = context.generatePropertySchema(schema, currentSchema, false);
576
+ const schemaString = context.generatePropertySchema(schema, currentSchema, false, true);
577
577
  merged = `${merged}.extend(${schemaString}.shape)`;
578
578
  }
579
579
  }
580
580
  result = merged;
581
581
  } else {
582
- const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false));
582
+ const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
583
583
  let merged = schemaStrings[0];
584
584
  for (let i = 1; i < schemaStrings.length; i++) {
585
585
  merged = `${merged}.and(${schemaStrings[i]})`;
@@ -1440,17 +1440,16 @@ var _PropertyGenerator = class _PropertyGenerator {
1440
1440
  return wrapNullable(zodUnion, nullable);
1441
1441
  }
1442
1442
  if (schema.allOf) {
1443
- const explicitNullableFalse = schema.nullable === false;
1443
+ const compositionNullable = isNullable(schema, false);
1444
1444
  let composition = generateAllOf(
1445
1445
  schema.allOf,
1446
- nullable,
1446
+ compositionNullable,
1447
1447
  {
1448
1448
  generatePropertySchema: this.generatePropertySchema.bind(this),
1449
1449
  generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
1450
1450
  resolveSchemaRef: this.resolveSchemaRef.bind(this)
1451
1451
  },
1452
- currentSchema,
1453
- explicitNullableFalse
1452
+ currentSchema
1454
1453
  );
1455
1454
  if (schema.unevaluatedProperties !== void 0) {
1456
1455
  composition = this.applyUnevaluatedProperties(composition, schema);
@@ -1458,11 +1457,12 @@ var _PropertyGenerator = class _PropertyGenerator {
1458
1457
  return composition;
1459
1458
  }
1460
1459
  if (schema.oneOf) {
1460
+ const compositionNullable = isNullable(schema, false);
1461
1461
  const needsPassthrough = schema.unevaluatedProperties !== void 0;
1462
1462
  let composition = generateUnion(
1463
1463
  schema.oneOf,
1464
1464
  (_b = schema.discriminator) == null ? void 0 : _b.propertyName,
1465
- nullable,
1465
+ compositionNullable,
1466
1466
  {
1467
1467
  generatePropertySchema: this.generatePropertySchema.bind(this),
1468
1468
  resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),
@@ -1480,11 +1480,12 @@ var _PropertyGenerator = class _PropertyGenerator {
1480
1480
  return composition;
1481
1481
  }
1482
1482
  if (schema.anyOf) {
1483
+ const compositionNullable = isNullable(schema, false);
1483
1484
  const needsPassthrough = schema.unevaluatedProperties !== void 0;
1484
1485
  let composition = generateUnion(
1485
1486
  schema.anyOf,
1486
1487
  (_d = schema.discriminator) == null ? void 0 : _d.propertyName,
1487
- nullable,
1488
+ compositionNullable,
1488
1489
  {
1489
1490
  generatePropertySchema: this.generatePropertySchema.bind(this),
1490
1491
  resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),