@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/cli.mjs CHANGED
@@ -5540,7 +5540,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
5540
5540
  );
5541
5541
  }
5542
5542
  if (schemas.length === 1) {
5543
- let singleSchema = context.generatePropertySchema(schemas[0], currentSchema);
5543
+ let singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
5544
5544
  if ((options == null ? void 0 : options.passthrough) && !singleSchema.includes(".catchall(")) {
5545
5545
  singleSchema = `${singleSchema}.catchall(z.unknown())`;
5546
5546
  }
@@ -5556,7 +5556,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
5556
5556
  console.warn(
5557
5557
  `[openapi-to-zod] Warning: Discriminator "${discriminator}" is not required in schemas: ${discriminatorCheck.invalidSchemas.join(", ")}. Falling back to z.union() instead of z.discriminatedUnion().`
5558
5558
  );
5559
- let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
5559
+ let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
5560
5560
  if (options == null ? void 0 : options.passthrough) {
5561
5561
  schemaStrings3 = schemaStrings3.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
5562
5562
  }
@@ -5564,14 +5564,14 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
5564
5564
  const union3 = `z.union([${schemaStrings3.join(", ")}]).describe("${fallbackDescription}")`;
5565
5565
  return wrapNullable(union3, isNullable2);
5566
5566
  }
5567
- let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
5567
+ let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
5568
5568
  if (options == null ? void 0 : options.passthrough) {
5569
5569
  schemaStrings2 = schemaStrings2.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
5570
5570
  }
5571
5571
  const union2 = `z.discriminatedUnion("${discriminator}", [${schemaStrings2.join(", ")}])`;
5572
5572
  return wrapNullable(union2, isNullable2);
5573
5573
  }
5574
- let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema));
5574
+ let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
5575
5575
  if (options == null ? void 0 : options.passthrough) {
5576
5576
  schemaStrings = schemaStrings.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
5577
5577
  }
@@ -5631,9 +5631,9 @@ function detectConflictingProperties(schemas, context) {
5631
5631
  }
5632
5632
  return conflicts;
5633
5633
  }
5634
- function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNullableFalse = false) {
5634
+ function generateAllOf(schemas, isNullable2, context, currentSchema) {
5635
5635
  if (schemas.length === 1) {
5636
- const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
5636
+ const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
5637
5637
  return wrapNullable(singleSchema, isNullable2);
5638
5638
  }
5639
5639
  const conflicts = detectConflictingProperties(schemas, context);
@@ -5647,23 +5647,23 @@ function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNul
5647
5647
  const allObjects = schemas.every((s) => s.type === "object" || s.properties || s.$ref || s.allOf);
5648
5648
  let result;
5649
5649
  if (allObjects) {
5650
- let merged = context.generatePropertySchema(schemas[0], currentSchema, false);
5650
+ let merged = context.generatePropertySchema(schemas[0], currentSchema, false, true);
5651
5651
  for (let i = 1; i < schemas.length; i++) {
5652
5652
  const schema = schemas[i];
5653
5653
  if (schema.$ref) {
5654
- const refSchema = context.generatePropertySchema(schema, currentSchema, false);
5654
+ const refSchema = context.generatePropertySchema(schema, currentSchema, false, true);
5655
5655
  merged = `${merged}.extend(${refSchema}.shape)`;
5656
5656
  } else if (context.generateInlineObjectShape && (schema.properties || schema.type === "object")) {
5657
5657
  const inlineShape = context.generateInlineObjectShape(schema, currentSchema);
5658
5658
  merged = `${merged}.extend(${inlineShape})`;
5659
5659
  } else {
5660
- const schemaString = context.generatePropertySchema(schema, currentSchema, false);
5660
+ const schemaString = context.generatePropertySchema(schema, currentSchema, false, true);
5661
5661
  merged = `${merged}.extend(${schemaString}.shape)`;
5662
5662
  }
5663
5663
  }
5664
5664
  result = merged;
5665
5665
  } else {
5666
- const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false));
5666
+ const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
5667
5667
  let merged = schemaStrings[0];
5668
5668
  for (let i = 1; i < schemaStrings.length; i++) {
5669
5669
  merged = `${merged}.and(${schemaStrings[i]})`;
@@ -6575,17 +6575,16 @@ var init_property_generator = __esm({
6575
6575
  return wrapNullable(zodUnion, nullable);
6576
6576
  }
6577
6577
  if (schema.allOf) {
6578
- const explicitNullableFalse = schema.nullable === false;
6578
+ const compositionNullable = isNullable(schema, false);
6579
6579
  let composition = generateAllOf(
6580
6580
  schema.allOf,
6581
- nullable,
6581
+ compositionNullable,
6582
6582
  {
6583
6583
  generatePropertySchema: this.generatePropertySchema.bind(this),
6584
6584
  generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
6585
6585
  resolveSchemaRef: this.resolveSchemaRef.bind(this)
6586
6586
  },
6587
- currentSchema,
6588
- explicitNullableFalse
6587
+ currentSchema
6589
6588
  );
6590
6589
  if (schema.unevaluatedProperties !== void 0) {
6591
6590
  composition = this.applyUnevaluatedProperties(composition, schema);
@@ -6593,11 +6592,12 @@ var init_property_generator = __esm({
6593
6592
  return composition;
6594
6593
  }
6595
6594
  if (schema.oneOf) {
6595
+ const compositionNullable = isNullable(schema, false);
6596
6596
  const needsPassthrough = schema.unevaluatedProperties !== void 0;
6597
6597
  let composition = generateUnion(
6598
6598
  schema.oneOf,
6599
6599
  (_b = schema.discriminator) == null ? void 0 : _b.propertyName,
6600
- nullable,
6600
+ compositionNullable,
6601
6601
  {
6602
6602
  generatePropertySchema: this.generatePropertySchema.bind(this),
6603
6603
  resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),
@@ -6615,11 +6615,12 @@ var init_property_generator = __esm({
6615
6615
  return composition;
6616
6616
  }
6617
6617
  if (schema.anyOf) {
6618
+ const compositionNullable = isNullable(schema, false);
6618
6619
  const needsPassthrough = schema.unevaluatedProperties !== void 0;
6619
6620
  let composition = generateUnion(
6620
6621
  schema.anyOf,
6621
6622
  (_d = schema.discriminator) == null ? void 0 : _d.propertyName,
6622
- nullable,
6623
+ compositionNullable,
6623
6624
  {
6624
6625
  generatePropertySchema: this.generatePropertySchema.bind(this),
6625
6626
  resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),