/** * Exports every registry schema to contracts/schema/.json (JSON Schema, * draft 2020-12). These committed files are the neutral cross-language contract * (ADR-0002); the Python side generates pydantic models from them. */ import { mkdirSync, writeFileSync } from 'node:fs' import { fileURLToPath } from 'node:url' import { z } from 'zod' import { schemaRegistry } from '../src/index.js' const outDir = fileURLToPath(new URL('../../../contracts/schema/', import.meta.url)) mkdirSync(outDir, { recursive: true }) const pascal = (s: string) => s.split('_').map((w) => w[0]!.toUpperCase() + w.slice(1)).join('') for (const [name, schema] of Object.entries(schemaRegistry)) { const json = z.toJSONSchema(schema) as Record json['$id'] = `https://vpp-ai-platform/contracts/${name}.json` json['title'] = pascal(name) // becomes the pydantic class name writeFileSync(`${outDir}${name}.json`, JSON.stringify(json, null, 2) + '\n') console.log(`exported ${name}.json`) }