@omer-x/next-openapi-json-generator 2.0.2 → 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 +28 -1
- package/dist/index.js +28 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -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
|
@@ -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.
|
|
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.
|
|
56
|
+
"minimatch": "^10.1.1"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@omer-x/eslint-config": "^2.
|
|
60
|
-
"@types/node": "^
|
|
61
|
-
"@vitest/coverage-v8": "^
|
|
62
|
-
"eslint": "^9.
|
|
63
|
-
"semantic-release": "^
|
|
64
|
-
"tsup": "^8.5.
|
|
65
|
-
"vitest": "^
|
|
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
|
}
|