1b4fd9cbae
- Added normalizeMixedSchemaNode() function to recursively convert mixed JTD and JSON Schema definitions into valid JSON Schema. - Changed output schema validation to gracefully fall back to unconstrained JSON objects when schema is invalid instead of throwing errors. - Fixed handling of mixed JTD and JSON Schema output definitions by normalizing them during schema conversion. - Added comprehensive test coverage for JTD-to-JSON Schema conversion and output schema validation edge cases.
73 lines
1.4 KiB
TypeScript
73 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { jtdToJsonSchema } from "@oh-my-pi/pi-coding-agent/tools/jtd-to-json-schema";
|
|
|
|
describe("jtdToJsonSchema", () => {
|
|
it("converts JTD elements and int32 primitives into JSON Schema", () => {
|
|
const converted = jtdToJsonSchema({
|
|
properties: {
|
|
results: {
|
|
elements: {
|
|
properties: {
|
|
issue: { type: "int32" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
expect(converted).toEqual({
|
|
type: "object",
|
|
properties: {
|
|
results: {
|
|
type: "array",
|
|
items: {
|
|
type: "object",
|
|
properties: {
|
|
issue: { type: "integer" },
|
|
},
|
|
required: ["issue"],
|
|
additionalProperties: false,
|
|
},
|
|
},
|
|
},
|
|
required: ["results"],
|
|
additionalProperties: false,
|
|
});
|
|
});
|
|
|
|
it("normalizes nested JTD fragments inside JSON Schema nodes", () => {
|
|
const converted = jtdToJsonSchema({
|
|
type: "object",
|
|
properties: {
|
|
results: {
|
|
type: "array",
|
|
elements: {
|
|
properties: {
|
|
issue: { type: "int32" },
|
|
},
|
|
},
|
|
},
|
|
},
|
|
required: ["results"],
|
|
});
|
|
|
|
expect(converted).toEqual({
|
|
type: "object",
|
|
properties: {
|
|
results: {
|
|
type: "array",
|
|
items: {
|
|
type: "object",
|
|
properties: {
|
|
issue: { type: "integer" },
|
|
},
|
|
required: ["issue"],
|
|
additionalProperties: false,
|
|
},
|
|
},
|
|
},
|
|
required: ["results"],
|
|
});
|
|
});
|
|
});
|