loopable / web /src /settings /KeyOpenApiRow.tsx
fsanyoto's picture
Deploy AIOS web (React glide grid + FastAPI slice)
8145bee verified
Raw History Blame Contribute Delete
1.1 kB
import type { ReactNode } from "react";
export function openApiDocumentUrl(apiBase: string, origin: string): string {
return new URL(`${apiBase.replace(/\/+$/, "")}/external/openapi.json`, origin).href;
}
export function openApiTypesCommand(documentUrl: string): string {
return `curl -fsS -H "Authorization: Bearer $LOOPABLE_API_KEY" ${documentUrl} | npx openapi-typescript -o loopable.d.ts`;
}
type Props = {
documentUrl: string;
renderCode: (value: string, name: string, content?: ReactNode) => ReactNode;
};
export function KeyOpenApiRow({ documentUrl, renderCode }: Props) {
return (
<details className="external-divider" data-key-openapi>
<summary className="set-help">OpenAPI</summary>
<div className="set-field">
<span className="set-label">Document</span>
{renderCode(documentUrl, "document", <a href={documentUrl}>{documentUrl}</a>)}
</div>
<div className="set-field">
<span className="set-label">Generate types</span>
{renderCode(openApiTypesCommand(documentUrl), "command")}
</div>
</details>
);
}