@cerios/openapi-to-zod 1.3.0 → 1.3.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/cli.js +25 -17
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +25 -17
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +20 -16
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -16
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.mts +44 -2
- package/dist/internal.d.ts +44 -2
- package/dist/internal.js +46 -4
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +45 -4
- package/dist/internal.mjs.map +1 -1
- package/dist/{types-B3GgqGzM.d.mts → types-DZ4Bw-D5.d.mts} +14 -3
- package/dist/{types-B3GgqGzM.d.ts → types-DZ4Bw-D5.d.ts} +14 -3
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -86,12 +86,12 @@ function toCamelCase(str, options) {
|
|
|
86
86
|
name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
87
87
|
}
|
|
88
88
|
if (options == null ? void 0 : options.prefix) {
|
|
89
|
-
const prefix = options.prefix.toLowerCase();
|
|
89
|
+
const prefix = options.prefix.charAt(0).toLowerCase() + options.prefix.slice(1);
|
|
90
90
|
name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
91
91
|
}
|
|
92
92
|
if (options == null ? void 0 : options.suffix) {
|
|
93
|
-
const suffix = options.suffix;
|
|
94
|
-
name = name + suffix
|
|
93
|
+
const suffix = options.suffix.charAt(0).toUpperCase() + options.suffix.slice(1);
|
|
94
|
+
name = name + suffix;
|
|
95
95
|
}
|
|
96
96
|
return name;
|
|
97
97
|
}
|
|
@@ -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, explicitNullableFalse = false) {
|
|
524
524
|
if (schemas.length === 1) {
|
|
525
|
-
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false);
|
|
525
|
+
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
|
|
526
526
|
return wrapNullable(singleSchema, isNullable2);
|
|
527
527
|
}
|
|
528
528
|
const conflicts = detectConflictingProperties(schemas, context);
|
|
@@ -1337,12 +1337,21 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1337
1337
|
}
|
|
1338
1338
|
/**
|
|
1339
1339
|
* Generate Zod schema for a property
|
|
1340
|
+
* @param schema - The OpenAPI schema to generate
|
|
1341
|
+
* @param currentSchema - The name of the current schema being processed (for circular ref detection)
|
|
1342
|
+
* @param isTopLevel - Whether this is a top-level schema definition
|
|
1343
|
+
* @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
|
|
1340
1344
|
*/
|
|
1341
|
-
generatePropertySchema(schema, currentSchema, isTopLevel = false) {
|
|
1345
|
+
generatePropertySchema(schema, currentSchema, isTopLevel = false, suppressDefaultNullable = false) {
|
|
1342
1346
|
var _a, _b, _c, _d, _e;
|
|
1343
1347
|
const isCacheable = !schema.$ref && !schema.allOf && !schema.oneOf && !schema.anyOf && !currentSchema;
|
|
1344
1348
|
if (isCacheable) {
|
|
1345
|
-
const cacheKey = JSON.stringify({
|
|
1349
|
+
const cacheKey = JSON.stringify({
|
|
1350
|
+
schema,
|
|
1351
|
+
type: this.context.schemaType,
|
|
1352
|
+
mode: this.context.mode,
|
|
1353
|
+
suppressDefaultNullable
|
|
1354
|
+
});
|
|
1346
1355
|
const cached = this.schemaCache.get(cacheKey);
|
|
1347
1356
|
if (cached) {
|
|
1348
1357
|
return cached;
|
|
@@ -1351,10 +1360,9 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1351
1360
|
if ((this.context.schemaType === "request" || this.context.schemaType === "response") && schema.properties) {
|
|
1352
1361
|
schema = this.filterNestedProperties(schema);
|
|
1353
1362
|
}
|
|
1354
|
-
const isSchemaRef = !!schema.$ref;
|
|
1355
1363
|
const isEnum = !!schema.enum;
|
|
1356
1364
|
const isConst = schema.const !== void 0;
|
|
1357
|
-
const shouldApplyDefaultNullable = !isTopLevel && !
|
|
1365
|
+
const shouldApplyDefaultNullable = !isTopLevel && !isEnum && !isConst && !suppressDefaultNullable;
|
|
1358
1366
|
const effectiveDefaultNullable = shouldApplyDefaultNullable ? this.context.defaultNullable : false;
|
|
1359
1367
|
const nullable = isNullable(schema, effectiveDefaultNullable);
|
|
1360
1368
|
if (hasMultipleTypes(schema)) {
|
|
@@ -1405,6 +1413,7 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1405
1413
|
return wrapNullable(zodUnion, nullable);
|
|
1406
1414
|
}
|
|
1407
1415
|
if (schema.allOf) {
|
|
1416
|
+
const explicitNullableFalse = schema.nullable === false;
|
|
1408
1417
|
let composition = generateAllOf(
|
|
1409
1418
|
schema.allOf,
|
|
1410
1419
|
nullable,
|
|
@@ -1413,7 +1422,8 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
1413
1422
|
generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
|
|
1414
1423
|
resolveSchemaRef: this.resolveSchemaRef.bind(this)
|
|
1415
1424
|
},
|
|
1416
|
-
currentSchema
|
|
1425
|
+
currentSchema,
|
|
1426
|
+
explicitNullableFalse
|
|
1417
1427
|
);
|
|
1418
1428
|
if (schema.unevaluatedProperties !== void 0) {
|
|
1419
1429
|
composition = this.applyUnevaluatedProperties(composition, schema);
|
|
@@ -1947,12 +1957,6 @@ var OpenApiGenerator = class {
|
|
|
1947
1957
|
* Generate the complete output file
|
|
1948
1958
|
*/
|
|
1949
1959
|
generate() {
|
|
1950
|
-
if (!this.options.output) {
|
|
1951
|
-
throw new ConfigurationError(
|
|
1952
|
-
"Output path is required when calling generate(). Either provide an 'output' option or use generateString() to get the result as a string.",
|
|
1953
|
-
{ hasOutput: false }
|
|
1954
|
-
);
|
|
1955
|
-
}
|
|
1956
1960
|
const output = this.generateString();
|
|
1957
1961
|
const normalizedOutput = normalize(this.options.output);
|
|
1958
1962
|
this.ensureDirectoryExists(normalizedOutput);
|