@cerios/openapi-to-zod 0.2.0 → 0.3.0

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
@@ -63,11 +63,9 @@ type TypeMode = "inferred" | "native";
63
63
  */
64
64
  type NativeEnumType = "union" | "enum";
65
65
  /**
66
- * Options that can be overridden per request/response context
67
- * These options override root-level options when specified.
68
- * Resolution order: root options → request/response overrides (nested wins silently)
66
+ * Common options shared by both request and response contexts
69
67
  */
70
- interface RequestResponseOptions {
68
+ interface CommonSchemaOptions {
71
69
  /**
72
70
  * Object validation mode
73
71
  * - 'strict': Uses z.strictObject() - no additional properties allowed
@@ -90,10 +88,16 @@ interface RequestResponseOptions {
90
88
  * Whether to include descriptions as JSDoc comments
91
89
  */
92
90
  includeDescriptions?: boolean;
91
+ }
92
+ /**
93
+ * Request-specific options that can override root-level options
94
+ * Requests support native TypeScript type generation as an alternative to Zod schemas
95
+ */
96
+ interface RequestOptions extends CommonSchemaOptions {
93
97
  /**
94
- * Type generation mode (only for requests)
98
+ * Type generation mode
95
99
  * - 'inferred': Generate Zod schemas with z.infer types (default)
96
- * - 'native': Generate native TypeScript types
100
+ * - 'native': Generate native TypeScript types without Zod validation
97
101
  */
98
102
  typeMode?: TypeMode;
99
103
  /**
@@ -103,6 +107,12 @@ interface RequestResponseOptions {
103
107
  */
104
108
  nativeEnumType?: NativeEnumType;
105
109
  }
110
+ /**
111
+ * Response-specific options that can override root-level options
112
+ * Responses always use Zod schemas for runtime validation
113
+ */
114
+ interface ResponseOptions extends CommonSchemaOptions {
115
+ }
106
116
  interface GeneratorOptions {
107
117
  /**
108
118
  * Object validation mode
@@ -168,13 +178,15 @@ interface GeneratorOptions {
168
178
  /**
169
179
  * Request-specific options that override root-level options
170
180
  * Applied when schemas are used in request contexts
181
+ * Supports native TypeScript type generation
171
182
  */
172
- request?: Partial<RequestResponseOptions>;
183
+ request?: RequestOptions;
173
184
  /**
174
185
  * Response-specific options that override root-level options
175
186
  * Applied when schemas are used in response contexts
187
+ * Always generates Zod schemas for runtime validation
176
188
  */
177
- response?: Partial<RequestResponseOptions>;
189
+ response?: ResponseOptions;
178
190
  }
179
191
  interface OpenAPISchema {
180
192
  type?: string | string[];
package/dist/index.d.ts CHANGED
@@ -63,11 +63,9 @@ type TypeMode = "inferred" | "native";
63
63
  */
64
64
  type NativeEnumType = "union" | "enum";
65
65
  /**
66
- * Options that can be overridden per request/response context
67
- * These options override root-level options when specified.
68
- * Resolution order: root options → request/response overrides (nested wins silently)
66
+ * Common options shared by both request and response contexts
69
67
  */
70
- interface RequestResponseOptions {
68
+ interface CommonSchemaOptions {
71
69
  /**
72
70
  * Object validation mode
73
71
  * - 'strict': Uses z.strictObject() - no additional properties allowed
@@ -90,10 +88,16 @@ interface RequestResponseOptions {
90
88
  * Whether to include descriptions as JSDoc comments
91
89
  */
92
90
  includeDescriptions?: boolean;
91
+ }
92
+ /**
93
+ * Request-specific options that can override root-level options
94
+ * Requests support native TypeScript type generation as an alternative to Zod schemas
95
+ */
96
+ interface RequestOptions extends CommonSchemaOptions {
93
97
  /**
94
- * Type generation mode (only for requests)
98
+ * Type generation mode
95
99
  * - 'inferred': Generate Zod schemas with z.infer types (default)
96
- * - 'native': Generate native TypeScript types
100
+ * - 'native': Generate native TypeScript types without Zod validation
97
101
  */
98
102
  typeMode?: TypeMode;
99
103
  /**
@@ -103,6 +107,12 @@ interface RequestResponseOptions {
103
107
  */
104
108
  nativeEnumType?: NativeEnumType;
105
109
  }
110
+ /**
111
+ * Response-specific options that can override root-level options
112
+ * Responses always use Zod schemas for runtime validation
113
+ */
114
+ interface ResponseOptions extends CommonSchemaOptions {
115
+ }
106
116
  interface GeneratorOptions {
107
117
  /**
108
118
  * Object validation mode
@@ -168,13 +178,15 @@ interface GeneratorOptions {
168
178
  /**
169
179
  * Request-specific options that override root-level options
170
180
  * Applied when schemas are used in request contexts
181
+ * Supports native TypeScript type generation
171
182
  */
172
- request?: Partial<RequestResponseOptions>;
183
+ request?: RequestOptions;
173
184
  /**
174
185
  * Response-specific options that override root-level options
175
186
  * Applied when schemas are used in response contexts
187
+ * Always generates Zod schemas for runtime validation
176
188
  */
177
- response?: Partial<RequestResponseOptions>;
189
+ response?: ResponseOptions;
178
190
  }
179
191
  interface OpenAPISchema {
180
192
  type?: string | string[];
package/dist/index.js CHANGED
@@ -1433,7 +1433,8 @@ var ZodSchemaGenerator = class {
1433
1433
  * Ensure directory exists for a file path
1434
1434
  */
1435
1435
  ensureDirectoryExists(filePath) {
1436
- const dir = (0, import_node_path.dirname)(filePath);
1436
+ const normalizedPath = (0, import_node_path.normalize)(filePath);
1437
+ const dir = (0, import_node_path.dirname)(normalizedPath);
1437
1438
  if (!(0, import_node_fs.existsSync)(dir)) {
1438
1439
  (0, import_node_fs.mkdirSync)(dir, { recursive: true });
1439
1440
  }
@@ -1449,8 +1450,9 @@ var ZodSchemaGenerator = class {
1449
1450
  );
1450
1451
  }
1451
1452
  const output = this.generateString();
1452
- this.ensureDirectoryExists(this.options.output);
1453
- (0, import_node_fs.writeFileSync)(this.options.output, output);
1453
+ const normalizedOutput = (0, import_node_path.normalize)(this.options.output);
1454
+ this.ensureDirectoryExists(normalizedOutput);
1455
+ (0, import_node_fs.writeFileSync)(normalizedOutput, output);
1454
1456
  }
1455
1457
  /**
1456
1458
  * Resolve options for a specific context (request or response)
@@ -1458,17 +1460,18 @@ var ZodSchemaGenerator = class {
1458
1460
  * Response schemas always use 'inferred' mode (Zod schemas)
1459
1461
  */
1460
1462
  resolveOptionsForContext(context) {
1461
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
1463
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n;
1462
1464
  const contextOptions = context === "request" ? this.options.request : this.options.response;
1465
+ const nativeEnumType = context === "request" ? (_c = (_b = (_a = this.options.request) == null ? void 0 : _a.nativeEnumType) != null ? _b : this.options.nativeEnumType) != null ? _c : "union" : (_d = this.options.nativeEnumType) != null ? _d : "union";
1463
1466
  return {
1464
- mode: (_b = (_a = contextOptions == null ? void 0 : contextOptions.mode) != null ? _a : this.options.mode) != null ? _b : "normal",
1465
- enumType: (_d = (_c = contextOptions == null ? void 0 : contextOptions.enumType) != null ? _c : this.options.enumType) != null ? _d : "zod",
1466
- useDescribe: (_f = (_e = contextOptions == null ? void 0 : contextOptions.useDescribe) != null ? _e : this.options.useDescribe) != null ? _f : false,
1467
- includeDescriptions: (_h = (_g = contextOptions == null ? void 0 : contextOptions.includeDescriptions) != null ? _g : this.options.includeDescriptions) != null ? _h : true,
1467
+ mode: (_f = (_e = contextOptions == null ? void 0 : contextOptions.mode) != null ? _e : this.options.mode) != null ? _f : "normal",
1468
+ enumType: (_h = (_g = contextOptions == null ? void 0 : contextOptions.enumType) != null ? _g : this.options.enumType) != null ? _h : "zod",
1469
+ useDescribe: (_j = (_i = contextOptions == null ? void 0 : contextOptions.useDescribe) != null ? _i : this.options.useDescribe) != null ? _j : false,
1470
+ includeDescriptions: (_l = (_k = contextOptions == null ? void 0 : contextOptions.includeDescriptions) != null ? _k : this.options.includeDescriptions) != null ? _l : true,
1468
1471
  // Response schemas always use 'inferred' mode (Zod schemas are required)
1469
1472
  // Request schemas can optionally use 'native' mode
1470
- typeMode: context === "response" ? "inferred" : (_i = contextOptions == null ? void 0 : contextOptions.typeMode) != null ? _i : "inferred",
1471
- nativeEnumType: (_k = (_j = contextOptions == null ? void 0 : contextOptions.nativeEnumType) != null ? _j : this.options.nativeEnumType) != null ? _k : "union"
1473
+ typeMode: context === "response" ? "inferred" : (_n = (_m = this.options.request) == null ? void 0 : _m.typeMode) != null ? _n : "inferred",
1474
+ nativeEnumType
1472
1475
  };
1473
1476
  }
1474
1477
  /**