@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.js +17 -16
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +17 -16
- package/dist/cli.mjs.map +1 -1
- package/dist/index.js +17 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -16
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -429,7 +429,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
|
|
|
429
429
|
);
|
|
430
430
|
}
|
|
431
431
|
if (schemas.length === 1) {
|
|
432
|
-
let singleSchema = context.generatePropertySchema(schemas[0], currentSchema);
|
|
432
|
+
let singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
|
|
433
433
|
if ((options == null ? void 0 : options.passthrough) && !singleSchema.includes(".catchall(")) {
|
|
434
434
|
singleSchema = `${singleSchema}.catchall(z.unknown())`;
|
|
435
435
|
}
|
|
@@ -445,7 +445,7 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
|
|
|
445
445
|
console.warn(
|
|
446
446
|
`[openapi-to-zod] Warning: Discriminator "${discriminator}" is not required in schemas: ${discriminatorCheck.invalidSchemas.join(", ")}. Falling back to z.union() instead of z.discriminatedUnion().`
|
|
447
447
|
);
|
|
448
|
-
let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
|
|
448
|
+
let schemaStrings3 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
|
|
449
449
|
if (options == null ? void 0 : options.passthrough) {
|
|
450
450
|
schemaStrings3 = schemaStrings3.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
|
|
451
451
|
}
|
|
@@ -453,14 +453,14 @@ function generateUnion(schemas, discriminator, isNullable2, context, options, cu
|
|
|
453
453
|
const union3 = `z.union([${schemaStrings3.join(", ")}]).describe("${fallbackDescription}")`;
|
|
454
454
|
return wrapNullable(union3, isNullable2);
|
|
455
455
|
}
|
|
456
|
-
let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema));
|
|
456
|
+
let schemaStrings2 = resolvedSchemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
|
|
457
457
|
if (options == null ? void 0 : options.passthrough) {
|
|
458
458
|
schemaStrings2 = schemaStrings2.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
|
|
459
459
|
}
|
|
460
460
|
const union2 = `z.discriminatedUnion("${discriminator}", [${schemaStrings2.join(", ")}])`;
|
|
461
461
|
return wrapNullable(union2, isNullable2);
|
|
462
462
|
}
|
|
463
|
-
let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema));
|
|
463
|
+
let schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
|
|
464
464
|
if (options == null ? void 0 : options.passthrough) {
|
|
465
465
|
schemaStrings = schemaStrings.map((s) => s.includes(".catchall(") ? s : `${s}.catchall(z.unknown())`);
|
|
466
466
|
}
|
|
@@ -520,9 +520,9 @@ function detectConflictingProperties(schemas, context) {
|
|
|
520
520
|
}
|
|
521
521
|
return conflicts;
|
|
522
522
|
}
|
|
523
|
-
function generateAllOf(schemas, isNullable2, context, currentSchema
|
|
523
|
+
function generateAllOf(schemas, isNullable2, context, currentSchema) {
|
|
524
524
|
if (schemas.length === 1) {
|
|
525
|
-
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false,
|
|
525
|
+
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, true);
|
|
526
526
|
return wrapNullable(singleSchema, isNullable2);
|
|
527
527
|
}
|
|
528
528
|
const conflicts = detectConflictingProperties(schemas, context);
|
|
@@ -536,23 +536,23 @@ function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNul
|
|
|
536
536
|
const allObjects = schemas.every((s) => s.type === "object" || s.properties || s.$ref || s.allOf);
|
|
537
537
|
let result;
|
|
538
538
|
if (allObjects) {
|
|
539
|
-
let merged = context.generatePropertySchema(schemas[0], currentSchema, false);
|
|
539
|
+
let merged = context.generatePropertySchema(schemas[0], currentSchema, false, true);
|
|
540
540
|
for (let i = 1; i < schemas.length; i++) {
|
|
541
541
|
const schema = schemas[i];
|
|
542
542
|
if (schema.$ref) {
|
|
543
|
-
const refSchema = context.generatePropertySchema(schema, currentSchema, false);
|
|
543
|
+
const refSchema = context.generatePropertySchema(schema, currentSchema, false, true);
|
|
544
544
|
merged = `${merged}.extend(${refSchema}.shape)`;
|
|
545
545
|
} else if (context.generateInlineObjectShape && (schema.properties || schema.type === "object")) {
|
|
546
546
|
const inlineShape = context.generateInlineObjectShape(schema, currentSchema);
|
|
547
547
|
merged = `${merged}.extend(${inlineShape})`;
|
|
548
548
|
} else {
|
|
549
|
-
const schemaString = context.generatePropertySchema(schema, currentSchema, false);
|
|
549
|
+
const schemaString = context.generatePropertySchema(schema, currentSchema, false, true);
|
|
550
550
|
merged = `${merged}.extend(${schemaString}.shape)`;
|
|
551
551
|
}
|
|
552
552
|
}
|
|
553
553
|
result = merged;
|
|
554
554
|
} else {
|
|
555
|
-
const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false));
|
|
555
|
+
const schemaStrings = schemas.map((s) => context.generatePropertySchema(s, currentSchema, false, true));
|
|
556
556
|
let merged = schemaStrings[0];
|
|
557
557
|
for (let i = 1; i < schemaStrings.length; i++) {
|
|
558
558
|
merged = `${merged}.and(${schemaStrings[i]})`;
|
|
@@ -1413,17 +1413,16 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1413
1413
|
return wrapNullable(zodUnion, nullable);
|
|
1414
1414
|
}
|
|
1415
1415
|
if (schema.allOf) {
|
|
1416
|
-
const
|
|
1416
|
+
const compositionNullable = isNullable(schema, false);
|
|
1417
1417
|
let composition = generateAllOf(
|
|
1418
1418
|
schema.allOf,
|
|
1419
|
-
|
|
1419
|
+
compositionNullable,
|
|
1420
1420
|
{
|
|
1421
1421
|
generatePropertySchema: this.generatePropertySchema.bind(this),
|
|
1422
1422
|
generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
|
|
1423
1423
|
resolveSchemaRef: this.resolveSchemaRef.bind(this)
|
|
1424
1424
|
},
|
|
1425
|
-
currentSchema
|
|
1426
|
-
explicitNullableFalse
|
|
1425
|
+
currentSchema
|
|
1427
1426
|
);
|
|
1428
1427
|
if (schema.unevaluatedProperties !== void 0) {
|
|
1429
1428
|
composition = this.applyUnevaluatedProperties(composition, schema);
|
|
@@ -1431,11 +1430,12 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1431
1430
|
return composition;
|
|
1432
1431
|
}
|
|
1433
1432
|
if (schema.oneOf) {
|
|
1433
|
+
const compositionNullable = isNullable(schema, false);
|
|
1434
1434
|
const needsPassthrough = schema.unevaluatedProperties !== void 0;
|
|
1435
1435
|
let composition = generateUnion(
|
|
1436
1436
|
schema.oneOf,
|
|
1437
1437
|
(_b = schema.discriminator) == null ? void 0 : _b.propertyName,
|
|
1438
|
-
|
|
1438
|
+
compositionNullable,
|
|
1439
1439
|
{
|
|
1440
1440
|
generatePropertySchema: this.generatePropertySchema.bind(this),
|
|
1441
1441
|
resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),
|
|
@@ -1453,11 +1453,12 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1453
1453
|
return composition;
|
|
1454
1454
|
}
|
|
1455
1455
|
if (schema.anyOf) {
|
|
1456
|
+
const compositionNullable = isNullable(schema, false);
|
|
1456
1457
|
const needsPassthrough = schema.unevaluatedProperties !== void 0;
|
|
1457
1458
|
let composition = generateUnion(
|
|
1458
1459
|
schema.anyOf,
|
|
1459
1460
|
(_d = schema.discriminator) == null ? void 0 : _d.propertyName,
|
|
1460
|
-
|
|
1461
|
+
compositionNullable,
|
|
1461
1462
|
{
|
|
1462
1463
|
generatePropertySchema: this.generatePropertySchema.bind(this),
|
|
1463
1464
|
resolveDiscriminatorMapping: this.resolveDiscriminatorMapping.bind(this),
|