fix(schema): generate full JSON schema with Zod v4
This commit is contained in:
parent
50afb6b2de
commit
aab8a23243
File diff suppressed because it is too large
Load Diff
17
script/build-schema-document.ts
Normal file
17
script/build-schema-document.ts
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
import * as z from "zod"
|
||||||
|
import { OhMyOpenCodeConfigSchema } from "../src/config/schema"
|
||||||
|
|
||||||
|
export function createOhMyOpenCodeJsonSchema(): Record<string, unknown> {
|
||||||
|
const jsonSchema = z.toJSONSchema(OhMyOpenCodeConfigSchema, {
|
||||||
|
target: "draft-07",
|
||||||
|
unrepresentable: "any",
|
||||||
|
})
|
||||||
|
|
||||||
|
return {
|
||||||
|
$schema: "http://json-schema.org/draft-07/schema#",
|
||||||
|
$id: "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/oh-my-opencode.schema.json",
|
||||||
|
title: "Oh My OpenCode Configuration",
|
||||||
|
description: "Configuration schema for oh-my-opencode plugin",
|
||||||
|
...jsonSchema,
|
||||||
|
}
|
||||||
|
}
|
||||||
18
script/build-schema.test.ts
Normal file
18
script/build-schema.test.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { describe, expect, test } from "bun:test"
|
||||||
|
import { createOhMyOpenCodeJsonSchema } from "./build-schema-document"
|
||||||
|
|
||||||
|
describe("build-schema-document", () => {
|
||||||
|
test("generates schema with skills property", () => {
|
||||||
|
// given
|
||||||
|
const expectedDraft = "http://json-schema.org/draft-07/schema#"
|
||||||
|
|
||||||
|
// when
|
||||||
|
const schema = createOhMyOpenCodeJsonSchema()
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(schema.$schema).toBe(expectedDraft)
|
||||||
|
expect(schema.title).toBe("Oh My OpenCode Configuration")
|
||||||
|
expect(schema.properties).toBeDefined()
|
||||||
|
expect(schema.properties.skills).toBeDefined()
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -1,24 +1,12 @@
|
|||||||
#!/usr/bin/env bun
|
#!/usr/bin/env bun
|
||||||
import * as z from "zod"
|
import { createOhMyOpenCodeJsonSchema } from "./build-schema-document"
|
||||||
import { zodToJsonSchema } from "zod-to-json-schema"
|
|
||||||
import { OhMyOpenCodeConfigSchema } from "../src/config/schema"
|
|
||||||
|
|
||||||
const SCHEMA_OUTPUT_PATH = "assets/oh-my-opencode.schema.json"
|
const SCHEMA_OUTPUT_PATH = "assets/oh-my-opencode.schema.json"
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
console.log("Generating JSON Schema...")
|
console.log("Generating JSON Schema...")
|
||||||
|
|
||||||
const jsonSchema = zodToJsonSchema(OhMyOpenCodeConfigSchema, {
|
const finalSchema = createOhMyOpenCodeJsonSchema()
|
||||||
target: "draft7",
|
|
||||||
})
|
|
||||||
|
|
||||||
const finalSchema = {
|
|
||||||
$schema: "http://json-schema.org/draft-07/schema#",
|
|
||||||
$id: "https://raw.githubusercontent.com/code-yeongyu/oh-my-opencode/master/assets/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))
|
await Bun.write(SCHEMA_OUTPUT_PATH, JSON.stringify(finalSchema, null, 2))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user