feat(config): add Zod schema validation and JSON Schema generation

- Add Zod schema for oh-my-opencode.json configuration validation
- Generate JSON Schema at build time for IDE autocompletion
- Add safeParse validation with error reporting on config load
- Export OhMyOpenCodeConfigSchema for programmatic usage
- Add build:schema script and ./schema.json export
- Update README with $schema usage documentation
This commit is contained in:
YeonGyu-Kim
2025-12-05 02:53:44 +09:00
parent 8e5064c547
commit b5274fcb63
3 changed files with 100 additions and 0 deletions

28
script/build-schema.ts Normal file
View File

@@ -0,0 +1,28 @@
#!/usr/bin/env bun
import * as z from "zod"
import { OhMyOpenCodeConfigSchema } from "../src/config/schema"
const SCHEMA_OUTPUT_PATH = "dist/oh-my-opencode.schema.json"
async function main() {
console.log("Generating JSON Schema...")
const jsonSchema = z.toJSONSchema(OhMyOpenCodeConfigSchema, {
io: "input",
target: "draft-7",
})
const finalSchema = {
$schema: "http://json-schema.org/draft-07/schema#",
$id: "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/dist/oh-my-opencode.schema.json",
title: "Oh My OpenCode Configuration",
description: "Configuration schema for oh-my-opencode plugin",
...jsonSchema,
}
await Bun.write(SCHEMA_OUTPUT_PATH, JSON.stringify(finalSchema, null, 2))
console.log(`✓ JSON Schema generated: ${SCHEMA_OUTPUT_PATH}`)
}
main()