From fd6162678174b0f43fa53559695c6fe22784b27d Mon Sep 17 00:00:00 2001 From: Mark Probst Date: Sun, 12 Jul 2026 17:19:15 -0400 Subject: [PATCH] Convert nested-intersection-union unit test to a schema fixture Replace the Vitest unit test (which checked Rust output strings for one language) with a standard JSON Schema fixture exercising the same shape: an allOf nested inside a oneOf inside another oneOf, taken from the issue #2913 repro. The fixture runs against every language in CI, round-trips a positive instance, and expects failure on a malformed union member for languages with the "union" feature. Verified end-to-end locally with schema-golang and schema-typescript; all 22 CI target languages generate successfully from the schema. Co-Authored-By: Claude Fable 5 --- ...ested-intersection-union.1.fail.union.json | 8 +++ .../schema/nested-intersection-union.1.json | 20 ++++++ .../schema/nested-intersection-union.schema | 58 ++++++++++++++++ test/unit/nested-intersection-union.test.ts | 67 ------------------- 4 files changed, 86 insertions(+), 67 deletions(-) create mode 100644 test/inputs/schema/nested-intersection-union.1.fail.union.json create mode 100644 test/inputs/schema/nested-intersection-union.1.json create mode 100644 test/inputs/schema/nested-intersection-union.schema delete mode 100644 test/unit/nested-intersection-union.test.ts diff --git a/test/inputs/schema/nested-intersection-union.1.fail.union.json b/test/inputs/schema/nested-intersection-union.1.fail.union.json new file mode 100644 index 000000000..cedeb3f00 --- /dev/null +++ b/test/inputs/schema/nested-intersection-union.1.fail.union.json @@ -0,0 +1,8 @@ +{ + "input": [ + { + "content": "valid item" + }, + ["this array is not a valid item"] + ] +} diff --git a/test/inputs/schema/nested-intersection-union.1.json b/test/inputs/schema/nested-intersection-union.1.json new file mode 100644 index 000000000..3018c7a10 --- /dev/null +++ b/test/inputs/schema/nested-intersection-union.1.json @@ -0,0 +1,20 @@ +{ + "input": [ + { + "content": "hello", + "id": "item-1", + "output": "42", + "summary": "all fields present" + }, + { + "content": "just a message" + }, + { + "id": "item-2", + "output": "function result" + }, + { + "summary": "just reasoning" + } + ] +} diff --git a/test/inputs/schema/nested-intersection-union.schema b/test/inputs/schema/nested-intersection-union.schema new file mode 100644 index 000000000..0453188e3 --- /dev/null +++ b/test/inputs/schema/nested-intersection-union.schema @@ -0,0 +1,58 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "type": "object", + "additionalProperties": false, + "properties": { + "input": { + "type": "array", + "items": { + "oneOf": [ + { "$ref": "#/definitions/Message" }, + { "$ref": "#/definitions/Item" } + ] + } + } + }, + "required": ["input"], + "definitions": { + "Message": { + "type": "object", + "properties": { + "content": { "type": "string" } + }, + "required": ["content"] + }, + "Item": { + "oneOf": [ + { "$ref": "#/definitions/FunctionOutput" }, + { "$ref": "#/definitions/ReasoningItem" } + ] + }, + "FunctionOutput": { + "allOf": [ + { "$ref": "#/definitions/BaseItem" }, + { + "type": "object", + "properties": { + "output": { "type": "string" } + }, + "required": ["output"] + } + ] + }, + "BaseItem": { + "type": "object", + "properties": { + "id": { "type": "string" } + }, + "required": ["id"] + }, + "ReasoningItem": { + "type": "object", + "properties": { + "summary": { "type": "string" } + }, + "required": ["summary"] + } + } +} diff --git a/test/unit/nested-intersection-union.test.ts b/test/unit/nested-intersection-union.test.ts deleted file mode 100644 index d9c3a4a5f..000000000 --- a/test/unit/nested-intersection-union.test.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { InputData, JSONSchemaInput, quicktype } from "quicktype-core"; -import { describe, expect, test } from "vitest"; - -const schema = JSON.stringify({ - $schema: "http://json-schema.org/draft-07/schema#", - type: "object", - properties: { - input: { - type: "array", - items: { - oneOf: [ - { $ref: "#/definitions/Message" }, - { $ref: "#/definitions/Item" }, - ], - }, - }, - }, - definitions: { - Message: { - type: "object", - properties: { content: { type: "string" } }, - required: ["content"], - }, - Item: { - oneOf: [ - { $ref: "#/definitions/FunctionOutput" }, - { $ref: "#/definitions/ReasoningItem" }, - ], - }, - FunctionOutput: { - allOf: [ - { $ref: "#/definitions/BaseItem" }, - { - type: "object", - properties: { output: { type: "string" } }, - required: ["output"], - }, - ], - }, - BaseItem: { - type: "object", - properties: { id: { type: "string" } }, - required: ["id"], - }, - ReasoningItem: { - type: "object", - properties: { summary: { type: "string" } }, - required: ["summary"], - }, - }, -}); - -describe("nested intersections in unions", () => { - test("flattens an array item union containing an indirect allOf", async () => { - const schemaInput = new JSONSchemaInput(undefined); - await schemaInput.addSource({ name: "TopLevel", schema }); - const inputData = new InputData(); - inputData.addInput(schemaInput); - - const result = await quicktype({ inputData, lang: "rust" }); - const output = result.lines.join("\n"); - - expect(output).toContain("pub struct Item"); - expect(output).toContain("output: Option"); - expect(output).toContain("summary: Option"); - }); -});