@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/README.md +2 -2
- package/dist/cli.js +129 -23
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +134 -28
- package/dist/cli.mjs.map +1 -1
- package/dist/index.d.mts +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +36 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +35 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -64,7 +64,7 @@ var ConfigurationError = class extends GeneratorError {
|
|
|
64
64
|
}
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
// src/generator.ts
|
|
67
|
+
// src/openapi-generator.ts
|
|
68
68
|
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
69
69
|
import { dirname, normalize } from "path";
|
|
70
70
|
import { parse } from "yaml";
|
|
@@ -1252,8 +1252,8 @@ _PropertyGenerator.INCLUSION_RULES = {
|
|
|
1252
1252
|
};
|
|
1253
1253
|
var PropertyGenerator = _PropertyGenerator;
|
|
1254
1254
|
|
|
1255
|
-
// src/generator.ts
|
|
1256
|
-
var
|
|
1255
|
+
// src/openapi-generator.ts
|
|
1256
|
+
var OpenApiGenerator = class {
|
|
1257
1257
|
constructor(options) {
|
|
1258
1258
|
this.schemas = /* @__PURE__ */ new Map();
|
|
1259
1259
|
this.types = /* @__PURE__ */ new Map();
|
|
@@ -1293,19 +1293,41 @@ var ZodSchemaGenerator = class {
|
|
|
1293
1293
|
}
|
|
1294
1294
|
}
|
|
1295
1295
|
try {
|
|
1296
|
-
const
|
|
1297
|
-
|
|
1296
|
+
const content = readFileSync(this.options.input, "utf-8");
|
|
1297
|
+
try {
|
|
1298
|
+
this.spec = parse(content);
|
|
1299
|
+
} catch (yamlError) {
|
|
1300
|
+
try {
|
|
1301
|
+
this.spec = JSON.parse(content);
|
|
1302
|
+
} catch {
|
|
1303
|
+
if (yamlError instanceof Error) {
|
|
1304
|
+
const errorMessage = [
|
|
1305
|
+
`Failed to parse OpenAPI specification from: ${this.options.input}`,
|
|
1306
|
+
"",
|
|
1307
|
+
`Error: ${yamlError.message}`,
|
|
1308
|
+
"",
|
|
1309
|
+
"Please ensure:",
|
|
1310
|
+
" - The file exists and is readable",
|
|
1311
|
+
" - The file contains valid YAML or JSON syntax",
|
|
1312
|
+
" - The file is a valid OpenAPI 3.x specification"
|
|
1313
|
+
].join("\n");
|
|
1314
|
+
throw new SpecValidationError(errorMessage, {
|
|
1315
|
+
filePath: this.options.input,
|
|
1316
|
+
originalError: yamlError.message
|
|
1317
|
+
});
|
|
1318
|
+
}
|
|
1319
|
+
throw yamlError;
|
|
1320
|
+
}
|
|
1321
|
+
}
|
|
1298
1322
|
} catch (error) {
|
|
1323
|
+
if (error instanceof SpecValidationError) {
|
|
1324
|
+
throw error;
|
|
1325
|
+
}
|
|
1299
1326
|
if (error instanceof Error) {
|
|
1300
1327
|
const errorMessage = [
|
|
1301
|
-
`Failed to
|
|
1302
|
-
"",
|
|
1303
|
-
`Error: ${error.message}`,
|
|
1328
|
+
`Failed to read OpenAPI specification from: ${this.options.input}`,
|
|
1304
1329
|
"",
|
|
1305
|
-
|
|
1306
|
-
" - The file exists and is readable",
|
|
1307
|
-
" - The file contains valid YAML syntax",
|
|
1308
|
-
" - The file is a valid OpenAPI 3.x specification"
|
|
1330
|
+
`Error: ${error.message}`
|
|
1309
1331
|
].join("\n");
|
|
1310
1332
|
throw new SpecValidationError(errorMessage, { filePath: this.options.input, originalError: error.message });
|
|
1311
1333
|
}
|
|
@@ -2173,9 +2195,9 @@ export {
|
|
|
2173
2195
|
ConfigValidationError,
|
|
2174
2196
|
FileOperationError,
|
|
2175
2197
|
GeneratorError,
|
|
2198
|
+
OpenApiGenerator,
|
|
2176
2199
|
SchemaGenerationError,
|
|
2177
2200
|
SpecValidationError,
|
|
2178
|
-
ZodSchemaGenerator,
|
|
2179
2201
|
defineConfig
|
|
2180
2202
|
};
|
|
2181
2203
|
//# sourceMappingURL=index.mjs.map
|