generate-schema.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435
  1. #!/usr/bin/env bun
  2. /**
  3. * Generates a JSON Schema from the Zod PluginConfigSchema.
  4. * Run as part of the build step so the schema stays in sync with the source.
  5. */
  6. import { writeFileSync } from 'node:fs';
  7. import { dirname, join } from 'node:path';
  8. import { fileURLToPath } from 'node:url';
  9. import { z } from 'zod';
  10. import { PluginConfigSchema } from '../src/config/schema';
  11. const __dirname = dirname(fileURLToPath(import.meta.url));
  12. const rootDir = join(__dirname, '..');
  13. const outputPath = join(rootDir, 'oh-my-opencode-slim.schema.json');
  14. const schema = z.toJSONSchema(PluginConfigSchema, {
  15. // Use 'input' so defaulted fields are optional in the schema,
  16. // matching how users actually write their config files
  17. io: 'input',
  18. });
  19. const jsonSchema = {
  20. ...schema,
  21. $schema: 'https://json-schema.org/draft/2020-12/schema',
  22. title: 'oh-my-opencode-slim',
  23. description:
  24. 'Configuration schema for oh-my-opencode-slim plugin for OpenCode',
  25. };
  26. const json = JSON.stringify(jsonSchema, null, 2);
  27. writeFileSync(outputPath, `${json}\n`);
  28. console.log(`✅ Schema written to ${outputPath}`);