mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-15 12:06:04 +00:00
* fix(schema): resolve large local refs in schema arrays * fix(schema): type large local ref fixture * style(schema): format large local ref regression --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { findJsonSchemaShapeError, normalizeJsonSchemaForTypeBox } from "./json-schema-defaults.js";
|
|
|
|
describe("normalizeJsonSchemaForTypeBox", () => {
|
|
it("combines pattern properties that collide after unicode repair", () => {
|
|
const normalized = normalizeJsonSchemaForTypeBox({
|
|
type: "object",
|
|
patternProperties: {
|
|
"^https:": { minLength: 1 },
|
|
"^https\\:": { maxLength: 10 },
|
|
},
|
|
});
|
|
|
|
expect(normalized).toMatchObject({
|
|
patternProperties: {
|
|
"^https:": {
|
|
allOf: [{ minLength: 1 }, { maxLength: 10 }],
|
|
},
|
|
},
|
|
});
|
|
});
|
|
|
|
it.each(["constructor", "toString", "__proto__"])(
|
|
"preserves pattern property key %s",
|
|
(pattern) => {
|
|
const normalized = normalizeJsonSchemaForTypeBox({
|
|
type: "object",
|
|
patternProperties: Object.fromEntries([[pattern, { type: "string" }]]),
|
|
});
|
|
|
|
expect(normalized).toMatchObject({
|
|
patternProperties: Object.fromEntries([[pattern, { type: "string" }]]),
|
|
});
|
|
},
|
|
);
|
|
|
|
it("resolves local refs to array entries beyond config path index limits", () => {
|
|
const prefixItems: (boolean | { type: string })[] = Array.from({ length: 100_002 }, () => true);
|
|
prefixItems[100_001] = { type: "string" };
|
|
|
|
expect(
|
|
findJsonSchemaShapeError({
|
|
type: "array",
|
|
prefixItems,
|
|
items: { $ref: "#/prefixItems/100001" },
|
|
}),
|
|
).toBeUndefined();
|
|
});
|
|
});
|