fix: pre-fetch URL spec then bundle+dereference to handle self-referencing $ref

This commit is contained in:
2026-04-02 15:00:32 +08:00
parent 6aaba810d8
commit afd8b444c7
2 changed files with 17 additions and 12 deletions

View File

@@ -31,20 +31,14 @@ export default function ImportDialog({ onClose }: { onClose: () => void }) {
setLoading(true);
setError('');
try {
let spec: unknown;
let body: Record<string, unknown>;
if (mode === '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; }
body = { specUrl: url };
} else {
try { spec = JSON.parse(fileContent); } catch { spec = fileContent; }
try { body = { spec: JSON.parse(fileContent) }; } catch { body = { spec: fileContent }; }
}
const data = await apiFetch<ImportResult>('/projects', {
method: 'POST', body: JSON.stringify({ spec }),
method: 'POST', body: JSON.stringify(body),
});
setResult(data);
queryClient.invalidateQueries({ queryKey: ['projects'] });