File size: 1,124 Bytes
af1bee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// Regenerate the typed API client from FastAPI's OpenAPI: python dumps the schema -> src/api/openapi.json ->
// openapi-typescript -> src/api/schema.d.ts. A backend test (coworker/tests/test_openapi_sync.py) fails on drift.
import { execFileSync } from 'node:child_process';
import { existsSync, writeFileSync } from 'node:fs';
import { resolve, dirname } from 'node:path';
import { fileURLToPath } from 'node:url';

const here = dirname(fileURLToPath(import.meta.url));
const root = resolve(here, '..', '..');
const py = [resolve(root, 'architecture/.venv/Scripts/python.exe'), resolve(root, 'architecture/.venv/bin/python')].find(existsSync) || 'python';
const json = execFileSync(py, ['-m', 'coworker.api.openapi_dump'], { cwd: root, encoding: 'utf-8', maxBuffer: 64 * 1024 * 1024 });
const out = resolve(here, '..', 'src', 'api', 'openapi.json');
writeFileSync(out, json);
execFileSync(process.execPath, [resolve(here, '..', 'node_modules', 'openapi-typescript', 'bin', 'cli.js'), out, '-o', resolve(here, '..', 'src', 'api', 'schema.d.ts')], { stdio: 'inherit' });
console.log('API types regenerated');