fix(plugin): normalize bare schema refs

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
YeonGyu-Kim
2026-05-01 18:55:57 +09:00
parent 9ba676330a
commit 9c4bcebb22
2 changed files with 47 additions and 1 deletions
+13
View File
@@ -47,6 +47,14 @@ function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null && !Array.isArray(value)
}
function normalizeJsonSchemaRef(value: string): string {
if (value.startsWith("#") || value.includes(":") || value.startsWith("/")) {
return value
}
return `#/$defs/${value}`
}
export function sanitizeJsonSchema(value: unknown, depth = 0, isPropertyName = false): unknown {
if (Array.isArray(value)) {
return value.map((item) => sanitizeJsonSchema(item, depth + 1, false))
@@ -67,6 +75,11 @@ export function sanitizeJsonSchema(value: unknown, depth = 0, isPropertyName = f
continue
}
if (!isPropertyName && key === "$ref" && typeof nestedValue === "string") {
sanitized[key] = normalizeJsonSchemaRef(nestedValue)
continue
}
const childIsPropertyName = key === "properties" && !isPropertyName
sanitized[key] = sanitizeJsonSchema(nestedValue, depth + 1, childIsPropertyName)
}