import { useEffect, useRef, useState } from "react"; import { Link } from "wouter"; import { ArrowLeft, Loader2 } from "lucide-react"; // @ts-expect-error no types import SwaggerUIBundle from "swagger-ui-dist/swagger-ui-bundle.js"; import "swagger-ui-dist/swagger-ui.css"; export default function SwaggerPage() { const containerRef = useRef(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!containerRef.current) return; // Determine the OpenAPI JSON URL — same origin as the page const base = (import.meta.env.VITE_API_BASE as string | undefined) ?? ""; const url = `${base}/openapi.json`; try { SwaggerUIBundle({ url, domNode: containerRef.current, presets: [SwaggerUIBundle.presets.apis, SwaggerUIBundle.SwaggerUIStandalonePreset], layout: "BaseLayout", deepLinking: true, displayRequestDuration: true, filter: true, tryItOutEnabled: true, onComplete: () => setLoading(false), }); setLoading(false); } catch (e) { setError(String(e)); setLoading(false); } }, []); return (
{/* Header */}
API Documentation OpenAPI 3.1
{/* Swagger UI */}
{loading && (
Loading API docs…
)} {error && (

Failed to load API docs: {error}

)}
); }