import { describe, expect, it } from "@suaveplan/testing/runner"; import fc from "fast-check"; import { mergeOpenAPIDocuments } from "../src/merger/merger.js"; import type { OpenAPIDocument } from "../src/types/openapi.js"; const operationArb = fc.record({ responses: fc.constant({}), }); const pathItemArb = fc.dictionary( fc.constantFrom("get", "post", "put", "patch", "delete"), operationArb, { minKeys: 1, maxKeys: 3 } ); const pathsArb = fc.dictionary( fc.string({ minLength: 1, maxLength: 10 }).map((s) => `/${s}`), pathItemArb, { minKeys: 0, maxKeys: 5 } ); const docArb = pathsArb.map((paths) => ({ openapi: "3.1.0", info: { title: "T", version: "1.0.0" }, paths, })); describe("mergeOpenAPIDocuments — associativity property", () => { it("merge(a, b, c) === merge(merge(a, b), c) for arbitrary path sets", { timeout: 30000, }, () => { fc.assert( fc.property(docArb, docArb, docArb, (a, b, c) => { const left = mergeOpenAPIDocuments(a, b, c); const right = mergeOpenAPIDocuments( mergeOpenAPIDocuments(a, b), c ); expect(right.paths).toEqual(left.paths); }), { numRuns: 200 } ); }); it("merging with empty extras is idempotent on paths", { timeout: 30000, }, () => { fc.assert( fc.property(docArb, (a) => { const m = mergeOpenAPIDocuments(a, {}, {}, {}); expect(m.paths).toEqual(a.paths); }), { numRuns: 100 } ); }); });