/** * Writes the /api/v2 OpenAPI document to frontend/src/lib/api-v2/openapi.json, from which the * frontend's types are generated (`npm run api:types` in the repo root does both). Run it after * adding or changing a v2 route; tests/v2.test.ts fails while the saved copy is out of date. */ import 'dotenv/config'; import fs from 'fs'; import path from 'path'; import { buildOpenApi } from '../src/v2/openapi'; import '../src/v2'; export const OPENAPI_FILE = path.join(__dirname, '..', '..', 'frontend', 'src', 'lib', 'api-v2', 'openapi.json'); // The version is left out so a release bump doesn't change the file. export const currentDocument = () => JSON.stringify(buildOpenApi({ version: 'v2' }), null, 2) + '\n'; if (require.main === module) { fs.mkdirSync(path.dirname(OPENAPI_FILE), { recursive: true }); fs.writeFileSync(OPENAPI_FILE, currentDocument()); console.log(`Wrote ${path.relative(process.cwd(), OPENAPI_FILE)}`); process.exit(0); }