next-openapi-gen 0.9.0 → 0.9.1
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/lib/route-processor.js +27 -22
- package/package.json +1 -1
|
@@ -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/package.json
CHANGED