@omer-x/next-openapi-json-generator 1.1.1 → 1.1.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 +15 -2
- package/dist/index.js +15 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -76,8 +76,19 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
|
|
|
76
76
|
});
|
|
77
77
|
}
|
|
78
78
|
|
|
79
|
-
// src/core/
|
|
79
|
+
// src/core/isDocumentedRoute.ts
|
|
80
80
|
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
81
|
+
async function isDocumentedRoute(routePath2) {
|
|
82
|
+
try {
|
|
83
|
+
const rawCode = await import_promises2.default.readFile(routePath2, "utf-8");
|
|
84
|
+
return rawCode.includes("@omer-x/next-openapi-route-handler");
|
|
85
|
+
} catch {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// src/core/next.ts
|
|
91
|
+
var import_promises3 = __toESM(require("fs/promises"), 1);
|
|
81
92
|
var import_node_path2 = __toESM(require("path"), 1);
|
|
82
93
|
|
|
83
94
|
// src/core/middleware.ts
|
|
@@ -138,7 +149,7 @@ function safeEval(code, routePath) {
|
|
|
138
149
|
}
|
|
139
150
|
}
|
|
140
151
|
async function getRouteExports(routePath2, routeDefinerName, schemas) {
|
|
141
|
-
const rawCode = await
|
|
152
|
+
const rawCode = await import_promises3.default.readFile(routePath2, "utf-8");
|
|
142
153
|
const middlewareName = detectMiddlewareName(rawCode);
|
|
143
154
|
const code2 = transpile(rawCode, routeDefinerName, middlewareName);
|
|
144
155
|
const fixedCode = Object.keys(schemas).reduce(injectSchemas, code2);
|
|
@@ -364,6 +375,8 @@ async function generateOpenApiSpec(schemas, {
|
|
|
364
375
|
const verifiedRoutes = filterDirectoryItems(appFolderPath, routes, verifiedOptions.include, verifiedOptions.exclude);
|
|
365
376
|
const validRoutes = [];
|
|
366
377
|
for (const route of verifiedRoutes) {
|
|
378
|
+
const isDocumented = await isDocumentedRoute(route);
|
|
379
|
+
if (!isDocumented) continue;
|
|
367
380
|
const exportedRouteHandlers = await getRouteExports(route, routeDefinerName, schemas);
|
|
368
381
|
for (const [method, routeHandler] of Object.entries(exportedRouteHandlers)) {
|
|
369
382
|
if (!routeHandler || !routeHandler.apiData) continue;
|
package/dist/index.js
CHANGED
|
@@ -40,8 +40,19 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
// src/core/
|
|
43
|
+
// src/core/isDocumentedRoute.ts
|
|
44
44
|
import fs2 from "node:fs/promises";
|
|
45
|
+
async function isDocumentedRoute(routePath2) {
|
|
46
|
+
try {
|
|
47
|
+
const rawCode = await fs2.readFile(routePath2, "utf-8");
|
|
48
|
+
return rawCode.includes("@omer-x/next-openapi-route-handler");
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// src/core/next.ts
|
|
55
|
+
import fs3 from "node:fs/promises";
|
|
45
56
|
import path2 from "node:path";
|
|
46
57
|
|
|
47
58
|
// src/core/middleware.ts
|
|
@@ -102,7 +113,7 @@ function safeEval(code, routePath) {
|
|
|
102
113
|
}
|
|
103
114
|
}
|
|
104
115
|
async function getRouteExports(routePath2, routeDefinerName, schemas) {
|
|
105
|
-
const rawCode = await
|
|
116
|
+
const rawCode = await fs3.readFile(routePath2, "utf-8");
|
|
106
117
|
const middlewareName = detectMiddlewareName(rawCode);
|
|
107
118
|
const code2 = transpile(rawCode, routeDefinerName, middlewareName);
|
|
108
119
|
const fixedCode = Object.keys(schemas).reduce(injectSchemas, code2);
|
|
@@ -328,6 +339,8 @@ async function generateOpenApiSpec(schemas, {
|
|
|
328
339
|
const verifiedRoutes = filterDirectoryItems(appFolderPath, routes, verifiedOptions.include, verifiedOptions.exclude);
|
|
329
340
|
const validRoutes = [];
|
|
330
341
|
for (const route of verifiedRoutes) {
|
|
342
|
+
const isDocumented = await isDocumentedRoute(route);
|
|
343
|
+
if (!isDocumented) continue;
|
|
331
344
|
const exportedRouteHandlers = await getRouteExports(route, routeDefinerName, schemas);
|
|
332
345
|
for (const [method, routeHandler] of Object.entries(exportedRouteHandlers)) {
|
|
333
346
|
if (!routeHandler || !routeHandler.apiData) continue;
|