File size: 1,096 Bytes
8145bee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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>
  );
}