@omer-x/next-openapi-json-generator 2.1.0-rc.1 → 2.1.0-rc.2
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.cjs +12 -6
- package/dist/index.js +12 -6
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -303,30 +303,36 @@ function bundlePaths(source) {
|
|
|
303
303
|
|
|
304
304
|
// src/core/zod-to-openapi.ts
|
|
305
305
|
var import_zod2 = require("zod");
|
|
306
|
+
function alterSchema(schema, newShape) {
|
|
307
|
+
if (schema.description) {
|
|
308
|
+
newShape = newShape.describe(schema.description);
|
|
309
|
+
}
|
|
310
|
+
return newShape;
|
|
311
|
+
}
|
|
306
312
|
function fixSchema(schema) {
|
|
307
313
|
if ("unwrap" in schema && typeof schema.unwrap === "function") {
|
|
308
314
|
switch (schema._zod.def.type) {
|
|
309
315
|
case "nullable":
|
|
310
|
-
return fixSchema(schema.unwrap()).nullable();
|
|
316
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).nullable());
|
|
311
317
|
case "optional":
|
|
312
|
-
return fixSchema(schema.unwrap()).optional();
|
|
318
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).optional());
|
|
313
319
|
case "readonly":
|
|
314
|
-
return fixSchema(schema.unwrap()).readonly();
|
|
320
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).readonly());
|
|
315
321
|
case "array":
|
|
316
|
-
return fixSchema(schema.unwrap()).array();
|
|
322
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).array());
|
|
317
323
|
default:
|
|
318
324
|
throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
|
|
319
325
|
}
|
|
320
326
|
}
|
|
321
327
|
if (schema._zod.def.type === "date") {
|
|
322
|
-
return import_zod2.z.iso.datetime();
|
|
328
|
+
return alterSchema(schema, import_zod2.z.iso.datetime());
|
|
323
329
|
}
|
|
324
330
|
if (schema._zod.def.type === "object") {
|
|
325
331
|
const { shape } = schema;
|
|
326
332
|
const entries = Object.entries(shape);
|
|
327
333
|
const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
|
|
328
334
|
const newShape = Object.fromEntries(alteredEntries);
|
|
329
|
-
return import_zod2.z.object(newShape);
|
|
335
|
+
return alterSchema(schema, import_zod2.z.object(newShape));
|
|
330
336
|
}
|
|
331
337
|
return schema;
|
|
332
338
|
}
|
package/dist/index.js
CHANGED
|
@@ -274,30 +274,36 @@ function bundlePaths(source) {
|
|
|
274
274
|
|
|
275
275
|
// src/core/zod-to-openapi.ts
|
|
276
276
|
import { z as z2 } from "zod";
|
|
277
|
+
function alterSchema(schema, newShape) {
|
|
278
|
+
if (schema.description) {
|
|
279
|
+
newShape = newShape.describe(schema.description);
|
|
280
|
+
}
|
|
281
|
+
return newShape;
|
|
282
|
+
}
|
|
277
283
|
function fixSchema(schema) {
|
|
278
284
|
if ("unwrap" in schema && typeof schema.unwrap === "function") {
|
|
279
285
|
switch (schema._zod.def.type) {
|
|
280
286
|
case "nullable":
|
|
281
|
-
return fixSchema(schema.unwrap()).nullable();
|
|
287
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).nullable());
|
|
282
288
|
case "optional":
|
|
283
|
-
return fixSchema(schema.unwrap()).optional();
|
|
289
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).optional());
|
|
284
290
|
case "readonly":
|
|
285
|
-
return fixSchema(schema.unwrap()).readonly();
|
|
291
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).readonly());
|
|
286
292
|
case "array":
|
|
287
|
-
return fixSchema(schema.unwrap()).array();
|
|
293
|
+
return alterSchema(schema, fixSchema(schema.unwrap()).array());
|
|
288
294
|
default:
|
|
289
295
|
throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
|
|
290
296
|
}
|
|
291
297
|
}
|
|
292
298
|
if (schema._zod.def.type === "date") {
|
|
293
|
-
return z2.iso.datetime();
|
|
299
|
+
return alterSchema(schema, z2.iso.datetime());
|
|
294
300
|
}
|
|
295
301
|
if (schema._zod.def.type === "object") {
|
|
296
302
|
const { shape } = schema;
|
|
297
303
|
const entries = Object.entries(shape);
|
|
298
304
|
const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
|
|
299
305
|
const newShape = Object.fromEntries(alteredEntries);
|
|
300
|
-
return z2.object(newShape);
|
|
306
|
+
return alterSchema(schema, z2.object(newShape));
|
|
301
307
|
}
|
|
302
308
|
return schema;
|
|
303
309
|
}
|