klg-asutk-app/app/api-docs/page.tsx
Yuriy 0150aba4f5 Consolidation: KLG ASUTK + PAPA integration
- Unify API: lib/api.ts uses /api/v1, inbox uses /api/inbox (rewrites)
- Remove localhost refs: openapi, inbox page
- Add rewrites: /api/inbox|tmc -> inbox-server, /api/v1 -> FastAPI
- Add stub routes: knowledge/insights, recommendations, search, log-error
- Transfer from PAPA: prompts (inspection, tmc), scripts, supabase, data/tmc-requests
- Fix inbox-server: ORDER BY created_at, package.json
- Remove redundant app/api/inbox/files route (rewrites handle it)
- knowledge/ in gitignore (large PDFs)

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-08 17:18:31 +03:00

81 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { useEffect, useRef, useState } from 'react';
export default function ApiDocsPage() {
const [SwaggerUI, setSwaggerUI] = useState<any>(null);
const [spec, setSpec] = useState<any>(null);
const swaggerRef = useRef<any>(null);
useEffect(() => {
// Динамически загружаем SwaggerUI только на клиенте
if (typeof window !== 'undefined') {
// Используем eval для обхода статического анализа Next.js
const loadSwaggerUI = async () => {
try {
// @ts-ignore
const swaggerModule = await eval('import("swagger-ui-react")');
if (swaggerModule && swaggerModule.default) {
setSwaggerUI(() => swaggerModule.default);
// CSS загрузится автоматически
}
} catch (err) {
console.warn('swagger-ui-react not installed:', err);
}
};
loadSwaggerUI();
}
// Загружаем OpenAPI спецификацию
fetch('/api/openapi')
.then(res => res.json())
.then(data => {
setSpec(data);
if (swaggerRef.current) {
swaggerRef.current.specActions.updateSpec(data);
}
})
.catch(err => {
console.error('Failed to load OpenAPI spec:', err);
});
}, []);
return (
<div style={{ padding: '20px' }}>
<div style={{ marginBottom: '24px' }}>
<h1 style={{ fontSize: '32px', fontWeight: 'bold', marginBottom: '8px' }}>
API Документация
</h1>
<p style={{ fontSize: '16px', color: '#666' }}>
Интерактивная документация для AI endpoints
</p>
</div>
{!SwaggerUI ? (
<div style={{ padding: '40px', textAlign: 'center', color: '#666' }}>
<p>Загрузка Swagger UI...</p>
<p style={{ fontSize: '14px', marginTop: '8px', color: '#999' }}>
Если Swagger UI не загружается, установите: npm install swagger-ui-react
</p>
{spec && (
<pre style={{ marginTop: '20px', padding: '16px', backgroundColor: '#f5f5f5', borderRadius: '4px', overflow: 'auto', textAlign: 'left' }}>
{JSON.stringify(spec, null, 2)}
</pre>
)}
</div>
) : (
<div style={{ border: '1px solid #e0e0e0', borderRadius: '8px', overflow: 'hidden' }}>
<SwaggerUI
spec={spec}
url="/api/openapi"
ref={swaggerRef}
docExpansion="list"
defaultModelsExpandDepth={1}
defaultModelExpandDepth={1}
/>
</div>
)}
</div>
);
}