fix: fetch OpenAPI doc from browser to avoid Docker network isolation, add Swagger 2.0 support

This commit is contained in:
2026-04-02 14:51:43 +08:00
parent 5f76abec8b
commit 6aaba810d8
3 changed files with 94 additions and 24 deletions

View File

@@ -31,14 +31,20 @@ export default function ImportDialog({ onClose }: { onClose: () => void }) {
setLoading(true);
setError('');
try {
let body: Record<string, unknown>;
let spec: unknown;
if (mode === 'url') {
body = { specUrl: url };
// Fetch from browser (can access local network) instead of letting server fetch
const res = await fetch(url);
if (!res.ok) throw new Error(`Failed to fetch: ${res.status} ${res.statusText}`);
const text = await res.text();
try { spec = JSON.parse(text); } catch { spec = text; }
} else {
try { body = { spec: JSON.parse(fileContent) }; } catch { body = { spec: fileContent }; }
try { spec = JSON.parse(fileContent); } catch { spec = fileContent; }
}
const data = await apiFetch<ImportResult>('/projects', {
method: 'POST', body: JSON.stringify(body),
method: 'POST', body: JSON.stringify({ spec }),
});
setResult(data);
queryClient.invalidateQueries({ queryKey: ['projects'] });