Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Mirrored from https://github.com/Camo67/composio.git
Synced Nov 22, 12:00 UTC
fix(docs): add redirect middleware for old Fern API reference URLs
Adds middleware to redirect kebab-case API reference URLs (old Fern format) to camelCase URLs (current fumadocs-openapi format). Example: /reference/api-reference/tools/get-tools → /reference/api-reference/tools/getTools This maintains SEO continuity with the old documentation URLs. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Sushmithamallesh committed
Jan 28, 2026 at 01:36 UTC
7bde9d59dcbc54efab656b4df5c805fb9f47e825
2 files changed
+63
-15
docs/lib/source.ts
-15
@@ -18,26 +18,11 @@ let _referenceSource: any = null;
18
// eslint-disable-next-line @typescript-eslint/no-explicit-any
19
let _openapiPagesPromise: Promise<any> | null = null;
20
21
-/**
22
- * Convert camelCase/PascalCase to kebab-case for URL compatibility
23
- * This matches the old Fern docs URL format (e.g., getTools -> get-tools)
24
- */
25
-function toKebabCase(name: string): string {
26
- return name
27
- .replace(/([a-z])([A-Z])/g, '$1-$2')
28
- .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
29
- .toLowerCase()
30
- .replace(/[\s_]+/g, '-')
31
- .replace(/-+/g, '-')
32
- .replace(/^-|-$/g, '');
33
-}
34
-
21
async function getOpenapiPages() {
22
if (!_openapiPagesPromise) {
23
_openapiPagesPromise = openapiSource(openapi, {
24
groupBy: 'tag',
25
baseDir: 'api-reference',
40
- slugify: toKebabCase,
26
});
27
}
28
return _openapiPagesPromise;
docs/middleware.ts
new
+63
@@ -0,0 +1,63 @@
1
+import { NextResponse } from 'next/server';
2
+import type { NextRequest } from 'next/server';
3
+
4
+/**
5
+ * Convert kebab-case to camelCase
6
+ */
7
+function kebabToCamel(str: string): string {
8
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
9
+}
10
+
11
+/**
12
+ * Check if a string contains kebab-case (has hyphens between lowercase letters)
13
+ */
14
+function hasKebabCase(str: string): boolean {
15
+ return /[a-z]-[a-z]/.test(str);
16
+}
17
+
18
+export function middleware(request: NextRequest) {
19
+ const { pathname } = request.nextUrl;
20
+
21
+ // Only handle API reference paths
22
+ if (!pathname.startsWith('/reference/api-reference/')) {
23
+ return NextResponse.next();
24
+ }
25
+
26
+ // Check if any path segment has kebab-case
27
+ const segments = pathname.split('/');
28
+ let hasKebab = false;
29
+
30
+ for (const segment of segments) {
31
+ if (hasKebabCase(segment)) {
32
+ hasKebab = true;
33
+ break;
34
+ }
35
+ }
36
+
37
+ if (!hasKebab) {
38
+ return NextResponse.next();
39
+ }
40
+
41
+ // Convert kebab-case segments to camelCase
42
+ const newSegments = segments.map((segment, index) => {
43
+ // Only convert segments after 'api-reference' (skip the tag/category names)
44
+ // api-reference structure: /reference/api-reference/{tag}/{operationId}
45
+ if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is
46
+ return kebabToCamel(segment);
47
+ });
48
+
49
+ const newPathname = newSegments.join('/');
50
+
51
+ // Only redirect if the path actually changed
52
+ if (newPathname !== pathname) {
53
+ const url = request.nextUrl.clone();
54
+ url.pathname = newPathname;
55
+ return NextResponse.redirect(url, 301);
56
+ }
57
+
58
+ return NextResponse.next();
59
+}
60
+
61
+export const config = {
62
+ matcher: '/reference/api-reference/:path*',
63
+};