next-openapi-gen 0.9.0 → 0.9.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/README.md CHANGED
@@ -213,7 +213,7 @@ export async function POST(request: NextRequest) {
213
213
  | `@description` | Endpoint description |
214
214
  | `@operationId` | Custom operation ID (overrides auto-generated ID) |
215
215
  | `@pathParams` | Path parameters type/schema |
216
- | `@params` | Query parameters type/schema |
216
+ | `@params` | Query parameters type/schema (use `@queryParams` if you have prettier-plugin-jsdoc conflicts) |
217
217
  | `@body` | Request body type/schema |
218
218
  | `@bodyDescription` | Request body description |
219
219
  | `@response` | Response type/schema with optional code and description (`User`, `201:User`, `User:Description`, `201:User:Description`) |
@@ -336,29 +336,34 @@ export class RouteProcessor {
336
336
  getRoutePath(filePath) {
337
337
  // Normalize path separators first
338
338
  const normalizedPath = filePath.replaceAll("\\", "/");
339
- // First, check if it's an app router path
340
- if (normalizedPath.includes("/app/api/")) {
341
- // Get the relative path from the api directory
342
- const apiDirPos = normalizedPath.lastIndexOf("/app/api/");
343
- let relativePath = normalizedPath.substring(apiDirPos + "/app/api".length);
344
- // Remove the /route.ts or /route.tsx suffix
345
- relativePath = relativePath.replace(/\/route\.tsx?$/, "");
346
- // Remove Next.js route groups (folders in parentheses like (authenticated), (marketing))
347
- relativePath = relativePath.replace(/\/\([^)]+\)/g, "");
348
- // Convert Next.js dynamic route syntax to OpenAPI parameter syntax
349
- relativePath = relativePath.replace(/\/\[([^\]]+)\]/g, "/{$1}");
350
- // Handle catch-all routes ([...param])
351
- relativePath = relativePath.replace(/\/\[\.\.\.(.*)\]/g, "/{$1}");
352
- return relativePath;
339
+ // Normalize apiDir to ensure consistent format
340
+ const normalizedApiDir = this.config.apiDir
341
+ .replaceAll("\\", "/")
342
+ .replace(/^\.\//, "")
343
+ .replace(/\/$/, "");
344
+ // Find the apiDir position in the normalized path
345
+ const apiDirIndex = normalizedPath.indexOf(normalizedApiDir);
346
+ if (apiDirIndex === -1) {
347
+ throw new Error(`Could not find apiDir "${this.config.apiDir}" in file path "${filePath}"`);
353
348
  }
354
- // For pages router or other formats
355
- const suffixPath = normalizedPath.split("api")[1];
356
- return suffixPath
357
- .replace(/route\.tsx?$/, "")
358
- .replace(/\/$/, "")
359
- .replace(/\/\([^)]+\)/g, "") // Remove route groups for pages router too
360
- .replace(/\/\[([^\]]+)\]/g, "/{$1}") // Replace [param] with {param}
361
- .replace(/\/\[\.\.\.(.*)\]/g, "/{$1}"); // Replace [...param] with {param}
349
+ // Extract the path after apiDir
350
+ let relativePath = normalizedPath.substring(apiDirIndex + normalizedApiDir.length);
351
+ // Remove the /route.ts or /route.tsx suffix
352
+ relativePath = relativePath.replace(/\/route\.tsx?$/, "");
353
+ // Ensure the path starts with /
354
+ if (!relativePath.startsWith("/")) {
355
+ relativePath = "/" + relativePath;
356
+ }
357
+ // Remove trailing slash
358
+ relativePath = relativePath.replace(/\/$/, "");
359
+ // Remove Next.js route groups (folders in parentheses like (authenticated), (marketing))
360
+ relativePath = relativePath.replace(/\/\([^)]+\)/g, "");
361
+ // Handle catch-all routes ([...param]) before converting dynamic routes
362
+ // This must come first because [...param] would also match the [param] pattern
363
+ relativePath = relativePath.replace(/\/\[\.\.\.(.*?)\]/g, "/{$1}");
364
+ // Convert Next.js dynamic route syntax to OpenAPI parameter syntax
365
+ relativePath = relativePath.replace(/\/\[([^\]]+)\]/g, "/{$1}");
366
+ return relativePath || "/";
362
367
  }
363
368
  getSortedPaths(paths) {
364
369
  function comparePaths(a, b) {
package/dist/lib/utils.js CHANGED
@@ -85,8 +85,9 @@ export function extractJSDocComments(path) {
85
85
  tag = match[1].trim();
86
86
  }
87
87
  }
88
- if (commentValue.includes("@params")) {
89
- paramsType = extractTypeFromComment(commentValue, "@params");
88
+ if (commentValue.includes("@params") || commentValue.includes("@queryParams")) {
89
+ paramsType = extractTypeFromComment(commentValue, "@queryParams") ||
90
+ extractTypeFromComment(commentValue, "@params");
90
91
  }
91
92
  if (commentValue.includes("@pathParams")) {
92
93
  pathParamsType = extractTypeFromComment(commentValue, "@pathParams");
@@ -169,8 +170,9 @@ export function extractJSDocComments(path) {
169
170
  }
170
171
  export function extractTypeFromComment(commentValue, tag) {
171
172
  // Updated regex to support generic types with angle brackets and array brackets
173
+ // Use multiline mode (m flag) to match tag at start of line (after optional * from JSDoc)
172
174
  return (commentValue
173
- .match(new RegExp(`${tag}\\s*\\s*([\\w<>,\\s\\[\\]]+)`))?.[1]
175
+ .match(new RegExp(`^\\s*\\*?\\s*${tag}\\s+([\\w<>,\\s\\[\\]]+)`, 'm'))?.[1]
174
176
  ?.trim() || "");
175
177
  }
176
178
  export function cleanComment(commentValue) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "next-openapi-gen",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "description": "Automatically generate OpenAPI 3.0 documentation from Next.js projects, with support for Zod schemas and TypeScript types.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",