@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/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OpenApiGeneratorOptions } from './types-B3GgqGzM.mjs';
2
- export { C as CommonSchemaOptions, a as ConfigFile, E as ExecutionMode, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, R as RequestOptions, h as ResponseOptions, i as defineConfig } from './types-B3GgqGzM.mjs';
1
+ import { O as OpenApiGeneratorOptions } from './types-DZ4Bw-D5.mjs';
2
+ export { C as CommonSchemaOptions, a as ConfigFile, E as ExecutionMode, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, R as RequestOptions, h as ResponseOptions, i as defineConfig } from './types-DZ4Bw-D5.mjs';
3
3
 
4
4
  /**
5
5
  * Custom error classes for better error handling and debugging
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { O as OpenApiGeneratorOptions } from './types-B3GgqGzM.js';
2
- export { C as CommonSchemaOptions, a as ConfigFile, E as ExecutionMode, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, R as RequestOptions, h as ResponseOptions, i as defineConfig } from './types-B3GgqGzM.js';
1
+ import { O as OpenApiGeneratorOptions } from './types-DZ4Bw-D5.js';
2
+ export { C as CommonSchemaOptions, a as ConfigFile, E as ExecutionMode, b as OpenAPIParameter, c as OpenAPIRequestBody, d as OpenAPIResponse, e as OpenAPISchema, f as OpenAPISpec, g as OperationFilters, R as RequestOptions, h as ResponseOptions, i as defineConfig } from './types-DZ4Bw-D5.js';
3
3
 
4
4
  /**
5
5
  * Custom error classes for better error handling and debugging
package/dist/index.js CHANGED
@@ -113,12 +113,12 @@ function toCamelCase(str, options) {
113
113
  name = words[0].charAt(0).toLowerCase() + words[0].slice(1) + words.slice(1).map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
114
114
  }
115
115
  if (options == null ? void 0 : options.prefix) {
116
- const prefix = options.prefix.toLowerCase();
116
+ const prefix = options.prefix.charAt(0).toLowerCase() + options.prefix.slice(1);
117
117
  name = prefix + name.charAt(0).toUpperCase() + name.slice(1);
118
118
  }
119
119
  if (options == null ? void 0 : options.suffix) {
120
- const suffix = options.suffix;
121
- name = name + suffix.charAt(0).toUpperCase() + suffix.slice(1).toLowerCase();
120
+ const suffix = options.suffix.charAt(0).toUpperCase() + options.suffix.slice(1);
121
+ name = name + suffix;
122
122
  }
123
123
  return name;
124
124
  }
@@ -547,9 +547,9 @@ function detectConflictingProperties(schemas, context) {
547
547
  }
548
548
  return conflicts;
549
549
  }
550
- function generateAllOf(schemas, isNullable2, context, currentSchema) {
550
+ function generateAllOf(schemas, isNullable2, context, currentSchema, explicitNullableFalse = false) {
551
551
  if (schemas.length === 1) {
552
- const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false);
552
+ const singleSchema = context.generatePropertySchema(schemas[0], currentSchema, false, explicitNullableFalse);
553
553
  return wrapNullable(singleSchema, isNullable2);
554
554
  }
555
555
  const conflicts = detectConflictingProperties(schemas, context);
@@ -1364,12 +1364,21 @@ var _PropertyGenerator = class _PropertyGenerator {
1364
1364
  }
1365
1365
  /**
1366
1366
  * Generate Zod schema for a property
1367
+ * @param schema - The OpenAPI schema to generate
1368
+ * @param currentSchema - The name of the current schema being processed (for circular ref detection)
1369
+ * @param isTopLevel - Whether this is a top-level schema definition
1370
+ * @param suppressDefaultNullable - When true, don't apply defaultNullable (used when outer schema has explicit nullable: false)
1367
1371
  */
1368
- generatePropertySchema(schema, currentSchema, isTopLevel = false) {
1372
+ generatePropertySchema(schema, currentSchema, isTopLevel = false, suppressDefaultNullable = false) {
1369
1373
  var _a, _b, _c, _d, _e;
1370
1374
  const isCacheable = !schema.$ref && !schema.allOf && !schema.oneOf && !schema.anyOf && !currentSchema;
1371
1375
  if (isCacheable) {
1372
- const cacheKey = JSON.stringify({ schema, type: this.context.schemaType, mode: this.context.mode });
1376
+ const cacheKey = JSON.stringify({
1377
+ schema,
1378
+ type: this.context.schemaType,
1379
+ mode: this.context.mode,
1380
+ suppressDefaultNullable
1381
+ });
1373
1382
  const cached = this.schemaCache.get(cacheKey);
1374
1383
  if (cached) {
1375
1384
  return cached;
@@ -1378,10 +1387,9 @@ var _PropertyGenerator = class _PropertyGenerator {
1378
1387
  if ((this.context.schemaType === "request" || this.context.schemaType === "response") && schema.properties) {
1379
1388
  schema = this.filterNestedProperties(schema);
1380
1389
  }
1381
- const isSchemaRef = !!schema.$ref;
1382
1390
  const isEnum = !!schema.enum;
1383
1391
  const isConst = schema.const !== void 0;
1384
- const shouldApplyDefaultNullable = !isTopLevel && !isSchemaRef && !isEnum && !isConst;
1392
+ const shouldApplyDefaultNullable = !isTopLevel && !isEnum && !isConst && !suppressDefaultNullable;
1385
1393
  const effectiveDefaultNullable = shouldApplyDefaultNullable ? this.context.defaultNullable : false;
1386
1394
  const nullable = isNullable(schema, effectiveDefaultNullable);
1387
1395
  if (hasMultipleTypes(schema)) {
@@ -1432,6 +1440,7 @@ var _PropertyGenerator = class _PropertyGenerator {
1432
1440
  return wrapNullable(zodUnion, nullable);
1433
1441
  }
1434
1442
  if (schema.allOf) {
1443
+ const explicitNullableFalse = schema.nullable === false;
1435
1444
  let composition = generateAllOf(
1436
1445
  schema.allOf,
1437
1446
  nullable,
@@ -1440,7 +1449,8 @@ var _PropertyGenerator = class _PropertyGenerator {
1440
1449
  generateInlineObjectShape: this.generateInlineObjectShape.bind(this),
1441
1450
  resolveSchemaRef: this.resolveSchemaRef.bind(this)
1442
1451
  },
1443
- currentSchema
1452
+ currentSchema,
1453
+ explicitNullableFalse
1444
1454
  );
1445
1455
  if (schema.unevaluatedProperties !== void 0) {
1446
1456
  composition = this.applyUnevaluatedProperties(composition, schema);
@@ -1974,12 +1984,6 @@ var OpenApiGenerator = class {
1974
1984
  * Generate the complete output file
1975
1985
  */
1976
1986
  generate() {
1977
- if (!this.options.output) {
1978
- throw new ConfigurationError(
1979
- "Output path is required when calling generate(). Either provide an 'output' option or use generateString() to get the result as a string.",
1980
- { hasOutput: false }
1981
- );
1982
- }
1983
1987
  const output = this.generateString();
1984
1988
  const normalizedOutput = (0, import_node_path.normalize)(this.options.output);
1985
1989
  this.ensureDirectoryExists(normalizedOutput);