import { useState, useRef } from 'react'; import { IconCheck } from '@tabler/icons'; import Button from 'ui/Button'; import { isHttpUrl } from 'utils/url/index'; import { isOpenApiSpec } from 'utils/importers/openapi-collection'; import { parseFileAsJsonOrYaml } from 'utils/importers/file-reader'; const FEATURES = [ 'Detect new, modified, and removed endpoints', 'Track local changes against the spec', 'Sync collection with a single click', 'Your tests, assertions, and scripts are preserved during sync' ]; const ConnectSpecForm = ({ sourceUrl, setSourceUrl, isLoading, error, setError, onConnect }) => { const [mode, setMode] = useState('url'); const fileInputRef = useRef(null); return (

Connect to OpenAPI Spec

Keep your collection synchronized with an OpenAPI specification. Changes in the spec will be detected automatically.

{ e.preventDefault(); onConnect(); }} >
{mode === 'url' ? ( setSourceUrl(e.target.value)} placeholder="https://api.example.com/openapi.json" /> ) : ( <> { const file = e.target.files?.[0]; if (!file) return; setError(null); setSourceUrl(''); try { const data = await parseFileAsJsonOrYaml(file); if (!isOpenApiSpec(data)) { setError('The selected file is not a valid OpenAPI 3.x specification'); return; } const filePath = window.ipcRenderer.getFilePath(file); if (filePath) setSourceUrl(filePath); } catch (err) { setError(err.message || 'Failed to read the selected file'); } }} /> )}

{mode === 'url' ? 'Supports OpenAPI 3.x specifications in JSON or YAML format' : 'Select a local OpenAPI/Swagger JSON or YAML file'}

{error && (

{error}

)}
{FEATURES.map((text) => (
{text}
))}

OpenAPI Sync is in Beta — we'd love to hear your feedback and suggestions.{' '}

); }; export default ConnectSpecForm;