@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/cli.js
CHANGED
|
@@ -5152,12 +5152,12 @@ function toCamelCase(str, options) {
|
|
|
5152
5152
|
name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
5153
5153
|
}
|
|
5154
5154
|
if (options == null ? void 0 : options.prefix) {
|
|
5155
|
-
const prefix = options.prefix.toLowerCase();
|
|
5155
|
+
const prefix = options.prefix.charAt(0).toLowerCase() + options.prefix.slice(1);
|
|
5156
5156
|
name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
5157
5157
|
}
|
|
5158
5158
|
if (options == null ? void 0 : options.suffix) {
|
|
5159
|
-
const suffix = options.suffix;
|
|
5160
|
-
name = name + suffix
|
|
5159
|
+
const suffix = options.suffix.charAt(0).toUpperCase() + options.suffix.slice(1);
|
|
5160
|
+
name = name + suffix;
|
|
5161
5161
|
}
|
|
5162
5162
|
return name;
|
|
5163
5163
|
}
|
|
@@ -5597,9 +5597,9 @@ function detectConflictingProperties(schemas, context) {
|
|
|
5597
5597
|
}
|
|
5598
5598
|
return conflicts;
|
|
5599
5599
|
}
|
|
5600
|
-
function generateAllOf(schemas, isNullable2, context, currentSchema) {
|
|
5600
|
+
function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNullableFalse = false) {
|
|
5601
5601
|
if (schemas.length === 1) {
|
|
5602
|
-
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false);
|
|
5602
|
+
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
|
|
5603
5603
|
return wrapNullable(singleSchema, isNullable2);
|
|
5604
5604
|
}
|
|
5605
5605
|
const conflicts = detectConflictingProperties(schemas, context);
|
|
@@ -6420,12 +6420,21 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6420
6420
|
}
|
|
6421
6421
|
/**
|
|
6422
6422
|
* Generate Zod schema for a property
|
|
6423
|
+
* @param schema - The OpenAPI schema to generate
|
|
6424
|
+
* @param currentSchema - The name of the current schema being processed (for circular ref detection)
|
|
6425
|
+
* @param isTopLevel - Whether this is a top-level schema definition
|
|
6426
|
+
* @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
|
|
6423
6427
|
*/
|
|
6424
|
-
generatePropertySchema(schema, currentSchema, isTopLevel = false) {
|
|
6428
|
+
generatePropertySchema(schema, currentSchema, isTopLevel = false, suppressDefaultNullable = false) {
|
|
6425
6429
|
var _a, _b, _c, _d, _e;
|
|
6426
6430
|
const isCacheable = !schema.$ref && !schema.allOf && !schema.oneOf && !schema.anyOf && !currentSchema;
|
|
6427
6431
|
if (isCacheable) {
|
|
6428
|
-
const cacheKey = JSON.stringify({
|
|
6432
|
+
const cacheKey = JSON.stringify({
|
|
6433
|
+
schema,
|
|
6434
|
+
type: this.context.schemaType,
|
|
6435
|
+
mode: this.context.mode,
|
|
6436
|
+
suppressDefaultNullable
|
|
6437
|
+
});
|
|
6429
6438
|
const cached = this.schemaCache.get(cacheKey);
|
|
6430
6439
|
if (cached) {
|
|
6431
6440
|
return cached;
|
|
@@ -6434,10 +6443,9 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6434
6443
|
if ((this.context.schemaType === "request" || this.context.schemaType === "response") && schema.properties) {
|
|
6435
6444
|
schema = this.filterNestedProperties(schema);
|
|
6436
6445
|
}
|
|
6437
|
-
const isSchemaRef = !!schema.$ref;
|
|
6438
6446
|
const isEnum = !!schema.enum;
|
|
6439
6447
|
const isConst = schema.const !== void 0;
|
|
6440
|
-
const shouldApplyDefaultNullable = !isTopLevel && !
|
|
6448
|
+
const shouldApplyDefaultNullable = !isTopLevel && !isEnum && !isConst && !suppressDefaultNullable;
|
|
6441
6449
|
const effectiveDefaultNullable = shouldApplyDefaultNullable ? this.context.defaultNullable : false;
|
|
6442
6450
|
const nullable = isNullable(schema, effectiveDefaultNullable);
|
|
6443
6451
|
if (hasMultipleTypes(schema)) {
|
|
@@ -6488,6 +6496,7 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6488
6496
|
return wrapNullable(zodUnion, nullable);
|
|
6489
6497
|
}
|
|
6490
6498
|
if (schema.allOf) {
|
|
6499
|
+
const explicitNullableFalse = schema.nullable === false;
|
|
6491
6500
|
let composition = generateAllOf(
|
|
6492
6501
|
schema.allOf,
|
|
6493
6502
|
nullable,
|
|
@@ -6496,7 +6505,8 @@ var _PropertyGenerator = class _PropertyGenerator {
|
|
|
6496
6505
|
generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
|
|
6497
6506
|
resolveSchemaRef: this.resolveSchemaRef.bind(this)
|
|
6498
6507
|
},
|
|
6499
|
-
currentSchema
|
|
6508
|
+
currentSchema,
|
|
6509
|
+
explicitNullableFalse
|
|
6500
6510
|
);
|
|
6501
6511
|
if (schema.unevaluatedProperties !== void 0) {
|
|
6502
6512
|
composition = this.applyUnevaluatedProperties(composition, schema);
|
|
@@ -7032,12 +7042,6 @@ var OpenApiGenerator = class {
|
|
|
7032
7042
|
* Generate the complete output file
|
|
7033
7043
|
*/
|
|
7034
7044
|
generate() {
|
|
7035
|
-
if (!this.options.output) {
|
|
7036
|
-
throw new ConfigurationError(
|
|
7037
|
-
"Output path is required when calling generate(). Either provide an 'output' option or use generateString() to get the result as a string.",
|
|
7038
|
-
{ hasOutput: false }
|
|
7039
|
-
);
|
|
7040
|
-
}
|
|
7041
7045
|
const output = this.generateString();
|
|
7042
7046
|
const normalizedOutput = (0, import_node_path.normalize)(this.options.output);
|
|
7043
7047
|
this.ensureDirectoryExists(normalizedOutput);
|
|
@@ -7765,7 +7769,8 @@ var RequestResponseOptionsSchema = import_zod.z.strictObject({
|
|
|
7765
7769
|
mode: import_zod.z.enum(["strict", "normal", "loose"]).optional(),
|
|
7766
7770
|
useDescribe: import_zod.z.boolean().optional(),
|
|
7767
7771
|
includeDescriptions: import_zod.z.boolean().optional(),
|
|
7768
|
-
defaultNullable: import_zod.z.boolean().optional()
|
|
7772
|
+
defaultNullable: import_zod.z.boolean().optional(),
|
|
7773
|
+
emptyObjectBehavior: import_zod.z.enum(["strict", "loose", "record"]).optional()
|
|
7769
7774
|
});
|
|
7770
7775
|
var OperationFiltersSchema = import_zod.z.strictObject({
|
|
7771
7776
|
includeTags: import_zod.z.array(import_zod.z.string()).optional(),
|
|
@@ -7849,6 +7854,7 @@ var OpenApiGeneratorOptionsSchema = import_zod2.z.strictObject({
|
|
|
7849
7854
|
includeDescriptions: import_zod2.z.boolean().optional(),
|
|
7850
7855
|
useDescribe: import_zod2.z.boolean().optional(),
|
|
7851
7856
|
defaultNullable: import_zod2.z.boolean().optional(),
|
|
7857
|
+
emptyObjectBehavior: import_zod2.z.enum(["strict", "loose", "record"]).optional(),
|
|
7852
7858
|
schemaType: import_zod2.z.enum(["all", "request", "response"]).optional(),
|
|
7853
7859
|
prefix: import_zod2.z.string().optional(),
|
|
7854
7860
|
suffix: import_zod2.z.string().optional(),
|
|
@@ -7881,6 +7887,7 @@ var ConfigFileSchema = import_zod2.z.strictObject({
|
|
|
7881
7887
|
includeDescriptions: import_zod2.z.boolean().optional(),
|
|
7882
7888
|
useDescribe: import_zod2.z.boolean().optional(),
|
|
7883
7889
|
defaultNullable: import_zod2.z.boolean().optional(),
|
|
7890
|
+
emptyObjectBehavior: import_zod2.z.enum(["strict", "loose", "record"]).optional(),
|
|
7884
7891
|
schemaType: import_zod2.z.enum(["all", "request", "response"]).optional(),
|
|
7885
7892
|
prefix: import_zod2.z.string().optional(),
|
|
7886
7893
|
suffix: import_zod2.z.string().optional(),
|
|
@@ -7954,6 +7961,7 @@ function mergeConfigWithDefaults(config) {
|
|
|
7954
7961
|
includeDescriptions: defaults.includeDescriptions,
|
|
7955
7962
|
useDescribe: defaults.useDescribe,
|
|
7956
7963
|
defaultNullable: defaults.defaultNullable,
|
|
7964
|
+
emptyObjectBehavior: defaults.emptyObjectBehavior,
|
|
7957
7965
|
schemaType: defaults.schemaType,
|
|
7958
7966
|
prefix: defaults.prefix,
|
|
7959
7967
|
suffix: defaults.suffix,
|