Preserve sibling object keywords in schema previews - #1985
Open
gjermundgaraba wants to merge 1 commit into
Open
Conversation
Inline schemas with properties or required beside allOf, anyOf, or oneOf lost those siblings in compiled TypeScript previews; only $id-named definitions kept them. Match inline schemas as UNNAMED_SCHEMA so the parser builds the same intersection, name a titled definition after the whole composition rather than its sibling fragment, and reuse the cached intersection when a recursive reference re-enters it instead of crashing the preview to unknown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Inline schemas with
propertiesbesideallOf,anyOf, oroneOflost those properties, and theirrequiredkeys, in TypeScript tool previews; only$id-named definitions kept them. Found through a connected MCP server whose create tool requiresmetadata.type:tools.describe.tool()showedmetadataas{ [k: string]: unknown }, so agents omittedtypeand failed the server's runtime validation.The vendored compiler is based on upstream json-schema-to-typescript 15.0.4. Upstream fixed the same bug in bcherny/json-schema-to-typescript#708, released in 16.0.0, and added the same intersection re-entry guard in bcherny/json-schema-to-typescript#829, which is still unreleased. This is the minimal equivalent, written before I found the upstream change: named definitions already joined the composition through
NAMED_SCHEMA, and inline schemas now take the same path. For the schemas in the new tests, the output matches 16.0.0's, with one exception: this branch names a titled definition after the whole composition, where 16.0.0 still splits it intoMetadataandMetadata1. The parser also no longer crashes tounknownwhen a composed definition's branch refers back to it.Not in this PR: a pattern-only string
allOfstill renders as({ [k: string]: unknown; } & string), and arequiredkey with no matchingpropertiesentry is still dropped. Both are separate, pre-existing issues; upstream 16.0.0 renders the first asstring.Verification
bun run format:checkbun run lintbun run typecheckbun run testscenarios/tool-descriptions.test.tson selfhost; artifacte2e/runs/selfhost/tools-agent-visible-descriptions-snapshot/descriptions.mdshowsmetadata?: ({ [k: string]: unknown; } & { type: string; }).The Cloudflare and Vercel real-spec snapshots are unchanged, and the Stripe fixture assertions still pass. Known limitation, documented in the vendored README: a
nullbranch of ananyOf/oneOfbeside sibling properties is absorbed by the intersection, as named definitions already did and as upstream 16.0.0 renders it.Checklist