import { mkdir, writeFile } from 'node:fs/promises'; const url = process.env.OPENAPI_URL ?? 'http://localhost:5080/swagger/v1/swagger.json'; const output = new URL('../../shared/openapi/openapi.json', import.meta.url); console.log(`Fetching OpenAPI schema from ${url}`); const response = await fetch(url); if (!response.ok) { throw new Error(`Failed to fetch OpenAPI schema: ${response.status} ${response.statusText}`); } const schema = await response.text(); await mkdir(new URL('../../shared/openapi', import.meta.url), { recursive: true }); await writeFile(output, schema); console.log(`Wrote ${output.pathname}`);