@omer-x/next-openapi-json-generator 1.3.4 → 2.0.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/dist/index.cjs +9 -36
- package/dist/index.js +12 -39
- package/package.json +17 -17
package/dist/index.cjs
CHANGED
|
@@ -28,11 +28,11 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
30
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
33
|
-
default: () =>
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
default: () => index_default
|
|
34
34
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
35
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
36
|
|
|
37
37
|
// src/core/generateOpenApiSpec.ts
|
|
38
38
|
var import_node_path4 = __toESM(require("path"), 1);
|
|
@@ -272,36 +272,9 @@ function deepEqual(a, b) {
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
// src/core/zod-to-openapi.ts
|
|
275
|
-
var
|
|
276
|
-
|
|
277
|
-
// src/utils/zod-schema.ts
|
|
278
|
-
function isFile(schema) {
|
|
279
|
-
const file = new File([], "nothing.txt");
|
|
280
|
-
const plainObject = { name: "test", size: 0 };
|
|
281
|
-
const fileResult = schema.safeParse(file);
|
|
282
|
-
const objectResult = schema.safeParse(plainObject);
|
|
283
|
-
return fileResult.success && !objectResult.success;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// src/core/zod-to-openapi.ts
|
|
275
|
+
var import_zod = require("zod");
|
|
287
276
|
function convertToOpenAPI(schema, isArray) {
|
|
288
|
-
|
|
289
|
-
target: "openApi3",
|
|
290
|
-
$refStrategy: "none"
|
|
291
|
-
});
|
|
292
|
-
if (result.type === "object" && result.properties) {
|
|
293
|
-
for (const [propName, prop] of Object.entries(schema.shape)) {
|
|
294
|
-
if (isFile(prop)) {
|
|
295
|
-
result.properties[propName] = {
|
|
296
|
-
type: "string",
|
|
297
|
-
format: "binary",
|
|
298
|
-
description: prop.description
|
|
299
|
-
// contentEncoding: "base64", // swagger-ui-react doesn't support this
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
return result;
|
|
277
|
+
return import_zod.z.toJSONSchema(isArray ? schema.array() : schema);
|
|
305
278
|
}
|
|
306
279
|
|
|
307
280
|
// src/core/mask.ts
|
|
@@ -469,7 +442,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
469
442
|
securitySchemes
|
|
470
443
|
}
|
|
471
444
|
};
|
|
472
|
-
return {
|
|
445
|
+
return JSON.parse(JSON.stringify({
|
|
473
446
|
openapi: "3.1.0",
|
|
474
447
|
info: {
|
|
475
448
|
title: metadata.serviceName,
|
|
@@ -480,8 +453,8 @@ async function generateOpenApiSpec(schemas, {
|
|
|
480
453
|
...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
|
|
481
454
|
security,
|
|
482
455
|
tags: []
|
|
483
|
-
};
|
|
456
|
+
}));
|
|
484
457
|
}
|
|
485
458
|
|
|
486
459
|
// src/index.ts
|
|
487
|
-
var
|
|
460
|
+
var index_default = generateOpenApiSpec;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/core/generateOpenApiSpec.ts
|
|
2
|
-
import path4 from "
|
|
2
|
+
import path4 from "path";
|
|
3
3
|
import getPackageMetadata from "@omer-x/package-metadata";
|
|
4
4
|
|
|
5
5
|
// src/utils/object.ts
|
|
@@ -35,7 +35,7 @@ function clearUnusedSchemas({
|
|
|
35
35
|
// src/core/dir.ts
|
|
36
36
|
import { constants } from "fs";
|
|
37
37
|
import fs from "fs/promises";
|
|
38
|
-
import path from "
|
|
38
|
+
import path from "path";
|
|
39
39
|
import { Minimatch } from "minimatch";
|
|
40
40
|
async function directoryExists(dirPath) {
|
|
41
41
|
try {
|
|
@@ -72,7 +72,7 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
// src/core/isDocumentedRoute.ts
|
|
75
|
-
import fs2 from "
|
|
75
|
+
import fs2 from "fs/promises";
|
|
76
76
|
async function isDocumentedRoute(routePath2) {
|
|
77
77
|
try {
|
|
78
78
|
const rawCode = await fs2.readFile(routePath2, "utf-8");
|
|
@@ -83,8 +83,8 @@ async function isDocumentedRoute(routePath2) {
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
// src/core/next.ts
|
|
86
|
-
import fs3 from "
|
|
87
|
-
import path2 from "
|
|
86
|
+
import fs3 from "fs/promises";
|
|
87
|
+
import path2 from "path";
|
|
88
88
|
|
|
89
89
|
// src/utils/generateRandomString.ts
|
|
90
90
|
function generateRandomString(length) {
|
|
@@ -207,7 +207,7 @@ function verifyOptions(include, exclude) {
|
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
// src/core/getRoutePathName.ts
|
|
210
|
-
import path3 from "
|
|
210
|
+
import path3 from "path";
|
|
211
211
|
function getRoutePathName(filePath, rootPath) {
|
|
212
212
|
const dirName = path3.dirname(filePath);
|
|
213
213
|
return "/" + path3.relative(rootPath, dirName).replaceAll("[", "{").replaceAll("]", "}").replaceAll("\\", "/");
|
|
@@ -236,36 +236,9 @@ function deepEqual(a, b) {
|
|
|
236
236
|
}
|
|
237
237
|
|
|
238
238
|
// src/core/zod-to-openapi.ts
|
|
239
|
-
import {
|
|
240
|
-
|
|
241
|
-
// src/utils/zod-schema.ts
|
|
242
|
-
function isFile(schema) {
|
|
243
|
-
const file = new File([], "nothing.txt");
|
|
244
|
-
const plainObject = { name: "test", size: 0 };
|
|
245
|
-
const fileResult = schema.safeParse(file);
|
|
246
|
-
const objectResult = schema.safeParse(plainObject);
|
|
247
|
-
return fileResult.success && !objectResult.success;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// src/core/zod-to-openapi.ts
|
|
239
|
+
import { z } from "zod";
|
|
251
240
|
function convertToOpenAPI(schema, isArray) {
|
|
252
|
-
|
|
253
|
-
target: "openApi3",
|
|
254
|
-
$refStrategy: "none"
|
|
255
|
-
});
|
|
256
|
-
if (result.type === "object" && result.properties) {
|
|
257
|
-
for (const [propName, prop] of Object.entries(schema.shape)) {
|
|
258
|
-
if (isFile(prop)) {
|
|
259
|
-
result.properties[propName] = {
|
|
260
|
-
type: "string",
|
|
261
|
-
format: "binary",
|
|
262
|
-
description: prop.description
|
|
263
|
-
// contentEncoding: "base64", // swagger-ui-react doesn't support this
|
|
264
|
-
};
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return result;
|
|
241
|
+
return z.toJSONSchema(isArray ? schema.array() : schema);
|
|
269
242
|
}
|
|
270
243
|
|
|
271
244
|
// src/core/mask.ts
|
|
@@ -433,7 +406,7 @@ async function generateOpenApiSpec(schemas, {
|
|
|
433
406
|
securitySchemes
|
|
434
407
|
}
|
|
435
408
|
};
|
|
436
|
-
return {
|
|
409
|
+
return JSON.parse(JSON.stringify({
|
|
437
410
|
openapi: "3.1.0",
|
|
438
411
|
info: {
|
|
439
412
|
title: metadata.serviceName,
|
|
@@ -444,11 +417,11 @@ async function generateOpenApiSpec(schemas, {
|
|
|
444
417
|
...clearUnusedSchemasOption ? clearUnusedSchemas(pathsAndComponents) : pathsAndComponents,
|
|
445
418
|
security,
|
|
446
419
|
tags: []
|
|
447
|
-
};
|
|
420
|
+
}));
|
|
448
421
|
}
|
|
449
422
|
|
|
450
423
|
// src/index.ts
|
|
451
|
-
var
|
|
424
|
+
var index_default = generateOpenApiSpec;
|
|
452
425
|
export {
|
|
453
|
-
|
|
426
|
+
index_default as default
|
|
454
427
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omer-x/next-openapi-json-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"next.js",
|
|
@@ -40,28 +40,28 @@
|
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|
|
43
|
-
"test": "
|
|
43
|
+
"test": "vitest run --coverage",
|
|
44
|
+
"test:watch": "vitest --coverage",
|
|
44
45
|
"dev": "tsup --watch",
|
|
45
46
|
"build": "tsup"
|
|
46
47
|
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@omer-x/next-openapi-route-handler": "^2",
|
|
50
|
+
"@omer-x/openapi-types": "^1",
|
|
51
|
+
"zod": "^4",
|
|
52
|
+
"typescript": "^5"
|
|
53
|
+
},
|
|
47
54
|
"dependencies": {
|
|
48
55
|
"@omer-x/package-metadata": "^1.0.2",
|
|
49
|
-
"minimatch": "^10.0.
|
|
50
|
-
"typescript": "^5.7.2",
|
|
51
|
-
"zod-to-json-schema": "^3.24.1"
|
|
56
|
+
"minimatch": "^10.0.3"
|
|
52
57
|
},
|
|
53
58
|
"devDependencies": {
|
|
54
|
-
"@omer-x/eslint-config": "^2.1.
|
|
55
|
-
"@types/node": "^
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"zod": "^3.24.1"
|
|
62
|
-
},
|
|
63
|
-
"peerDependencies": {
|
|
64
|
-
"@omer-x/next-openapi-route-handler": "^1",
|
|
65
|
-
"@omer-x/openapi-types": "^1"
|
|
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"
|
|
66
66
|
}
|
|
67
67
|
}
|