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 +1 -1
- package/dist/lib/route-processor.js +27 -22
- package/dist/lib/utils.js +5 -3
- package/package.json +1 -1
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
|
-
//
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
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
|
-
//
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
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, "@
|
|
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(
|
|
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