-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-schema.ts
More file actions
32 lines (27 loc) · 1.12 KB
/
generate-schema.ts
File metadata and controls
32 lines (27 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import * as z from "zod";
import { CONFIG_FILE_NAME } from "@/config/constants";
import { ConfigSchema } from "@/config/schema";
// Read package.json to get version for schema $id
const packageJsonPath = `${import.meta.dir}/../package.json`;
const packageJson = await Bun.file(packageJsonPath).json();
const version = packageJson.version;
const jsonSchema = z.toJSONSchema(ConfigSchema, {
io: "input",
target: "draft-2020-12",
unrepresentable: "throw",
});
const rootSchema = jsonSchema as z.core.JSONSchema.ObjectSchema;
rootSchema.properties ??= {};
rootSchema.properties.$schema = {
type: "string",
description: "JSON Schema URL for editor autocomplete and validation",
};
// Add $id with versioned URL for npm/unpkg CDN
// This allows users to reference specific schema versions
const schemaWithId = {
$id: `https://unpkg.com/opencode-notification@${version}/schema/${CONFIG_FILE_NAME}`,
...jsonSchema,
};
const outputPath = `${import.meta.dir}/../schema/${CONFIG_FILE_NAME}`;
await Bun.write(outputPath, JSON.stringify(schemaWithId, null, 2));
console.log(`Generated JSON schema: schema/${CONFIG_FILE_NAME} (version ${version})`);