@omer-x/next-openapi-json-generator 2.1.0-rc.1 → 2.1.0-rc.3

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 CHANGED
@@ -303,30 +303,40 @@ 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());
321
+ case "default": {
322
+ const defaultValue = schema._zod.def.defaultValue;
323
+ return alterSchema(schema, fixSchema(schema.unwrap()).default(defaultValue));
324
+ }
315
325
  case "array":
316
- return fixSchema(schema.unwrap()).array();
326
+ return alterSchema(schema, fixSchema(schema.unwrap()).array());
317
327
  default:
318
328
  throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
319
329
  }
320
330
  }
321
331
  if (schema._zod.def.type === "date") {
322
- return import_zod2.z.iso.datetime();
332
+ return alterSchema(schema, import_zod2.z.iso.datetime());
323
333
  }
324
334
  if (schema._zod.def.type === "object") {
325
335
  const { shape } = schema;
326
336
  const entries = Object.entries(shape);
327
337
  const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
328
338
  const newShape = Object.fromEntries(alteredEntries);
329
- return import_zod2.z.object(newShape);
339
+ return alterSchema(schema, import_zod2.z.object(newShape));
330
340
  }
331
341
  return schema;
332
342
  }
package/dist/index.js CHANGED
@@ -274,30 +274,40 @@ 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());
292
+ case "default": {
293
+ const defaultValue = schema._zod.def.defaultValue;
294
+ return alterSchema(schema, fixSchema(schema.unwrap()).default(defaultValue));
295
+ }
286
296
  case "array":
287
- return fixSchema(schema.unwrap()).array();
297
+ return alterSchema(schema, fixSchema(schema.unwrap()).array());
288
298
  default:
289
299
  throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
290
300
  }
291
301
  }
292
302
  if (schema._zod.def.type === "date") {
293
- return z2.iso.datetime();
303
+ return alterSchema(schema, z2.iso.datetime());
294
304
  }
295
305
  if (schema._zod.def.type === "object") {
296
306
  const { shape } = schema;
297
307
  const entries = Object.entries(shape);
298
308
  const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
299
309
  const newShape = Object.fromEntries(alteredEntries);
300
- return z2.object(newShape);
310
+ return alterSchema(schema, z2.object(newShape));
301
311
  }
302
312
  return schema;
303
313
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/next-openapi-json-generator",
3
- "version": "2.1.0-rc.1",
3
+ "version": "2.1.0-rc.3",
4
4
  "description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
5
5
  "keywords": [
6
6
  "next.js",