@devries-cameron20 / composio-1 / commits / 4b423e918
Fork 0

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

refactor(docs): simplify kebab-case redirect logic

Remove redundant hasKebab detection loop. Since kebabToCamel() returns input unchanged when there's no kebab pattern, the pathname comparison already catches whether any conversion occurred. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Sushmithamallesh committed Jan 28, 2026 at 01:51 UTC 4b423e91830ab3b0ee9e3fa79caa10904d5522a7
1 file changed +11 -29
docs/proxy.ts
+11 -29
@@ -7,13 +7,6 @@ function kebabToCamel(str: string): string {
7 return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
8 }
9
10 -/**
11 - * Check if a string contains kebab-case (has hyphens between lowercase letters)
12 - */
13 -function hasKebabCase(str: string): boolean {
14 - return /[a-z]-[a-z]/.test(str);
15 -}
16 -
10 /**
11 * Proxy handles:
12 * 1. Markdown content negotiation for AI agents (Accept: text/markdown)
@@ -33,30 +26,19 @@ export function proxy(request: NextRequest) {
26 // Example: /reference/api-reference/tools/get-tools → /reference/api-reference/tools/getTools
27 if (pathname.startsWith('/reference/api-reference/')) {
28 const segments = pathname.split('/');
36 - let hasKebab = false;
29
38 - // Check if any segment after the tag has kebab-case
30 + // Convert kebab-case segments to camelCase (only operation IDs after index 3)
31 // Structure: /reference/api-reference/{tag}/{operationId}
40 - for (let i = 4; i < segments.length; i++) {
41 - if (hasKebabCase(segments[i])) {
42 - hasKebab = true;
43 - break;
44 - }
45 - }
46 -
47 - if (hasKebab) {
48 - // Convert kebab-case segments to camelCase (only operation IDs, not tags)
49 - const newSegments = segments.map((segment, index) => {
50 - if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is
51 - return kebabToCamel(segment);
52 - });
53 -
54 - const newPathname = newSegments.join('/');
55 - if (newPathname !== pathname) {
56 - const url = request.nextUrl.clone();
57 - url.pathname = newPathname;
58 - return NextResponse.redirect(url, 301);
59 - }
32 + const newSegments = segments.map((segment, index) => {
33 + if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is
34 + return kebabToCamel(segment);
35 + });
36 +
37 + const newPathname = newSegments.join('/');
38 + if (newPathname !== pathname) {
39 + const url = request.nextUrl.clone();
40 + url.pathname = newPathname;
41 + return NextResponse.redirect(url, 301);
42 }
43 }
44