Rewrite nested `$ref`s when merging JSON schema definitions

Merged
LI
1mo ago
+103-15

This pull request was posted by Codex Desktop using gpt-6-luna on behalf of David.

Why we make these changes

When output schemas have colliding $defs, the merge walker can leave references in six nested schema keywords pointing to another output type's definition. This can make a schema accept values of the wrong type. Closes #10589.

New public surface

none

User-visible behavior

Before: merged schemas could resolve nested references to the wrong definition. After: references in contains, if, then, else, dependentSchemas, and tuple-form items follow renamed definitions, including through shared definitions.

Verification

What changes for existing users

Merged output schemas preserve nested references to the intended definitions.

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration, release note, and exact API-check waiver. (Not applicable.)
  • PR title is fit for the release changelog.