@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.mjs
CHANGED
|
@@ -5151,12 +5151,12 @@ function toCamelCase(str, options) {
|
|
|
5151
5151
|
name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
|
5152
5152
|
}
|
|
5153
5153
|
if (options == null ? void 0 : options.prefix) {
|
|
5154
|
-
const prefix = options.prefix.toLowerCase();
|
|
5154
|
+
const prefix = options.prefix.charAt(0).toLowerCase() + options.prefix.slice(1);
|
|
5155
5155
|
name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
|
|
5156
5156
|
}
|
|
5157
5157
|
if (options == null ? void 0 : options.suffix) {
|
|
5158
|
-
const suffix = options.suffix;
|
|
5159
|
-
name = name + suffix
|
|
5158
|
+
const suffix = options.suffix.charAt(0).toUpperCase() + options.suffix.slice(1);
|
|
5159
|
+
name = name + suffix;
|
|
5160
5160
|
}
|
|
5161
5161
|
return name;
|
|
5162
5162
|
}
|
|
@@ -5631,9 +5631,9 @@ function detectConflictingProperties(schemas, context) {
|
|
|
5631
5631
|
}
|
|
5632
5632
|
return conflicts;
|
|
5633
5633
|
}
|
|
5634
|
-
function generateAllOf(schemas, isNullable2, context, currentSchema) {
|
|
5634
|
+
function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNullableFalse = false) {
|
|
5635
5635
|
if (schemas.length === 1) {
|
|
5636
|
-
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false);
|
|
5636
|
+
const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
|
|
5637
5637
|
return wrapNullable(singleSchema, isNullable2);
|
|
5638
5638
|
}
|
|
5639
5639
|
const conflicts = detectConflictingProperties(schemas, context);
|
|
@@ -6499,12 +6499,21 @@ var init_property_generator = __esm({
|
|
|
6499
6499
|
}
|
|
6500
6500
|
/**
|
|
6501
6501
|
* Generate Zod schema for a property
|
|
6502
|
+
* @param schema - The OpenAPI schema to generate
|
|
6503
|
+
* @param currentSchema - The name of the current schema being processed (for circular ref detection)
|
|
6504
|
+
* @param isTopLevel - Whether this is a top-level schema definition
|
|
6505
|
+
* @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
|
|
6502
6506
|
*/
|
|
6503
|
-
generatePropertySchema(schema, currentSchema, isTopLevel = false) {
|
|
6507
|
+
generatePropertySchema(schema, currentSchema, isTopLevel = false, suppressDefaultNullable = false) {
|
|
6504
6508
|
var _a, _b, _c, _d, _e;
|
|
6505
6509
|
const isCacheable = !schema.$ref && !schema.allOf && !schema.oneOf && !schema.anyOf && !currentSchema;
|
|
6506
6510
|
if (isCacheable) {
|
|
6507
|
-
const cacheKey = JSON.stringify({
|
|
6511
|
+
const cacheKey = JSON.stringify({
|
|
6512
|
+
schema,
|
|
6513
|
+
type: this.context.schemaType,
|
|
6514
|
+
mode: this.context.mode,
|
|
6515
|
+
suppressDefaultNullable
|
|
6516
|
+
});
|
|
6508
6517
|
const cached = this.schemaCache.get(cacheKey);
|
|
6509
6518
|
if (cached) {
|
|
6510
6519
|
return cached;
|
|
@@ -6513,10 +6522,9 @@ var init_property_generator = __esm({
|
|
|
6513
6522
|
if ((this.context.schemaType === "request" || this.context.schemaType === "response") && schema.properties) {
|
|
6514
6523
|
schema = this.filterNestedProperties(schema);
|
|
6515
6524
|
}
|
|
6516
|
-
const isSchemaRef = !!schema.$ref;
|
|
6517
6525
|
const isEnum = !!schema.enum;
|
|
6518
6526
|
const isConst = schema.const !== void 0;
|
|
6519
|
-
const shouldApplyDefaultNullable = !isTopLevel && !
|
|
6527
|
+
const shouldApplyDefaultNullable = !isTopLevel && !isEnum && !isConst && !suppressDefaultNullable;
|
|
6520
6528
|
const effectiveDefaultNullable = shouldApplyDefaultNullable ? this.context.defaultNullable : false;
|
|
6521
6529
|
const nullable = isNullable(schema, effectiveDefaultNullable);
|
|
6522
6530
|
if (hasMultipleTypes(schema)) {
|
|
@@ -6567,6 +6575,7 @@ var init_property_generator = __esm({
|
|
|
6567
6575
|
return wrapNullable(zodUnion, nullable);
|
|
6568
6576
|
}
|
|
6569
6577
|
if (schema.allOf) {
|
|
6578
|
+
const explicitNullableFalse = schema.nullable === false;
|
|
6570
6579
|
let composition = generateAllOf(
|
|
6571
6580
|
schema.allOf,
|
|
6572
6581
|
nullable,
|
|
@@ -6575,7 +6584,8 @@ var init_property_generator = __esm({
|
|
|
6575
6584
|
generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
|
|
6576
6585
|
resolveSchemaRef: this.resolveSchemaRef.bind(this)
|
|
6577
6586
|
},
|
|
6578
|
-
currentSchema
|
|
6587
|
+
currentSchema,
|
|
6588
|
+
explicitNullableFalse
|
|
6579
6589
|
);
|
|
6580
6590
|
if (schema.unevaluatedProperties !== void 0) {
|
|
6581
6591
|
composition = this.applyUnevaluatedProperties(composition, schema);
|
|
@@ -7141,12 +7151,6 @@ var init_openapi_generator = __esm({
|
|
|
7141
7151
|
* Generate the complete output file
|
|
7142
7152
|
*/
|
|
7143
7153
|
generate() {
|
|
7144
|
-
if (!this.options.output) {
|
|
7145
|
-
throw new ConfigurationError(
|
|
7146
|
-
"Output path is required when calling generate(). Either provide an 'output' option or use generateString() to get the result as a string.",
|
|
7147
|
-
{ hasOutput: false }
|
|
7148
|
-
);
|
|
7149
|
-
}
|
|
7150
7154
|
const output = this.generateString();
|
|
7151
7155
|
const normalizedOutput = normalize(this.options.output);
|
|
7152
7156
|
this.ensureDirectoryExists(normalizedOutput);
|
|
@@ -7875,7 +7879,8 @@ var init_config_schemas = __esm({
|
|
|
7875
7879
|
mode: z.enum(["strict", "normal", "loose"]).optional(),
|
|
7876
7880
|
useDescribe: z.boolean().optional(),
|
|
7877
7881
|
includeDescriptions: z.boolean().optional(),
|
|
7878
|
-
defaultNullable: z.boolean().optional()
|
|
7882
|
+
defaultNullable: z.boolean().optional(),
|
|
7883
|
+
emptyObjectBehavior: z.enum(["strict", "loose", "record"]).optional()
|
|
7879
7884
|
});
|
|
7880
7885
|
OperationFiltersSchema = z.strictObject({
|
|
7881
7886
|
includeTags: z.array(z.string()).optional(),
|
|
@@ -8007,6 +8012,7 @@ function mergeConfigWithDefaults(config) {
|
|
|
8007
8012
|
includeDescriptions: defaults.includeDescriptions,
|
|
8008
8013
|
useDescribe: defaults.useDescribe,
|
|
8009
8014
|
defaultNullable: defaults.defaultNullable,
|
|
8015
|
+
emptyObjectBehavior: defaults.emptyObjectBehavior,
|
|
8010
8016
|
schemaType: defaults.schemaType,
|
|
8011
8017
|
prefix: defaults.prefix,
|
|
8012
8018
|
suffix: defaults.suffix,
|
|
@@ -8033,6 +8039,7 @@ var init_config_loader = __esm({
|
|
|
8033
8039
|
includeDescriptions: z2.boolean().optional(),
|
|
8034
8040
|
useDescribe: z2.boolean().optional(),
|
|
8035
8041
|
defaultNullable: z2.boolean().optional(),
|
|
8042
|
+
emptyObjectBehavior: z2.enum(["strict", "loose", "record"]).optional(),
|
|
8036
8043
|
schemaType: z2.enum(["all", "request", "response"]).optional(),
|
|
8037
8044
|
prefix: z2.string().optional(),
|
|
8038
8045
|
suffix: z2.string().optional(),
|
|
@@ -8065,6 +8072,7 @@ var init_config_loader = __esm({
|
|
|
8065
8072
|
includeDescriptions: z2.boolean().optional(),
|
|
8066
8073
|
useDescribe: z2.boolean().optional(),
|
|
8067
8074
|
defaultNullable: z2.boolean().optional(),
|
|
8075
|
+
emptyObjectBehavior: z2.enum(["strict", "loose", "record"]).optional(),
|
|
8068
8076
|
schemaType: z2.enum(["all", "request", "response"]).optional(),
|
|
8069
8077
|
prefix: z2.string().optional(),
|
|
8070
8078
|
suffix: z2.string().optional(),
|