mirror of
https://github.com/aljazceru/opencode.git
synced 2025-12-21 17:54:23 +01:00
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com> Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com> Co-authored-by: rekram1-node <rekram1-node@users.noreply.github.com>
48 lines
1.5 KiB
TypeScript
Executable File
48 lines
1.5 KiB
TypeScript
Executable File
#!/usr/bin/env bun
|
|
|
|
import { z } from "zod"
|
|
import { Config } from "../src/config/config"
|
|
|
|
const file = process.argv[2]
|
|
console.log(file)
|
|
|
|
const result = z.toJSONSchema(Config.Info, {
|
|
io: "input", // Generate input shape (treats optional().default() as not required)
|
|
/**
|
|
* We'll use the `default` values of the field as the only value in `examples`.
|
|
* This will ensure no docs are needed to be read, as the configuration is
|
|
* self-documenting.
|
|
*
|
|
* See https://json-schema.org/draft/2020-12/draft-bhutton-json-schema-validation-00#rfc.section.9.5
|
|
*/
|
|
override(ctx) {
|
|
const schema = ctx.jsonSchema
|
|
|
|
// Preserve strictness: set additionalProperties: false for objects
|
|
if (schema && typeof schema === "object" && schema.type === "object" && schema.additionalProperties === undefined) {
|
|
schema.additionalProperties = false
|
|
}
|
|
|
|
// Add examples and default descriptions for string fields with defaults
|
|
if (schema && typeof schema === "object" && "type" in schema && schema.type === "string" && schema?.default) {
|
|
if (!schema.examples) {
|
|
schema.examples = [schema.default]
|
|
}
|
|
|
|
schema.description = [schema.description || "", `default: \`${schema.default}\``]
|
|
.filter(Boolean)
|
|
.join("\n\n")
|
|
.trim()
|
|
}
|
|
},
|
|
}) as Record<string, unknown> & {
|
|
allowComments?: boolean
|
|
allowTrailingCommas?: boolean
|
|
}
|
|
|
|
// used for json lsps since config supports jsonc
|
|
result.allowComments = true
|
|
result.allowTrailingCommas = true
|
|
|
|
await Bun.write(file, JSON.stringify(result, null, 2))
|