@cerios/openapi-to-zod 0.3.0 → 0.4.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
@@ -113,7 +113,7 @@ interface RequestOptions extends CommonSchemaOptions {
113
113
  */
114
114
  interface ResponseOptions extends CommonSchemaOptions {
115
115
  }
116
- interface GeneratorOptions {
116
+ interface OpenApiGeneratorOptions {
117
117
  /**
118
118
  * Object validation mode
119
119
  * - 'strict': Uses z.strictObject() - no additional properties allowed
@@ -263,12 +263,12 @@ interface ConfigFile {
263
263
  * Global default options applied to all specs
264
264
  * Can be overridden by individual spec configurations
265
265
  */
266
- defaults?: Partial<Omit<GeneratorOptions, "input" | "output">>;
266
+ defaults?: Partial<Omit<OpenApiGeneratorOptions, "input" | "output">>;
267
267
  /**
268
268
  * Array of OpenAPI specifications to process
269
269
  * Each spec must have input and output paths
270
270
  */
271
- specs: GeneratorOptions[];
271
+ specs: OpenApiGeneratorOptions[];
272
272
  /**
273
273
  * Execution mode for batch processing
274
274
  * @default "parallel"
@@ -297,7 +297,7 @@ interface ConfigFile {
297
297
  */
298
298
  declare function defineConfig(config: ConfigFile): ConfigFile;
299
299
 
300
- declare class ZodSchemaGenerator {
300
+ declare class OpenApiGenerator {
301
301
  private schemas;
302
302
  private types;
303
303
  private enums;
@@ -311,7 +311,7 @@ declare class ZodSchemaGenerator {
311
311
  private requestOptions;
312
312
  private responseOptions;
313
313
  private needsZodImport;
314
- constructor(options: GeneratorOptions);
314
+ constructor(options: OpenApiGeneratorOptions);
315
315
  /**
316
316
  * Generate schemas as a string (without writing to file)
317
317
  * @returns The generated TypeScript code as a string
@@ -412,4 +412,4 @@ declare class ZodSchemaGenerator {
412
412
  private generateStats;
413
413
  }
414
414
 
415
- export { CircularReferenceError, CliOptionsError, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, GeneratorError, type GeneratorOptions, type OpenAPISpec, SchemaGenerationError, SpecValidationError, ZodSchemaGenerator, defineConfig };
415
+ export { CircularReferenceError, CliOptionsError, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, GeneratorError, type OpenAPISpec, OpenApiGenerator, type OpenApiGeneratorOptions, SchemaGenerationError, SpecValidationError, defineConfig };
package/dist/index.d.ts CHANGED
@@ -113,7 +113,7 @@ interface RequestOptions extends CommonSchemaOptions {
113
113
  */
114
114
  interface ResponseOptions extends CommonSchemaOptions {
115
115
  }
116
- interface GeneratorOptions {
116
+ interface OpenApiGeneratorOptions {
117
117
  /**
118
118
  * Object validation mode
119
119
  * - 'strict': Uses z.strictObject() - no additional properties allowed
@@ -263,12 +263,12 @@ interface ConfigFile {
263
263
  * Global default options applied to all specs
264
264
  * Can be overridden by individual spec configurations
265
265
  */
266
- defaults?: Partial<Omit<GeneratorOptions, "input" | "output">>;
266
+ defaults?: Partial<Omit<OpenApiGeneratorOptions, "input" | "output">>;
267
267
  /**
268
268
  * Array of OpenAPI specifications to process
269
269
  * Each spec must have input and output paths
270
270
  */
271
- specs: GeneratorOptions[];
271
+ specs: OpenApiGeneratorOptions[];
272
272
  /**
273
273
  * Execution mode for batch processing
274
274
  * @default "parallel"
@@ -297,7 +297,7 @@ interface ConfigFile {
297
297
  */
298
298
  declare function defineConfig(config: ConfigFile): ConfigFile;
299
299
 
300
- declare class ZodSchemaGenerator {
300
+ declare class OpenApiGenerator {
301
301
  private schemas;
302
302
  private types;
303
303
  private enums;
@@ -311,7 +311,7 @@ declare class ZodSchemaGenerator {
311
311
  private requestOptions;
312
312
  private responseOptions;
313
313
  private needsZodImport;
314
- constructor(options: GeneratorOptions);
314
+ constructor(options: OpenApiGeneratorOptions);
315
315
  /**
316
316
  * Generate schemas as a string (without writing to file)
317
317
  * @returns The generated TypeScript code as a string
@@ -412,4 +412,4 @@ declare class ZodSchemaGenerator {
412
412
  private generateStats;
413
413
  }
414
414
 
415
- export { CircularReferenceError, CliOptionsError, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, GeneratorError, type GeneratorOptions, type OpenAPISpec, SchemaGenerationError, SpecValidationError, ZodSchemaGenerator, defineConfig };
415
+ export { CircularReferenceError, CliOptionsError, type ConfigFile, ConfigValidationError, type ExecutionMode, FileOperationError, GeneratorError, type OpenAPISpec, OpenApiGenerator, type OpenApiGeneratorOptions, SchemaGenerationError, SpecValidationError, defineConfig };
package/dist/index.js CHANGED
@@ -25,9 +25,9 @@ __export(src_exports, {
25
25
  ConfigValidationError: () => ConfigValidationError,
26
26
  FileOperationError: () => FileOperationError,
27
27
  GeneratorError: () => GeneratorError,
28
+ OpenApiGenerator: () => OpenApiGenerator,
28
29
  SchemaGenerationError: () => SchemaGenerationError,
29
30
  SpecValidationError: () => SpecValidationError,
30
- ZodSchemaGenerator: () => ZodSchemaGenerator,
31
31
  defineConfig: () => defineConfig
32
32
  });
33
33
  module.exports = __toCommonJS(src_exports);
@@ -91,7 +91,7 @@ var ConfigurationError = class extends GeneratorError {
91
91
  }
92
92
  };
93
93
 
94
- // src/generator.ts
94
+ // src/openapi-generator.ts
95
95
  var import_node_fs = require("fs");
96
96
  var import_node_path = require("path");
97
97
  var import_yaml = require("yaml");
@@ -1279,8 +1279,8 @@ _PropertyGenerator.INCLUSION_RULES = {
1279
1279
  };
1280
1280
  var PropertyGenerator = _PropertyGenerator;
1281
1281
 
1282
- // src/generator.ts
1283
- var ZodSchemaGenerator = class {
1282
+ // src/openapi-generator.ts
1283
+ var OpenApiGenerator = class {
1284
1284
  constructor(options) {
1285
1285
  this.schemas = /* @__PURE__ */ new Map();
1286
1286
  this.types = /* @__PURE__ */ new Map();
@@ -1320,19 +1320,41 @@ var ZodSchemaGenerator = class {
1320
1320
  }
1321
1321
  }
1322
1322
  try {
1323
- const yamlContent = (0, import_node_fs.readFileSync)(this.options.input, "utf-8");
1324
- this.spec = (0, import_yaml.parse)(yamlContent);
1323
+ const content = (0, import_node_fs.readFileSync)(this.options.input, "utf-8");
1324
+ try {
1325
+ this.spec = (0, import_yaml.parse)(content);
1326
+ } catch (yamlError) {
1327
+ try {
1328
+ this.spec = JSON.parse(content);
1329
+ } catch {
1330
+ if (yamlError instanceof Error) {
1331
+ const errorMessage = [
1332
+ `Failed to parse OpenAPI specification from: ${this.options.input}`,
1333
+ "",
1334
+ `Error: ${yamlError.message}`,
1335
+ "",
1336
+ "Please ensure:",
1337
+ " - The file exists and is readable",
1338
+ " - The file contains valid YAML or JSON syntax",
1339
+ " - The file is a valid OpenAPI 3.x specification"
1340
+ ].join("\n");
1341
+ throw new SpecValidationError(errorMessage, {
1342
+ filePath: this.options.input,
1343
+ originalError: yamlError.message
1344
+ });
1345
+ }
1346
+ throw yamlError;
1347
+ }
1348
+ }
1325
1349
  } catch (error) {
1350
+ if (error instanceof SpecValidationError) {
1351
+ throw error;
1352
+ }
1326
1353
  if (error instanceof Error) {
1327
1354
  const errorMessage = [
1328
- `Failed to parse OpenAPI specification from: ${this.options.input}`,
1329
- "",
1330
- `Error: ${error.message}`,
1355
+ `Failed to read OpenAPI specification from: ${this.options.input}`,
1331
1356
  "",
1332
- "Please ensure:",
1333
- " - The file exists and is readable",
1334
- " - The file contains valid YAML syntax",
1335
- " - The file is a valid OpenAPI 3.x specification"
1357
+ `Error: ${error.message}`
1336
1358
  ].join("\n");
1337
1359
  throw new SpecValidationError(errorMessage, { filePath: this.options.input, originalError: error.message });
1338
1360
  }
@@ -2201,9 +2223,9 @@ function defineConfig(config) {
2201
2223
  ConfigValidationError,
2202
2224
  FileOperationError,
2203
2225
  GeneratorError,
2226
+ OpenApiGenerator,
2204
2227
  SchemaGenerationError,
2205
2228
  SpecValidationError,
2206
- ZodSchemaGenerator,
2207
2229
  defineConfig
2208
2230
  });
2209
2231
  //# sourceMappingURL=index.js.map