Skip to content

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

fix(docs): add redirect middleware for old Fern API reference URLs

Sushmithamallesh7bde9d59dcbc
diff --git a/docs/lib/source.ts b/docs/lib/source.ts
index bcf2d2111..25c7b9580 100644
--- a/docs/lib/source.ts
+++ b/docs/lib/source.ts
@@ -18,26 +18,11 @@ let _referenceSource: any = null;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let _openapiPagesPromise: Promise<any> | null = null;
-/**
- * Convert camelCase/PascalCase to kebab-case for URL compatibility
- * This matches the old Fern docs URL format (e.g., getTools -> get-tools)
- */
-function toKebabCase(name: string): string {
- return name
- .replace(/([a-z])([A-Z])/g, '$1-$2')
- .replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
- .toLowerCase()
- .replace(/[\s_]+/g, '-')
- .replace(/-+/g, '-')
- .replace(/^-|-$/g, '');
-}
-
async function getOpenapiPages() {
if (!_openapiPagesPromise) {
_openapiPagesPromise = openapiSource(openapi, {
groupBy: 'tag',
baseDir: 'api-reference',
- slugify: toKebabCase,
});
}
return _openapiPagesPromise;
diff --git a/docs/middleware.ts b/docs/middleware.ts
new file mode 100644
index 000000000..7ed563bbd
--- /dev/null
+++ b/docs/middleware.ts
@@ -0,0 +1,63 @@
+import { NextResponse } from 'next/server';
+import type { NextRequest } from 'next/server';
+
+/**
+ * Convert kebab-case to camelCase
+ */
+function kebabToCamel(str: string): string {
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
+}
+
+/**
+ * Check if a string contains kebab-case (has hyphens between lowercase letters)
+ */
+function hasKebabCase(str: string): boolean {
+ return /[a-z]-[a-z]/.test(str);
+}
+
+export function middleware(request: NextRequest) {
+ const { pathname } = request.nextUrl;
+
+ // Only handle API reference paths
+ if (!pathname.startsWith('/reference/api-reference/')) {
+ return NextResponse.next();
+ }
+
+ // Check if any path segment has kebab-case
+ const segments = pathname.split('/');
+ let hasKebab = false;
+
+ for (const segment of segments) {
+ if (hasKebabCase(segment)) {
+ hasKebab = true;
+ break;
+ }
+ }
+
+ if (!hasKebab) {
+ return NextResponse.next();
+ }
+
+ // Convert kebab-case segments to camelCase
+ const newSegments = segments.map((segment, index) => {
+ // Only convert segments after 'api-reference' (skip the tag/category names)
+ // api-reference structure: /reference/api-reference/{tag}/{operationId}
+ if (index <= 3) return segment; // Keep /reference/api-reference/{tag} as-is
+ return kebabToCamel(segment);
+ });
+
+ const newPathname = newSegments.join('/');
+
+ // Only redirect if the path actually changed
+ if (newPathname !== pathname) {
+ const url = request.nextUrl.clone();
+ url.pathname = newPathname;
+ return NextResponse.redirect(url, 301);
+ }
+
+ return NextResponse.next();
+}
+
+export const config = {
+ matcher: '/reference/api-reference/:path*',
+};