Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
TypeScript agentic-aiagentsaiai-agentsaiagentsdeveloper-toolsfunction-callinggpt-4javascriptjsllmllmopsmcppythonremote-mcp-serverssetypescript
fix(json-schema): accept and preserve dynamic object content across converters
jkomyno5e57815af16e
diff --git a/.changeset/fix-property-less-object-conversion.md b/.changeset/fix-property-less-object-conversion.mdnew file mode 100644index 000000000..e986cb6f0--- /dev/null+++ b/.changeset/fix-property-less-object-conversion.md@@ -0,0 +1,5 @@+---+'@composio/json-schema-to-zod': patch+---++Accept and preserve arbitrary content in property-less objects (`{ type: "object" }` or `properties: {}`) at root, nested, and array-item positions, instead of collapsing them to a strict empty object. Dynamic keys are also routed correctly: every matching `patternProperties` entry validates its key, and a schema-valued `additionalProperties` applies only to keys no property or pattern claims.diff --git a/.changeset/preserve-root-dynamic-key-constraints.md b/.changeset/preserve-root-dynamic-key-constraints.mdnew file mode 100644index 000000000..1317a1809--- /dev/null+++ b/.changeset/preserve-root-dynamic-key-constraints.md@@ -0,0 +1,5 @@+---+'@composio/core': patch+---++Preserve root `patternProperties` and boolean- or schema-valued `additionalProperties` when parsing tool parameters. `ToolSchema.parse` previously stripped `patternProperties` as an unknown key and rejected a schema-valued `additionalProperties` outright, so both dynamic-key constraints were lost before any converter could see them.diff --git a/.github/workflows/py.test.yml b/.github/workflows/py.test.ymlindex 3bfdaf325..ad4c8c0df 100644--- a/.github/workflows/py.test.yml+++ b/.github/workflows/py.test.yml@@ -5,6 +5,7 @@ on:branches: [master, next]paths:- 'python/**/*.py'+ - 'python/**/*.json'- '.github/workflows/py.test.yml'- '.github/actions/setup-python-uv/action.yml'- 'mise.toml'@@ -16,6 +17,7 @@ on:branches: [master, next]paths:- 'python/**/*.py'+ - 'python/**/*.json'- '.github/workflows/py.test.yml'- '.github/actions/setup-python-uv/action.yml'- 'mise.toml'diff --git a/python/tests/conftest.py b/python/tests/conftest.pyindex 3abdc7dab..7bcc7cdcf 100644--- a/python/tests/conftest.py+++ b/python/tests/conftest.py@@ -30,6 +30,24 @@ def get_ts_fixtures_dir() -> Path:)+def get_py_json_schema_corpus_dir() -> Path:+ """Get the Python JSON Schema conversion corpus directory path."""+ return Path(__file__).parent / "fixtures" / "json-schema-conversion"+++def get_ts_json_schema_corpus_dir() -> Path:+ """Get the TypeScript JSON Schema conversion corpus directory path."""+ return (+ Path(__file__).parent.parent.parent+ / "ts"+ / "packages"+ / "core"+ / "test"+ / "fixtures"+ / "json-schema-conversion"+ )++def compute_signature(webhook_id: str, timestamp: str, payload: str, secret: str) -> str:diff --git a/python/tests/fixtures/json-schema-conversion/object-cases.json b/python/tests/fixtures/json-schema-conversion/object-cases.jsonnew file mode 100644index 000000000..82f06ecd7--- /dev/null+++ b/python/tests/fixtures/json-schema-conversion/object-cases.json@@ -0,0 +1,422 @@+{+ "cases": [+ {+ "id": "nested-free-form-object",+ "description": "A nested `{ type: \"object\" }` property must accept and preserve arbitrary content (issue #4064, METABASE_POST_API_CARD.dataset_query).",+ "schema": {+ "type": "object",+ "properties": { "dataset_query": { "type": "object" } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "dataset_query": { "type": "object" } }+ }+ },+ "instances": [+ {+ "input": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } },+ "accepted": true,+ "zod": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ },+ "effect": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ },+ "python": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ }+ }+ ]+ },+ {+ "id": "root-free-form-absent-properties",+ "description": "A root object with no `properties` member and omitted `additionalProperties` is open.",+ "schema": { "type": "object" },+ "instances": [+ {+ "input": { "anything": { "a": 1 }, "other": "x" },+ "accepted": true,+ "zod": { "output": { "anything": { "a": 1 }, "other": "x" } },+ "effect": { "output": { "anything": { "a": 1 }, "other": "x" } },+ "python": { "output": { "anything": { "a": 1 }, "other": "x" } }+ }+ ]+ },+ {+ "id": "root-free-form-empty-properties",+ "description": "`properties: {}` is property-less too, and stays open when `additionalProperties` is omitted.",+ "schema": { "type": "object", "properties": {} },+ "ingress": {+ "accepted": true,+ "preserved": { "type": "object", "properties": {} }+ },+ "instances": [+ {+ "input": { "foo": 1, "bar": { "baz": true } },+ "accepted": true,+ "zod": { "output": { "foo": 1, "bar": { "baz": true } } },+ "effect": { "output": { "foo": 1, "bar": { "baz": true } } },+ "python": { "output": { "foo": 1, "bar": { "baz": true } } }+ }+ ]+ },+ {+ "id": "free-form-object-in-array-items",+ "description": "Property-less objects placed as array items preserve arbitrary content.",+ "schema": {+ "type": "object",+ "properties": {+ "records": { "type": "array", "items": { "type": "object" } }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": {+ "records": { "type": "array", "items": { "type": "object" } }+ }+ }+ },+ "instances": [+ {+ "input": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] },+ "accepted": true,+ "zod": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } },+ "effect": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } },+ "python": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } }+ }+ ]+ },+ {+ "id": "explicit-additional-properties-false",+ "description": "An explicit `additionalProperties: false` closes an otherwise property-less object.",+ "schema": { "type": "object", "properties": {}, "additionalProperties": false },+ "ingress": {+ "accepted": true,+ "preserved": { "type": "object", "properties": {}, "additionalProperties": false }+ },+ "instances": [+ {+ "input": {},+ "accepted": true,+ "zod": { "output": {} },+ "effect": { "output": {} },+ "python": { "output": {} }+ },+ {+ "input": { "foo": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "explicit-additional-properties-true",+ "description": "An explicit `additionalProperties: true` preserves unknown keys alongside named properties.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": true+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": true+ }+ },+ "instances": [+ {+ "input": { "name": "a", "extra": 1 },+ "accepted": true,+ "zod": { "output": { "name": "a", "extra": 1 } },+ "effect": { "output": { "name": "a", "extra": 1 } },+ "python": { "output": { "name": "a", "extra": 1 } }+ }+ ]+ },+ {+ "id": "named-properties-strict-by-default",+ "description": "Composio divergence: named `properties` with omitted `additionalProperties` stay strict for tool inputs, while JSON Schema itself would allow unknown keys.",+ "divergesFromJsonSchema": "JSON Schema treats omitted `additionalProperties` as permissive; Composio tool inputs keep it strict.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "required": ["name"]+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "required": ["name"]+ }+ },+ "instances": [+ {+ "input": { "name": "a" },+ "accepted": true,+ "zod": { "output": { "name": "a" } },+ "effect": { "output": { "name": "a" } },+ "python": { "output": { "name": "a" } }+ },+ {+ "input": { "name": "a", "extra": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "named-properties-with-pattern-properties",+ "description": "With named `properties` plus `patternProperties` and omitted `additionalProperties`, pattern-matching keys are admitted and validated while other unknown keys stay rejected.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^x-": { "type": "number" } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^x-": { "type": "number" } }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "x-count": 3 },+ "accepted": true,+ "zod": { "output": { "name": "a", "x-count": 3 } },+ "effect": { "output": { "name": "a", "x-count": 3 } },+ "python": { "output": { "name": "a", "x-count": 3 } }+ },+ {+ "input": { "name": "a", "x-count": "nope" },+ "accepted": false+ },+ {+ "input": { "name": "a", "other": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "root-additional-properties-schema-valued",+ "description": "A schema-valued root `additionalProperties` survives `ToolSchema.parse` and validates unknown keys.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": { "type": "number" }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": { "type": "number" }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "count": 2 },+ "accepted": true,+ "zod": { "output": { "name": "a", "count": 2 } },+ "effect": { "output": { "name": "a", "count": 2 } },+ "python": { "output": { "name": "a", "count": 2 } }+ },+ {+ "input": { "name": "a", "count": "x" },+ "accepted": false+ }+ ]+ },+ {+ "id": "pattern-only-object",+ "description": "A pattern-only object with no named `properties` accepts unmatched keys while still validating matched ones.",+ "schema": {+ "type": "object",+ "patternProperties": { "^s_": { "type": "string" } }+ },+ "instances": [+ {+ "input": { "s_a": "x", "other": 1 },+ "accepted": true,+ "zod": { "output": { "s_a": "x", "other": 1 } },+ "effect": { "output": { "s_a": "x", "other": 1 } },+ "python": { "output": { "s_a": "x", "other": 1 } }+ },+ {+ "input": { "s_a": 5 },+ "accepted": false+ }+ ]+ },+ {+ "id": "multiple-matching-patterns",+ "description": "A key matching several non-transforming patterns must satisfy all of them.",+ "schema": {+ "type": "object",+ "patternProperties": {+ "^a": { "type": "string" },+ "b$": { "type": "string", "minLength": 2 }+ }+ },+ "instances": [+ {+ "input": { "ab": "xy" },+ "accepted": true,+ "zod": { "output": { "ab": "xy" } },+ "effect": { "output": { "ab": "xy" } },+ "python": { "output": { "ab": "xy" } }+ },+ {+ "input": { "ab": "x" },+ "accepted": false+ },+ {+ "input": { "ab": 5 },+ "accepted": false+ }+ ]+ },+ {+ "id": "declared-property-also-matching-a-pattern",+ "description": "A key declared in `properties` is still checked against every matching pattern.",+ "schema": {+ "type": "object",+ "properties": { "x_id": { "type": "string" } },+ "patternProperties": { "^x_": { "type": "string", "minLength": 3 } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "x_id": { "type": "string" } },+ "patternProperties": { "^x_": { "type": "string", "minLength": 3 } }+ }+ },+ "instances": [+ {+ "input": { "x_id": "abc" },+ "accepted": true,+ "zod": { "output": { "x_id": "abc" } },+ "effect": { "output": { "x_id": "abc" } },+ "python": { "output": { "x_id": "abc" } }+ },+ {+ "input": { "x_id": "ab" },+ "accepted": false+ }+ ]+ },+ {+ "id": "schema-valued-additional-applies-only-to-unmatched-keys",+ "description": "Schema-valued `additionalProperties` must not rescue a key that a `patternProperties` entry already claims and rejects.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^n_": { "type": "number" } },+ "additionalProperties": { "type": "boolean" }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^n_": { "type": "number" } },+ "additionalProperties": { "type": "boolean" }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "n_x": 1, "flag": true },+ "accepted": true,+ "zod": { "output": { "name": "a", "n_x": 1, "flag": true } },+ "effect": { "output": { "name": "a", "n_x": 1, "flag": true } },+ "python": { "output": { "name": "a", "n_x": 1, "flag": true } }+ },+ {+ "input": { "name": "a", "n_x": true },+ "accepted": false+ },+ {+ "input": { "name": "a", "flag": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "pattern-property-default-materialization",+ "description": "Composio divergence: Zod and Pydantic materialize `default` inside a matching pattern schema, while Effect decoding is validation-only and returns the input unchanged.",+ "divergesFromJsonSchema": "`default` is annotation-only in JSON Schema; the Zod and Pydantic converters materialize it.",+ "schema": {+ "type": "object",+ "properties": {},+ "patternProperties": {+ "^p_": {+ "type": "object",+ "properties": { "mode": { "type": "string", "default": "auto" } }+ }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": {},+ "patternProperties": {+ "^p_": {+ "type": "object",+ "properties": { "mode": { "type": "string", "default": "auto" } }+ }+ }+ }+ },+ "instances": [+ {+ "input": { "p_a": {} },+ "accepted": true,+ "zod": { "output": { "p_a": { "mode": "auto" } } },+ "effect": { "output": { "p_a": {} } },+ "python": { "output": { "p_a": { "mode": "auto" } } }+ }+ ]+ },+ {+ "id": "additional-property-default-materialization",+ "description": "Composio divergence: a schema-valued `additionalProperties` also materializes defaults in Zod and Pydantic while Effect leaves the input unchanged.",+ "divergesFromJsonSchema": "`default` is annotation-only in JSON Schema; the Zod and Pydantic converters materialize it.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": {+ "type": "object",+ "properties": { "enabled": { "type": "boolean", "default": false } }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": {+ "type": "object",+ "properties": { "enabled": { "type": "boolean", "default": false } }+ }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "extra": {} },+ "accepted": true,+ "zod": { "output": { "name": "a", "extra": { "enabled": false } } },+ "effect": { "output": { "name": "a", "extra": {} } },+ "python": { "output": { "name": "a", "extra": { "enabled": false } } }+ }+ ]+ }+ ]+}diff --git a/python/tests/test_cross_sdk_compatibility.py b/python/tests/test_cross_sdk_compatibility.pyindex 83dcd0b60..0dce09222 100644--- a/python/tests/test_cross_sdk_compatibility.py+++ b/python/tests/test_cross_sdk_compatibility.py@@ -9,7 +9,12 @@ import jsonimport pytest-from tests.conftest import get_py_fixtures_dir, get_ts_fixtures_dir+from tests.conftest import (+ get_py_fixtures_dir,+ get_py_json_schema_corpus_dir,+ get_ts_fixtures_dir,+ get_ts_json_schema_corpus_dir,+)class TestCrossSDKFixtureCompatibility:@@ -38,3 +43,13 @@ class TestCrossSDKFixtureCompatibility:f"Fixture {fixture_name} differs between TypeScript and Python SDKs. ""Ensure fixtures are kept in sync.")++ def test_json_schema_conversion_corpus_is_identical(self) -> None:+ """The shared JSON Schema conversion corpus has one copy per language."""+ ts_path = get_ts_json_schema_corpus_dir() / "object-cases.json"+ py_path = get_py_json_schema_corpus_dir() / "object-cases.json"++ assert ts_path.read_bytes() == py_path.read_bytes(), (+ "object-cases.json differs between the TypeScript and Python SDKs. "+ "Both copies must stay byte-identical."+ )diff --git a/ts/packages/cli/test/fixtures/corpus.ts b/ts/packages/cli/test/fixtures/corpus.tsnew file mode 100644index 000000000..2dfbe552d--- /dev/null+++ b/ts/packages/cli/test/fixtures/corpus.ts@@ -0,0 +1,85 @@+/**+ * Loader for the shared cross-SDK JSON Schema conversion corpus.+ *+ * The corpus is a single logical fixture with one byte-identical copy per+ * language (`ts/packages/core/test/fixtures/json-schema-conversion/` and+ * `python/tests/fixtures/json-schema-conversion/`), following the same+ * convention as the webhook fixtures. Every consumer resolves its own copy+ * module-relatively — no working-directory or repository-root assumptions.+ */+import * as z from 'zod';++import objectCases from '../../../core/test/fixtures/json-schema-conversion/object-cases.json';++const JsonObject = z.record(z.string(), z.unknown());++const LanguageExpectation = z.object({+ output: z.unknown().optional(),+ accepted: z.boolean().optional(),+});++const CorpusInstance = z.object({+ input: JsonObject,+ accepted: z.boolean(),+ zod: LanguageExpectation.optional(),+ effect: LanguageExpectation.optional(),+ python: LanguageExpectation.optional(),+ divergence: z.object({ reason: z.string().min(1) }).optional(),+});++const CorpusCase = z.object({+ id: z.string().min(1),+ description: z.string().optional(),+ divergesFromJsonSchema: z.string().optional(),+ schema: JsonObject,+ ingress: z.object({ accepted: z.boolean(), preserved: JsonObject }).optional(),+ instances: z.array(CorpusInstance).min(1),+});++const Corpus = z.object({ cases: z.array(CorpusCase).min(1) });++export type CorpusInstance = z.infer<typeof CorpusInstance>;+export type CorpusCase = z.infer<typeof CorpusCase>;+export type CorpusLanguage = 'zod' | 'effect' | 'python';++/**+ * Enforce the invariants that keep the corpus a shared contract rather than a+ * per-language wish list: ids are unique, and a language may only disagree about+ * acceptance when the instance declares why.+ */+export const assertCorpusInvariants = (cases: ReadonlyArray<CorpusCase>): void => {+ const seen = new Set<string>();+ for (const testCase of cases) {+ if (seen.has(testCase.id)) {+ throw new Error(`Duplicate corpus case id: ${testCase.id}`);+ }+ seen.add(testCase.id);++ for (const [index, instance] of testCase.instances.entries()) {+ for (const language of ['zod', 'effect', 'python'] as const) {+ const override = instance[language]?.accepted;+ if (override !== undefined && override !== instance.accepted && !instance.divergence) {+ throw new Error(+ `Corpus case ${testCase.id} instance ${index} overrides ${language} acceptance without a divergence reason`+ );+ }+ }+ }+ }+};++let cached: ReadonlyArray<CorpusCase> | undefined;++/** Decode the shared corpus and enforce its cross-language invariants. */+export const loadObjectCases = (): ReadonlyArray<CorpusCase> => {+ if (!cached) {+ const { cases } = Corpus.parse(objectCases);+ assertCorpusInvariants(cases);+ cached = cases;+ }+ return cached;+};++/** Acceptance for one language: the shared flag unless a declared divergence overrides it. */+export const acceptedFor = (instance: CorpusInstance, language: CorpusLanguage): boolean =>+ instance[language]?.accepted ?? instance.accepted;diff --git a/ts/packages/cli/test/src/services/tool-input-validation.test.ts b/ts/packages/cli/test/src/services/tool-input-validation.test.tsindex fbb2b540f..8c7a5f0ff 100644--- a/ts/packages/cli/test/src/services/tool-input-validation.test.ts+++ b/ts/packages/cli/test/src/services/tool-input-validation.test.ts@@ -10,6 +10,7 @@ import {validateToolInputArgumentsWithDefinition,} from 'src/services/tool-input-validation';import { defaultNodeOs, NodeOs } from 'src/services/node-os';+import { loadObjectCases } from '../../fixtures/corpus';const definition = {schemaPath: '/tmp/GMAIL_SEND_EMAIL.json',@@ -162,3 +163,39 @@ describe('tool input validation', () => {}));});++describe('free-form object tool inputs', () => {+ const freeFormCase = loadObjectCases().find(entry => entry.id === 'nested-free-form-object');+ if (!freeFormCase) {+ throw new Error('Corpus is missing the nested-free-form-object case');+ }++ const freeFormDefinition = {+ schemaPath: '/tmp/METABASE_POST_API_CARD.json',+ schema: freeFormCase.schema,+ } as const;++ it.effect('accepts arbitrary content inside a property-less object', () =>+ Effect.gen(function* () {+ const result = yield* validateToolInputArgumentsWithDefinition(+ 'METABASE_POST_API_CARD',+ freeFormCase.instances[0].input,+ freeFormDefinition+ );++ expect(result).toEqual(freeFormDefinition);+ })+ );++ it.effect('still reports unknown keys for named-property schemas', () =>+ Effect.gen(function* () {+ const error = yield* validateToolInputArgumentsWithDefinition(+ 'GMAIL_SEND_EMAIL',+ { recipient_email: '[email protected]', nope: 1 },+ definition+ ).pipe(Effect.flip);++ expect(error).toBeInstanceOf(ToolInputValidationError);+ })+ );+});diff --git a/ts/packages/core/src/types/tool.types.ts b/ts/packages/core/src/types/tool.types.tsindex 20fbe2d85..c418c94c3 100644--- a/ts/packages/core/src/types/tool.types.ts+++ b/ts/packages/core/src/types/tool.types.ts@@ -145,7 +145,13 @@ const ParametersSchema = z.preprocess(default: z.unknown().optional(),nullable: z.boolean().optional(),description: z.string().optional(),- additionalProperties: z.boolean().default(false).optional(),+ // Dynamic-key constraints the Composio API ships at the parameters root.+ // Both were previously lost on parse: `patternProperties` was stripped as an+ // unknown key, and a schema-valued `additionalProperties` was rejected+ // outright by the boolean-only schema. Omission still stays omission —+ // downstream converters, not the parser, decide the implicit policy.+ patternProperties: z.record(z.string(), JSONSchemaPropertySchema).optional(),+ additionalProperties: z.union([z.boolean(), JSONSchemaPropertySchema]).optional(),// Definition blocks targeted by `$ref` pointers. The Composio API ships// these at the parameters root (e.g. `data` → `$ref` → `#/$defs/...`), but// because `z.object` strips unknown keys they were being dropped on parse —diff --git a/ts/packages/core/test/fixtures/json-schema-conversion/corpus.ts b/ts/packages/core/test/fixtures/json-schema-conversion/corpus.tsnew file mode 100644index 000000000..dbc368701--- /dev/null+++ b/ts/packages/core/test/fixtures/json-schema-conversion/corpus.ts@@ -0,0 +1,85 @@+/**+ * Loader for the shared cross-SDK JSON Schema conversion corpus.+ *+ * The corpus is a single logical fixture with one byte-identical copy per+ * language (`ts/packages/core/test/fixtures/json-schema-conversion/` and+ * `python/tests/fixtures/json-schema-conversion/`), following the same+ * convention as the webhook fixtures. Every consumer resolves its own copy+ * module-relatively — no working-directory or repository-root assumptions.+ */+import * as z from 'zod';++import objectCases from './object-cases.json';++const JsonObject = z.record(z.string(), z.unknown());++const LanguageExpectation = z.object({+ output: z.unknown().optional(),+ accepted: z.boolean().optional(),+});++const CorpusInstance = z.object({+ input: JsonObject,+ accepted: z.boolean(),+ zod: LanguageExpectation.optional(),+ effect: LanguageExpectation.optional(),+ python: LanguageExpectation.optional(),+ divergence: z.object({ reason: z.string().min(1) }).optional(),+});++const CorpusCase = z.object({+ id: z.string().min(1),+ description: z.string().optional(),+ divergesFromJsonSchema: z.string().optional(),+ schema: JsonObject,+ ingress: z.object({ accepted: z.boolean(), preserved: JsonObject }).optional(),+ instances: z.array(CorpusInstance).min(1),+});++const Corpus = z.object({ cases: z.array(CorpusCase).min(1) });++export type CorpusInstance = z.infer<typeof CorpusInstance>;+export type CorpusCase = z.infer<typeof CorpusCase>;+export type CorpusLanguage = 'zod' | 'effect' | 'python';++/**+ * Enforce the invariants that keep the corpus a shared contract rather than a+ * per-language wish list: ids are unique, and a language may only disagree about+ * acceptance when the instance declares why.+ */+export const assertCorpusInvariants = (cases: ReadonlyArray<CorpusCase>): void => {+ const seen = new Set<string>();+ for (const testCase of cases) {+ if (seen.has(testCase.id)) {+ throw new Error(`Duplicate corpus case id: ${testCase.id}`);+ }+ seen.add(testCase.id);++ for (const [index, instance] of testCase.instances.entries()) {+ for (const language of ['zod', 'effect', 'python'] as const) {+ const override = instance[language]?.accepted;+ if (override !== undefined && override !== instance.accepted && !instance.divergence) {+ throw new Error(+ `Corpus case ${testCase.id} instance ${index} overrides ${language} acceptance without a divergence reason`+ );+ }+ }+ }+ }+};++let cached: ReadonlyArray<CorpusCase> | undefined;++/** Decode the shared corpus and enforce its cross-language invariants. */+export const loadObjectCases = (): ReadonlyArray<CorpusCase> => {+ if (!cached) {+ const { cases } = Corpus.parse(objectCases);+ assertCorpusInvariants(cases);+ cached = cases;+ }+ return cached;+};++/** Acceptance for one language: the shared flag unless a declared divergence overrides it. */+export const acceptedFor = (instance: CorpusInstance, language: CorpusLanguage): boolean =>+ instance[language]?.accepted ?? instance.accepted;diff --git a/ts/packages/core/test/fixtures/json-schema-conversion/object-cases.json b/ts/packages/core/test/fixtures/json-schema-conversion/object-cases.jsonnew file mode 100644index 000000000..82f06ecd7--- /dev/null+++ b/ts/packages/core/test/fixtures/json-schema-conversion/object-cases.json@@ -0,0 +1,422 @@+{+ "cases": [+ {+ "id": "nested-free-form-object",+ "description": "A nested `{ type: \"object\" }` property must accept and preserve arbitrary content (issue #4064, METABASE_POST_API_CARD.dataset_query).",+ "schema": {+ "type": "object",+ "properties": { "dataset_query": { "type": "object" } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "dataset_query": { "type": "object" } }+ }+ },+ "instances": [+ {+ "input": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } },+ "accepted": true,+ "zod": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ },+ "effect": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ },+ "python": {+ "output": { "dataset_query": { "database": 1, "query": { "source-table": 2 } } }+ }+ }+ ]+ },+ {+ "id": "root-free-form-absent-properties",+ "description": "A root object with no `properties` member and omitted `additionalProperties` is open.",+ "schema": { "type": "object" },+ "instances": [+ {+ "input": { "anything": { "a": 1 }, "other": "x" },+ "accepted": true,+ "zod": { "output": { "anything": { "a": 1 }, "other": "x" } },+ "effect": { "output": { "anything": { "a": 1 }, "other": "x" } },+ "python": { "output": { "anything": { "a": 1 }, "other": "x" } }+ }+ ]+ },+ {+ "id": "root-free-form-empty-properties",+ "description": "`properties: {}` is property-less too, and stays open when `additionalProperties` is omitted.",+ "schema": { "type": "object", "properties": {} },+ "ingress": {+ "accepted": true,+ "preserved": { "type": "object", "properties": {} }+ },+ "instances": [+ {+ "input": { "foo": 1, "bar": { "baz": true } },+ "accepted": true,+ "zod": { "output": { "foo": 1, "bar": { "baz": true } } },+ "effect": { "output": { "foo": 1, "bar": { "baz": true } } },+ "python": { "output": { "foo": 1, "bar": { "baz": true } } }+ }+ ]+ },+ {+ "id": "free-form-object-in-array-items",+ "description": "Property-less objects placed as array items preserve arbitrary content.",+ "schema": {+ "type": "object",+ "properties": {+ "records": { "type": "array", "items": { "type": "object" } }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": {+ "records": { "type": "array", "items": { "type": "object" } }+ }+ }+ },+ "instances": [+ {+ "input": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] },+ "accepted": true,+ "zod": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } },+ "effect": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } },+ "python": { "output": { "records": [{ "a": 1 }, { "b": { "c": 2 } }] } }+ }+ ]+ },+ {+ "id": "explicit-additional-properties-false",+ "description": "An explicit `additionalProperties: false` closes an otherwise property-less object.",+ "schema": { "type": "object", "properties": {}, "additionalProperties": false },+ "ingress": {+ "accepted": true,+ "preserved": { "type": "object", "properties": {}, "additionalProperties": false }+ },+ "instances": [+ {+ "input": {},+ "accepted": true,+ "zod": { "output": {} },+ "effect": { "output": {} },+ "python": { "output": {} }+ },+ {+ "input": { "foo": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "explicit-additional-properties-true",+ "description": "An explicit `additionalProperties: true` preserves unknown keys alongside named properties.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": true+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": true+ }+ },+ "instances": [+ {+ "input": { "name": "a", "extra": 1 },+ "accepted": true,+ "zod": { "output": { "name": "a", "extra": 1 } },+ "effect": { "output": { "name": "a", "extra": 1 } },+ "python": { "output": { "name": "a", "extra": 1 } }+ }+ ]+ },+ {+ "id": "named-properties-strict-by-default",+ "description": "Composio divergence: named `properties` with omitted `additionalProperties` stay strict for tool inputs, while JSON Schema itself would allow unknown keys.",+ "divergesFromJsonSchema": "JSON Schema treats omitted `additionalProperties` as permissive; Composio tool inputs keep it strict.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "required": ["name"]+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "required": ["name"]+ }+ },+ "instances": [+ {+ "input": { "name": "a" },+ "accepted": true,+ "zod": { "output": { "name": "a" } },+ "effect": { "output": { "name": "a" } },+ "python": { "output": { "name": "a" } }+ },+ {+ "input": { "name": "a", "extra": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "named-properties-with-pattern-properties",+ "description": "With named `properties` plus `patternProperties` and omitted `additionalProperties`, pattern-matching keys are admitted and validated while other unknown keys stay rejected.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^x-": { "type": "number" } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^x-": { "type": "number" } }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "x-count": 3 },+ "accepted": true,+ "zod": { "output": { "name": "a", "x-count": 3 } },+ "effect": { "output": { "name": "a", "x-count": 3 } },+ "python": { "output": { "name": "a", "x-count": 3 } }+ },+ {+ "input": { "name": "a", "x-count": "nope" },+ "accepted": false+ },+ {+ "input": { "name": "a", "other": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "root-additional-properties-schema-valued",+ "description": "A schema-valued root `additionalProperties` survives `ToolSchema.parse` and validates unknown keys.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": { "type": "number" }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": { "type": "number" }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "count": 2 },+ "accepted": true,+ "zod": { "output": { "name": "a", "count": 2 } },+ "effect": { "output": { "name": "a", "count": 2 } },+ "python": { "output": { "name": "a", "count": 2 } }+ },+ {+ "input": { "name": "a", "count": "x" },+ "accepted": false+ }+ ]+ },+ {+ "id": "pattern-only-object",+ "description": "A pattern-only object with no named `properties` accepts unmatched keys while still validating matched ones.",+ "schema": {+ "type": "object",+ "patternProperties": { "^s_": { "type": "string" } }+ },+ "instances": [+ {+ "input": { "s_a": "x", "other": 1 },+ "accepted": true,+ "zod": { "output": { "s_a": "x", "other": 1 } },+ "effect": { "output": { "s_a": "x", "other": 1 } },+ "python": { "output": { "s_a": "x", "other": 1 } }+ },+ {+ "input": { "s_a": 5 },+ "accepted": false+ }+ ]+ },+ {+ "id": "multiple-matching-patterns",+ "description": "A key matching several non-transforming patterns must satisfy all of them.",+ "schema": {+ "type": "object",+ "patternProperties": {+ "^a": { "type": "string" },+ "b$": { "type": "string", "minLength": 2 }+ }+ },+ "instances": [+ {+ "input": { "ab": "xy" },+ "accepted": true,+ "zod": { "output": { "ab": "xy" } },+ "effect": { "output": { "ab": "xy" } },+ "python": { "output": { "ab": "xy" } }+ },+ {+ "input": { "ab": "x" },+ "accepted": false+ },+ {+ "input": { "ab": 5 },+ "accepted": false+ }+ ]+ },+ {+ "id": "declared-property-also-matching-a-pattern",+ "description": "A key declared in `properties` is still checked against every matching pattern.",+ "schema": {+ "type": "object",+ "properties": { "x_id": { "type": "string" } },+ "patternProperties": { "^x_": { "type": "string", "minLength": 3 } }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "x_id": { "type": "string" } },+ "patternProperties": { "^x_": { "type": "string", "minLength": 3 } }+ }+ },+ "instances": [+ {+ "input": { "x_id": "abc" },+ "accepted": true,+ "zod": { "output": { "x_id": "abc" } },+ "effect": { "output": { "x_id": "abc" } },+ "python": { "output": { "x_id": "abc" } }+ },+ {+ "input": { "x_id": "ab" },+ "accepted": false+ }+ ]+ },+ {+ "id": "schema-valued-additional-applies-only-to-unmatched-keys",+ "description": "Schema-valued `additionalProperties` must not rescue a key that a `patternProperties` entry already claims and rejects.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^n_": { "type": "number" } },+ "additionalProperties": { "type": "boolean" }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "patternProperties": { "^n_": { "type": "number" } },+ "additionalProperties": { "type": "boolean" }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "n_x": 1, "flag": true },+ "accepted": true,+ "zod": { "output": { "name": "a", "n_x": 1, "flag": true } },+ "effect": { "output": { "name": "a", "n_x": 1, "flag": true } },+ "python": { "output": { "name": "a", "n_x": 1, "flag": true } }+ },+ {+ "input": { "name": "a", "n_x": true },+ "accepted": false+ },+ {+ "input": { "name": "a", "flag": 1 },+ "accepted": false+ }+ ]+ },+ {+ "id": "pattern-property-default-materialization",+ "description": "Composio divergence: Zod and Pydantic materialize `default` inside a matching pattern schema, while Effect decoding is validation-only and returns the input unchanged.",+ "divergesFromJsonSchema": "`default` is annotation-only in JSON Schema; the Zod and Pydantic converters materialize it.",+ "schema": {+ "type": "object",+ "properties": {},+ "patternProperties": {+ "^p_": {+ "type": "object",+ "properties": { "mode": { "type": "string", "default": "auto" } }+ }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": {},+ "patternProperties": {+ "^p_": {+ "type": "object",+ "properties": { "mode": { "type": "string", "default": "auto" } }+ }+ }+ }+ },+ "instances": [+ {+ "input": { "p_a": {} },+ "accepted": true,+ "zod": { "output": { "p_a": { "mode": "auto" } } },+ "effect": { "output": { "p_a": {} } },+ "python": { "output": { "p_a": { "mode": "auto" } } }+ }+ ]+ },+ {+ "id": "additional-property-default-materialization",+ "description": "Composio divergence: a schema-valued `additionalProperties` also materializes defaults in Zod and Pydantic while Effect leaves the input unchanged.",+ "divergesFromJsonSchema": "`default` is annotation-only in JSON Schema; the Zod and Pydantic converters materialize it.",+ "schema": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": {+ "type": "object",+ "properties": { "enabled": { "type": "boolean", "default": false } }+ }+ },+ "ingress": {+ "accepted": true,+ "preserved": {+ "type": "object",+ "properties": { "name": { "type": "string" } },+ "additionalProperties": {+ "type": "object",+ "properties": { "enabled": { "type": "boolean", "default": false } }+ }+ }+ },+ "instances": [+ {+ "input": { "name": "a", "extra": {} },+ "accepted": true,+ "zod": { "output": { "name": "a", "extra": { "enabled": false } } },+ "effect": { "output": { "name": "a", "extra": {} } },+ "python": { "output": { "name": "a", "extra": { "enabled": false } } }+ }+ ]+ }+ ]+}diff --git a/ts/packages/core/test/utils/jsonSchema.test.ts b/ts/packages/core/test/utils/jsonSchema.test.tsindex 76d593efc..438e864ef 100644--- a/ts/packages/core/test/utils/jsonSchema.test.ts+++ b/ts/packages/core/test/utils/jsonSchema.test.ts@@ -6,6 +6,11 @@ import {import { JsonSchemaRefResolutionError } from '../../src/errors/ValidationErrors';import logger from '../../src/utils/logger';import { ToolSchema } from '../../src/types/tool.types';+import {+ assertCorpusInvariants,+ loadObjectCases,+ type CorpusCase,+} from '../fixtures/json-schema-conversion/corpus';const containsRef = (value: unknown): boolean => {if (value === null || typeof value !== 'object') return false;@@ -594,3 +599,82 @@ describe('deduplicateJsonSchemaRequiredArrays', () => {expect(tool.inputParameters?.properties.options.required).toEqual(['enabled']);});});++describe('ToolSchema parameter-root preservation', () => {+ for (const testCase of loadObjectCases()) {+ const { ingress } = testCase;+ if (!ingress) {+ continue;+ }++ it(`preserves the ${testCase.id} parameter root exactly`, () => {+ const result = ToolSchema.safeParse({+ slug: 'TEST_TOOL',+ name: 'Test tool',+ inputParameters: testCase.schema,+ });++ expect(result.success).toBe(ingress.accepted);+ if (result.success) {+ expect(result.data.inputParameters).toEqual(ingress.preserved);+ }+ });+ }++ it('leaves an omitted root additionalProperties omitted', () => {+ const tool = ToolSchema.parse({+ slug: 'TEST_TOOL',+ name: 'Test tool',+ inputParameters: { type: 'object', properties: { name: { type: 'string' } } },+ });++ expect(tool.inputParameters).not.toHaveProperty('additionalProperties');+ });+});++describe('shared corpus invariants', () => {+ const baseCase = (id: string): CorpusCase => ({+ id,+ schema: { type: 'object' },+ instances: [{ input: {}, accepted: true }],+ });++ it('accepts the checked-in corpus', () => {+ expect(() => assertCorpusInvariants(loadObjectCases())).not.toThrow();+ });++ it('rejects duplicate case ids', () => {+ expect(() => assertCorpusInvariants([baseCase('dup'), baseCase('dup')])).toThrow(+ 'Duplicate corpus case id: dup'+ );+ });++ it('rejects a per-language acceptance override without a declared divergence', () => {+ const undeclared: CorpusCase = {+ id: 'undeclared',+ schema: { type: 'object' },+ instances: [{ input: {}, accepted: true, python: { accepted: false } }],+ };++ expect(() => assertCorpusInvariants([undeclared])).toThrow(+ 'overrides python acceptance without a divergence reason'+ );+ });++ it('allows a per-language acceptance override that declares its reason', () => {+ const declared: CorpusCase = {+ id: 'declared',+ schema: { type: 'object' },+ instances: [+ {+ input: {},+ accepted: true,+ python: { accepted: false },+ divergence: { reason: 'documented Pydantic limitation' },+ },+ ],+ };++ expect(() => assertCorpusInvariants([declared])).not.toThrow();+ });+});diff --git a/ts/packages/json-schema-to-effect-schema/src/index.ts b/ts/packages/json-schema-to-effect-schema/src/index.tsindex f599325aa..9ae1cb1a4 100644--- a/ts/packages/json-schema-to-effect-schema/src/index.ts+++ b/ts/packages/json-schema-to-effect-schema/src/index.ts@@ -53,6 +53,9 @@ const isObjectSchema = (schema: JsonObject): boolean =>'patternProperties' in schema ||'additionalProperties' in schema;+const hasNamedProperties = (schema: JsonObject): boolean =>+ isJsonObject(schema.properties) && Object.keys(schema.properties).length > 0;+const appendAllOf = (schema: JsonObject, constraint: JsonObject): void => {const current = schema.allOf;schema.allOf = Array.isArray(current) ? [...current, constraint] : [constraint];@@ -162,7 +165,16 @@ const normalizeSchemaNode = (}}- if (isObjectSchema(normalized) && normalized.additionalProperties === undefined) {+ // Composio tool inputs treat an omitted `additionalProperties` as strict, but+ // only for objects that actually name properties. Injecting `false` into a+ // property-less object (`{ type: "object" }`, `properties: {}`) or a+ // pattern-only object turned every valid free-form payload into an unknown-key+ // rejection.+ if (+ isObjectSchema(normalized) &&+ normalized.additionalProperties === undefined &&+ hasNamedProperties(normalized)+ ) {normalized.additionalProperties = false;}diff --git a/ts/packages/json-schema-to-effect-schema/test/fixtures/corpus.ts b/ts/packages/json-schema-to-effect-schema/test/fixtures/corpus.tsnew file mode 100644index 000000000..2dfbe552d--- /dev/null+++ b/ts/packages/json-schema-to-effect-schema/test/fixtures/corpus.ts@@ -0,0 +1,85 @@+/**+ * Loader for the shared cross-SDK JSON Schema conversion corpus.+ *+ * The corpus is a single logical fixture with one byte-identical copy per+ * language (`ts/packages/core/test/fixtures/json-schema-conversion/` and+ * `python/tests/fixtures/json-schema-conversion/`), following the same+ * convention as the webhook fixtures. Every consumer resolves its own copy+ * module-relatively — no working-directory or repository-root assumptions.+ */+import * as z from 'zod';++import objectCases from '../../../core/test/fixtures/json-schema-conversion/object-cases.json';++const JsonObject = z.record(z.string(), z.unknown());++const LanguageExpectation = z.object({+ output: z.unknown().optional(),+ accepted: z.boolean().optional(),+});++const CorpusInstance = z.object({+ input: JsonObject,+ accepted: z.boolean(),+ zod: LanguageExpectation.optional(),+ effect: LanguageExpectation.optional(),+ python: LanguageExpectation.optional(),+ divergence: z.object({ reason: z.string().min(1) }).optional(),+});++const CorpusCase = z.object({+ id: z.string().min(1),+ description: z.string().optional(),+ divergesFromJsonSchema: z.string().optional(),+ schema: JsonObject,+ ingress: z.object({ accepted: z.boolean(), preserved: JsonObject }).optional(),+ instances: z.array(CorpusInstance).min(1),+});++const Corpus = z.object({ cases: z.array(CorpusCase).min(1) });++export type CorpusInstance = z.infer<typeof CorpusInstance>;+export type CorpusCase = z.infer<typeof CorpusCase>;+export type CorpusLanguage = 'zod' | 'effect' | 'python';++/**+ * Enforce the invariants that keep the corpus a shared contract rather than a+ * per-language wish list: ids are unique, and a language may only disagree about+ * acceptance when the instance declares why.+ */+export const assertCorpusInvariants = (cases: ReadonlyArray<CorpusCase>): void => {+ const seen = new Set<string>();+ for (const testCase of cases) {+ if (seen.has(testCase.id)) {+ throw new Error(`Duplicate corpus case id: ${testCase.id}`);+ }+ seen.add(testCase.id);++ for (const [index, instance] of testCase.instances.entries()) {+ for (const language of ['zod', 'effect', 'python'] as const) {+ const override = instance[language]?.accepted;+ if (override !== undefined && override !== instance.accepted && !instance.divergence) {+ throw new Error(+ `Corpus case ${testCase.id} instance ${index} overrides ${language} acceptance without a divergence reason`+ );+ }+ }+ }+ }+};++let cached: ReadonlyArray<CorpusCase> | undefined;++/** Decode the shared corpus and enforce its cross-language invariants. */+export const loadObjectCases = (): ReadonlyArray<CorpusCase> => {+ if (!cached) {+ const { cases } = Corpus.parse(objectCases);+ assertCorpusInvariants(cases);+ cached = cases;+ }+ return cached;+};++/** Acceptance for one language: the shared flag unless a declared divergence overrides it. */+export const acceptedFor = (instance: CorpusInstance, language: CorpusLanguage): boolean =>+ instance[language]?.accepted ?? instance.accepted;diff --git a/ts/packages/json-schema-to-effect-schema/test/json-schema-to-effect-schema.test.ts b/ts/packages/json-schema-to-effect-schema/test/json-schema-to-effect-schema.test.tsindex 48b1e1a62..e345ef6e0 100644--- a/ts/packages/json-schema-to-effect-schema/test/json-schema-to-effect-schema.test.ts+++ b/ts/packages/json-schema-to-effect-schema/test/json-schema-to-effect-schema.test.ts@@ -2,6 +2,7 @@ import { jsonSchemaToZod } from '@composio/json-schema-to-zod';import { Either, Schema } from 'effect';import { describe, expect, it } from 'vitest';import { jsonSchemaToEffectSchema, type JsonSchemaValidationIssue } from '../src/index';+import { acceptedFor, loadObjectCases } from './fixtures/corpus';type JsonSchema = Record<string, unknown>;@@ -116,3 +117,27 @@ describe('jsonSchemaToEffectSchema', () => {);});});++describe('shared cross-SDK object corpus', () => {+ for (const testCase of loadObjectCases()) {+ describe(testCase.id, () => {+ for (const [index, instance] of testCase.instances.entries()) {+ const expected = acceptedFor(instance, 'effect');++ it(`instance ${index} is ${expected ? 'accepted' : 'rejected'}`, () => {+ const result = Schema.decodeUnknownEither(+ jsonSchemaToEffectSchema(testCase.schema as JsonSchema),+ { errors: 'all' }+ )(instance.input);++ expect(Either.isRight(result)).toBe(expected);+ if (Either.isRight(result) && instance.effect && 'output' in instance.effect) {+ // Effect decoding is validation-only: a successful decode returns the+ // input value unchanged, with no default materialization.+ expect(result.right).toEqual(instance.effect.output);+ }+ });+ }+ });+ }+});diff --git a/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts b/ts/packages/json-schema-to-zod/src/parsers/parse-object.tsindex a85c87c30..a45236982 100644--- a/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts+++ b/ts/packages/json-schema-to-zod/src/parsers/parse-object.ts@@ -7,15 +7,25 @@ import { parseSchema } from './parse-schema';import type { JsonSchemaObject, Refs, JsonSchema } from '../types';import { its } from '../utils/its';+/**+ * Build the static part of an object parser, or `undefined` when the schema+ * declares no named properties.+ *+ * A property-less object (`properties` absent or `{}`) deliberately returns+ * `undefined` so the caller can apply the open-object policy. This supersedes+ * an earlier `z.object({})` fallback that was kept "or else this will break+ * openai responses": collapsing `{ type: "object" }` to a strict empty object+ * is the defect it was masking, and the OpenAI provider suite is part of this+ * package's verification precisely so the claim stays checked.+ */function parseObjectProperties(objectSchema: JsonSchemaObject & { type?: 'object' }, refs: Refs) {if (!objectSchema.properties) {- // leave it as an empty object or else this will break openai responses- return z.object({});+ return undefined;}const propertyKeys = Object.keys(objectSchema.properties);if (propertyKeys.length === 0) {- return z.object({});+ return undefined;}const properties: Record<string, z.ZodTypeAny> = {};@@ -78,6 +88,96 @@ function parseObjectProperties(objectSchema: JsonSchemaObject & { type?: 'objectreturn z.object(properties);}+/**+ * Object parser for schemas carrying `patternProperties`.+ *+ * Every key is routed to exactly the schemas that apply to it — each matching+ * pattern, and `additionalProperties` only when no pattern and no named+ * property claims the key. A catch-all union would instead let a key sneak past+ * its own pattern by satisfying an unrelated one.+ */+function parseDynamicKeyObject(+ normalizedSchema: JsonSchemaObject & { type?: 'object' },+ propertiesSchema: z.ZodObject<Record<string, z.ZodTypeAny>, 'strip', z.ZodTypeAny> | undefined,+ additionalProperties: z.ZodTypeAny | undefined,+ refs: Refs+): z.ZodTypeAny {+ const patterns = Object.entries(normalizedSchema.patternProperties ?? {}).map(+ ([pattern, schema]) => ({+ regex: new RegExp(pattern),+ parser: parseSchema(schema, {+ ...refs,+ path: [...refs.path, 'patternProperties', pattern],+ }),+ })+ );++ const declaredKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));+ const rejectsUnmatched =+ additionalProperties instanceof z.ZodNever ||+ (additionalProperties === undefined && declaredKeys.size > 0);+ const validatesUnmatched =+ additionalProperties !== undefined &&+ !(additionalProperties instanceof z.ZodNever) &&+ normalizedSchema.additionalProperties !== true;++ const base = (propertiesSchema ?? z.object({})).passthrough();++ return base.transform((value: Record<string, unknown>, ctx) => {+ const result: Record<string, unknown> = { ...value };+ const unrecognizedKeys: string[] = [];++ for (const key of Object.keys(value)) {+ const matching = patterns.filter(({ regex }) => regex.test(key));++ for (const { parser } of matching) {+ const parsed = parser.safeParse(value[key]);+ if (!parsed.success) {+ ctx.addIssue({+ path: [...ctx.path, key],+ code: 'custom',+ message: `Invalid input: key "${key}" must match its patternProperties schema`,+ params: { issues: parsed.error.issues },+ });+ } else if (!declaredKeys.has(key)) {+ result[key] = parsed.data;+ }+ }++ if (matching.length > 0 || declaredKeys.has(key)) {+ continue;+ }++ if (rejectsUnmatched) {+ unrecognizedKeys.push(key);+ } else if (validatesUnmatched) {+ const parsed = additionalProperties!.safeParse(value[key]);+ if (!parsed.success) {+ ctx.addIssue({+ path: [...ctx.path, key],+ code: 'custom',+ message: `Invalid input: key "${key}" must match the additionalProperties schema`,+ params: { issues: parsed.error.issues },+ });+ } else {+ result[key] = parsed.data;+ }+ }+ }++ if (unrecognizedKeys.length > 0) {+ ctx.addIssue({+ path: [...ctx.path],+ code: 'unrecognized_keys',+ keys: unrecognizedKeys,+ message: `Unrecognized key(s) in object: ${unrecognizedKeys.map(key => `'${key}'`).join(', ')}`,+ });+ }++ return result;+ });+}+export function parseObject(objectSchema: JsonSchemaObject & { type?: 'object' },refs: Refs@@ -89,9 +189,8 @@ export function parseObject(objectSchema.type === 'object' ? objectSchema : { ...objectSchema, type: 'object' as const };const propertiesSchema:- | z.ZodObject<Record<string, z.ZodTypeAny>, 'strip', z.ZodTypeAny>- | undefined = parseObjectProperties(normalizedSchema, refs);- let zodSchema: z.ZodTypeAny | undefined = propertiesSchema;+ z.ZodObject<Record<string, z.ZodTypeAny>, 'strip', z.ZodTypeAny> | undefined =+ parseObjectProperties(normalizedSchema, refs);const additionalProperties =normalizedSchema.additionalProperties !== undefined@@ -104,88 +203,11 @@ export function parseObject(// Track if additionalProperties was explicitly set to trueconst isAdditionalPropertiesTrue = normalizedSchema.additionalProperties === true;- if (normalizedSchema.patternProperties) {- const parsedPatternProperties = Object.fromEntries(- Object.entries(normalizedSchema.patternProperties).map(([key, value]) => {- return [- key,- parseSchema(value, {- ...refs,- path: [...refs.path, 'patternProperties', key],- }),- ];- })- );- const patternPropertyValues = Object.values(parsedPatternProperties);-- if (propertiesSchema) {- if (additionalProperties) {- zodSchema = propertiesSchema.catchall(- z.union([...patternPropertyValues, additionalProperties] as [z.ZodTypeAny, z.ZodTypeAny])- );- } else if (Object.keys(parsedPatternProperties).length > 1) {- zodSchema = propertiesSchema.catchall(- z.union(patternPropertyValues as [z.ZodTypeAny, z.ZodTypeAny])- );- } else {- zodSchema = propertiesSchema.catchall(patternPropertyValues[0]);- }- } else {- if (additionalProperties) {- zodSchema = z.record(- z.union([...patternPropertyValues, additionalProperties] as [z.ZodTypeAny, z.ZodTypeAny])- );- } else if (patternPropertyValues.length > 1) {- zodSchema = z.record(z.union(patternPropertyValues as [z.ZodTypeAny, z.ZodTypeAny]));- } else {- zodSchema = z.record(patternPropertyValues[0]);- }- }-- const objectPropertyKeys = new Set(Object.keys(normalizedSchema.properties ?? {}));- zodSchema = zodSchema.superRefine((value: Record<string, unknown>, ctx) => {- for (const key in value) {- let wasMatched = objectPropertyKeys.has(key);-- for (const patternPropertyKey in normalizedSchema.patternProperties) {- const regex = new RegExp(patternPropertyKey);- if (key.match(regex)) {- wasMatched = true;- const result = parsedPatternProperties[patternPropertyKey].safeParse(value[key]);- if (!result.success) {- ctx.addIssue({- path: [...ctx.path, key],- code: 'custom',- message: `Invalid input: Key matching regex /${key}/ must match schema`,- params: {- issues: result.error.issues,- },- });- }- }- }-- if (!wasMatched && additionalProperties) {- const result = additionalProperties.safeParse(value[key]);- if (!result.success) {- ctx.addIssue({- path: [...ctx.path, key],- code: 'custom',- message: 'Invalid input: must match catchall schema',- params: {- issues: result.error.issues,- },- });- }- }- }- });- }let output: z.ZodTypeAny;- if (propertiesSchema) {- if (hasPatternProperties) {- output = zodSchema!;- } else if (additionalProperties) {+ if (hasPatternProperties) {+ output = parseDynamicKeyObject(normalizedSchema, propertiesSchema, additionalProperties, refs);+ } else if (propertiesSchema) {+ if (additionalProperties) {if (additionalProperties instanceof z.ZodNever) {output = propertiesSchema.strict();} else if (isAdditionalPropertiesTrue) {@@ -195,13 +217,12 @@ export function parseObject(output = propertiesSchema.catchall(additionalProperties);}} else {- // When additionalProperties is not specified, treat it as false+ // Named properties with an omitted `additionalProperties` stay strict for+ // tool inputs, even though JSON Schema itself would allow unknown keys.output = propertiesSchema.strict();}} else {- if (hasPatternProperties) {- output = zodSchema!;- } else if (additionalProperties) {+ if (additionalProperties) {if (additionalProperties instanceof z.ZodNever) {// When additionalProperties is false, create strict empty objectoutput = z.object({}).strict();@@ -212,7 +233,8 @@ export function parseObject(output = z.record(additionalProperties);}} else {- // When no properties and no additionalProperties specified, default to allowing additional properties+ // A property-less object with no `additionalProperties` keyword is open:+ // arbitrary content is accepted and preserved verbatim.output = z.object({}).passthrough();}}diff --git a/ts/packages/json-schema-to-zod/test/fixtures/corpus.ts b/ts/packages/json-schema-to-zod/test/fixtures/corpus.tsnew file mode 100644index 000000000..2dfbe552d--- /dev/null+++ b/ts/packages/json-schema-to-zod/test/fixtures/corpus.ts@@ -0,0 +1,85 @@+/**+ * Loader for the shared cross-SDK JSON Schema conversion corpus.+ *+ * The corpus is a single logical fixture with one byte-identical copy per+ * language (`ts/packages/core/test/fixtures/json-schema-conversion/` and+ * `python/tests/fixtures/json-schema-conversion/`), following the same+ * convention as the webhook fixtures. Every consumer resolves its own copy+ * module-relatively — no working-directory or repository-root assumptions.+ */+import * as z from 'zod';++import objectCases from '../../../core/test/fixtures/json-schema-conversion/object-cases.json';++const JsonObject = z.record(z.string(), z.unknown());++const LanguageExpectation = z.object({+ output: z.unknown().optional(),+ accepted: z.boolean().optional(),+});++const CorpusInstance = z.object({+ input: JsonObject,+ accepted: z.boolean(),+ zod: LanguageExpectation.optional(),+ effect: LanguageExpectation.optional(),+ python: LanguageExpectation.optional(),+ divergence: z.object({ reason: z.string().min(1) }).optional(),+});++const CorpusCase = z.object({+ id: z.string().min(1),+ description: z.string().optional(),+ divergesFromJsonSchema: z.string().optional(),+ schema: JsonObject,+ ingress: z.object({ accepted: z.boolean(), preserved: JsonObject }).optional(),+ instances: z.array(CorpusInstance).min(1),+});++const Corpus = z.object({ cases: z.array(CorpusCase).min(1) });++export type CorpusInstance = z.infer<typeof CorpusInstance>;+export type CorpusCase = z.infer<typeof CorpusCase>;+export type CorpusLanguage = 'zod' | 'effect' | 'python';++/**+ * Enforce the invariants that keep the corpus a shared contract rather than a+ * per-language wish list: ids are unique, and a language may only disagree about+ * acceptance when the instance declares why.+ */+export const assertCorpusInvariants = (cases: ReadonlyArray<CorpusCase>): void => {+ const seen = new Set<string>();+ for (const testCase of cases) {+ if (seen.has(testCase.id)) {+ throw new Error(`Duplicate corpus case id: ${testCase.id}`);+ }+ seen.add(testCase.id);++ for (const [index, instance] of testCase.instances.entries()) {+ for (const language of ['zod', 'effect', 'python'] as const) {+ const override = instance[language]?.accepted;+ if (override !== undefined && override !== instance.accepted && !instance.divergence) {+ throw new Error(+ `Corpus case ${testCase.id} instance ${index} overrides ${language} acceptance without a divergence reason`+ );+ }+ }+ }+ }+};++let cached: ReadonlyArray<CorpusCase> | undefined;++/** Decode the shared corpus and enforce its cross-language invariants. */+export const loadObjectCases = (): ReadonlyArray<CorpusCase> => {+ if (!cached) {+ const { cases } = Corpus.parse(objectCases);+ assertCorpusInvariants(cases);+ cached = cases;+ }+ return cached;+};++/** Acceptance for one language: the shared flag unless a declared divergence overrides it. */+export const acceptedFor = (instance: CorpusInstance, language: CorpusLanguage): boolean =>+ instance[language]?.accepted ?? instance.accepted;diff --git a/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts b/ts/packages/json-schema-to-zod/test/json-to-zod.test.tsindex 045d9a72f..8b3f34d8d 100644--- a/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts+++ b/ts/packages/json-schema-to-zod/test/json-to-zod.test.ts@@ -2,6 +2,7 @@ import { describe, it, expect } from 'vitest';import { z } from 'zod/v3';import { jsonSchemaToZod } from '../src/json-schema-to-zod';import type { JsonSchema } from '../src/types';+import { acceptedFor, loadObjectCases } from './fixtures/corpus';describe('jsonSchemaToZod', () => {describe('Basic Types', () => {@@ -1513,3 +1514,23 @@ describe('jsonSchemaToZod', () => {});});});++describe('shared cross-SDK object corpus', () => {+ for (const testCase of loadObjectCases()) {+ describe(testCase.id, () => {+ for (const [index, instance] of testCase.instances.entries()) {+ const expected = acceptedFor(instance, 'zod');++ it(`instance ${index} is ${expected ? 'accepted' : 'rejected'}`, () => {+ const zodSchema = jsonSchemaToZod(testCase.schema as JsonSchema);+ const result = zodSchema.safeParse(instance.input);++ expect(result.success).toBe(expected);+ if (result.success && instance.zod && 'output' in instance.zod) {+ expect(result.data).toEqual(instance.zod.output);+ }+ });+ }+ });+ }+});diff --git a/turbo.jsonc b/turbo.jsoncindex 71374f060..950a769fc 100644--- a/turbo.jsonc+++ b/turbo.jsonc@@ -24,7 +24,14 @@"outputs": ["dist/"]},"test": {- "dependsOn": ["^build"]+ "dependsOn": ["^build"],+ // the shared cross-SDK JSON Schema conversion corpus is owned by+ // `@composio/core` but read by the Zod, Effect, and CLI test suites, whose+ // $TURBO_DEFAULT$ inputs stop at their own package directory+ "inputs": [+ "$TURBO_DEFAULT$",+ "../core/test/fixtures/json-schema-conversion/object-cases.json"+ ]},"test:e2e": {"dependsOn": ["^build"],