Skip to content

Merge all plain-object anyOf branches instead of keeping only the first#703

Open
pushpak1300 wants to merge 3 commits into
0.xfrom
fix/schema-normalizer-anyof-merging
Open

Merge all plain-object anyOf branches instead of keeping only the first#703
pushpak1300 wants to merge 3 commits into
0.xfrom
fix/schema-normalizer-anyof-merging

Conversation

@pushpak1300

Copy link
Copy Markdown
Member

The normalizer currently collapses anyOf/oneOf to the first branch, so discriminated union schemas lose all variant-specific properties:

// before — choices and scale are gone
{type: object, properties: {kind: {enum: ['open']}, text: ...}, required: [kind, text]}

// after
{type: object, properties: {kind: {enum: ['open', 'choice', 'rating']}, text: ..., choices: ..., scale: ...}, required: [kind]}

All plain-object branches are unioned into one schema. For a shared discriminator property with enum values in each branch, the enums are merged. The required intersection keeps only fields required in every opinionated branch.

Three correctness fixes are also included: required was incorrectly promoted when only one of multiple branches declared it; the array_merge fallback now uses mergeSchema to avoid shallow-overwriting already-merged properties when both anyOf and oneOf appear on the same node; and is_array guards prevent a TypeError from non-array enum values in malformed MCP tool schemas.

@pushpak1300 pushpak1300 marked this pull request as ready for review June 11, 2026 19:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant