import { describe, it } from "@std/testing/bdd"; import { expect } from "@std/expect"; import { createSchemaTransformerV2 } from "../../src/plugin.ts"; import { asObjectSchema, getTypeFromCode } from "../utils.ts"; describe("Schema: Default does not mutate shared definitions", () => { it("two props using same named type with different defaults", async () => { const code = ` interface Default {} interface Address { city: string } interface X { a: Default; b: Default; } `; const { type, checker } = await getTypeFromCode(code, "X"); const gen = createSchemaTransformerV2(); const s = asObjectSchema(gen.generateSchema(type, checker)); const a = s.properties?.a as any; const b = s.properties?.b as any; expect(a.default?.city).toBe("NY"); expect(b.default?.city).toBe("SF"); // If a definition for Address exists, it should not carry a default const defs = (s as any).$defs as Record | undefined; const address = defs?.["Address"] as any | undefined; if (address) { expect(address.default).toBeUndefined(); } }); });