@omer-x/next-openapi-json-generator 2.0.1 → 2.0.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
@@ -226,17 +226,17 @@ async function safeEval(code, routePath) {
226
226
  }
227
227
  }
228
228
  async function getModuleTranspiler() {
229
- if (typeof require === "undefined") {
230
- const { transpileModule } = await import(
229
+ if (typeof require !== "undefined" && typeof exports !== "undefined") {
230
+ return require(
231
231
  /* webpackIgnore: true */
232
232
  "typescript"
233
- );
234
- return transpileModule;
233
+ ).transpileModule;
235
234
  }
236
- return require(
235
+ const { transpileModule } = await import(
237
236
  /* webpackIgnore: true */
238
237
  "typescript"
239
- ).transpileModule;
238
+ );
239
+ return transpileModule;
240
240
  }
241
241
  async function getRouteExports(routePath2, routeDefinerName, schemas) {
242
242
  const rawCode = await import_promises3.default.readFile(routePath2, "utf-8");
@@ -305,8 +305,35 @@ function deepEqual(a, b) {
305
305
 
306
306
  // src/core/zod-to-openapi.ts
307
307
  var import_zod2 = require("zod");
308
+ function fixSchema(schema) {
309
+ if ("unwrap" in schema && typeof schema.unwrap === "function") {
310
+ switch (schema._zod.def.type) {
311
+ case "nullable":
312
+ return fixSchema(schema.unwrap()).nullable();
313
+ case "optional":
314
+ return fixSchema(schema.unwrap()).optional();
315
+ case "readonly":
316
+ return fixSchema(schema.unwrap()).readonly();
317
+ case "array":
318
+ return fixSchema(schema.unwrap()).array();
319
+ default:
320
+ throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
321
+ }
322
+ }
323
+ if (schema._zod.def.type === "date") {
324
+ return import_zod2.z.iso.datetime();
325
+ }
326
+ if (schema._zod.def.type === "object") {
327
+ const { shape } = schema;
328
+ const entries = Object.entries(shape);
329
+ const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
330
+ const newShape = Object.fromEntries(alteredEntries);
331
+ return import_zod2.z.object(newShape);
332
+ }
333
+ return schema;
334
+ }
308
335
  function convertToOpenAPI(schema, isArray) {
309
- return import_zod2.z.toJSONSchema(isArray ? schema.array() : schema);
336
+ return import_zod2.z.toJSONSchema(fixSchema(isArray ? schema.array() : schema));
310
337
  }
311
338
 
312
339
  // src/core/mask.ts
package/dist/index.js CHANGED
@@ -197,17 +197,17 @@ async function safeEval(code, routePath) {
197
197
  }
198
198
  }
199
199
  async function getModuleTranspiler() {
200
- if (typeof __require === "undefined") {
201
- const { transpileModule } = await import(
200
+ if (typeof __require !== "undefined" && typeof exports !== "undefined") {
201
+ return __require(
202
202
  /* webpackIgnore: true */
203
203
  "typescript"
204
- );
205
- return transpileModule;
204
+ ).transpileModule;
206
205
  }
207
- return __require(
206
+ const { transpileModule } = await import(
208
207
  /* webpackIgnore: true */
209
208
  "typescript"
210
- ).transpileModule;
209
+ );
210
+ return transpileModule;
211
211
  }
212
212
  async function getRouteExports(routePath2, routeDefinerName, schemas) {
213
213
  const rawCode = await fs3.readFile(routePath2, "utf-8");
@@ -276,8 +276,35 @@ function deepEqual(a, b) {
276
276
 
277
277
  // src/core/zod-to-openapi.ts
278
278
  import { z as z2 } from "zod";
279
+ function fixSchema(schema) {
280
+ if ("unwrap" in schema && typeof schema.unwrap === "function") {
281
+ switch (schema._zod.def.type) {
282
+ case "nullable":
283
+ return fixSchema(schema.unwrap()).nullable();
284
+ case "optional":
285
+ return fixSchema(schema.unwrap()).optional();
286
+ case "readonly":
287
+ return fixSchema(schema.unwrap()).readonly();
288
+ case "array":
289
+ return fixSchema(schema.unwrap()).array();
290
+ default:
291
+ throw new Error(`${schema._zod.def.type} type is not covered in fixSchema (@omer-x/next-openapi-json-generator")`);
292
+ }
293
+ }
294
+ if (schema._zod.def.type === "date") {
295
+ return z2.iso.datetime();
296
+ }
297
+ if (schema._zod.def.type === "object") {
298
+ const { shape } = schema;
299
+ const entries = Object.entries(shape);
300
+ const alteredEntries = entries.map(([propName, prop]) => [propName, fixSchema(prop)]);
301
+ const newShape = Object.fromEntries(alteredEntries);
302
+ return z2.object(newShape);
303
+ }
304
+ return schema;
305
+ }
279
306
  function convertToOpenAPI(schema, isArray) {
280
- return z2.toJSONSchema(isArray ? schema.array() : schema);
307
+ return z2.toJSONSchema(fixSchema(isArray ? schema.array() : schema));
281
308
  }
282
309
 
283
310
  // src/core/mask.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/next-openapi-json-generator",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
5
5
  "keywords": [
6
6
  "next.js",
@@ -53,15 +53,15 @@
53
53
  },
54
54
  "dependencies": {
55
55
  "@omer-x/package-metadata": "^1.0.2",
56
- "minimatch": "^10.0.3"
56
+ "minimatch": "^10.1.1"
57
57
  },
58
58
  "devDependencies": {
59
- "@omer-x/eslint-config": "^2.1.3",
60
- "@types/node": "^24.0.14",
61
- "@vitest/coverage-v8": "^3.2.4",
62
- "eslint": "^9.31.0",
63
- "semantic-release": "^24.2.7",
64
- "tsup": "^8.5.0",
65
- "vitest": "^3.2.4"
59
+ "@omer-x/eslint-config": "^2.2.6",
60
+ "@types/node": "^25.0.1",
61
+ "@vitest/coverage-v8": "^4.0.15",
62
+ "eslint": "^9.39.2",
63
+ "semantic-release": "^25.0.2",
64
+ "tsup": "^8.5.1",
65
+ "vitest": "^4.0.15"
66
66
  }
67
67
  }