@omer-x/next-openapi-json-generator 1.1.0 → 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 CHANGED
@@ -76,8 +76,19 @@ function filterDirectoryItems(rootPath, items, include, exclude) {
76
76
  });
77
77
  }
78
78
 
79
- // src/core/next.ts
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 import_promises2.default.readFile(routePath2, "utf-8");
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);
@@ -195,7 +206,7 @@ function deepEqual(a, b) {
195
206
  }
196
207
 
197
208
  // src/core/zod-to-openapi.ts
198
- var import_zod_to_json_schema = __toESM(require("zod-to-json-schema"), 1);
209
+ var import_zod_to_json_schema = require("zod-to-json-schema");
199
210
 
200
211
  // src/utils/zod-schema.ts
201
212
  function isFile(schema) {
@@ -205,7 +216,7 @@ function isFile(schema) {
205
216
 
206
217
  // src/core/zod-to-openapi.ts
207
218
  function convertToOpenAPI(schema, isArray) {
208
- const result = (0, import_zod_to_json_schema.default)(isArray ? schema.array() : schema, {
219
+ const result = (0, import_zod_to_json_schema.zodToJsonSchema)(isArray ? schema.array() : schema, {
209
220
  target: "openApi3",
210
221
  $refStrategy: "none"
211
222
  });
@@ -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/next.ts
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 fs2.readFile(routePath2, "utf-8");
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);
@@ -159,7 +170,7 @@ function deepEqual(a, b) {
159
170
  }
160
171
 
161
172
  // src/core/zod-to-openapi.ts
162
- import zodToJsonSchema from "zod-to-json-schema";
173
+ import { zodToJsonSchema } from "zod-to-json-schema";
163
174
 
164
175
  // src/utils/zod-schema.ts
165
176
  function isFile(schema) {
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/next-openapi-json-generator",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "a Next.js plugin to generate OpenAPI documentation from route handlers",
5
5
  "keywords": [
6
6
  "next.js",
@@ -45,7 +45,7 @@
45
45
  "build": "tsup"
46
46
  },
47
47
  "dependencies": {
48
- "@omer-x/package-metadata": "^0.1.2",
48
+ "@omer-x/package-metadata": "^1.0.0",
49
49
  "minimatch": "^10.0.1",
50
50
  "typescript": "^5.6.3",
51
51
  "zod-to-json-schema": "^3.23.3"
@@ -53,9 +53,9 @@
53
53
  "devDependencies": {
54
54
  "@omer-x/eslint-config": "^1.0.7",
55
55
  "@omer-x/openapi-types": "^0.2.1",
56
- "@types/node": "^22.7.5",
56
+ "@types/node": "^22.7.9",
57
57
  "eslint": "^8.57.1",
58
- "semantic-release": "^24.1.2",
58
+ "semantic-release": "^24.1.3",
59
59
  "ts-jest": "^29.2.5",
60
60
  "ts-node": "^10.9.2",
61
61
  "tsup": "^8.3.0",