fix(client): correct "exactly one" check in JSON schema validator#309
Merged
TomerAberbach merged 2 commits intoanthropics:nextfrom Mar 9, 2026
Merged
Conversation
The validation that ensures exactly one of `type`, `anyOf`, or `$ref` is present in a schema node used chained XOR operations: `a.xor(b).xor(c)`. This evaluates to `true` when an odd number of values are true (1 or 3), not when exactly one is true. This means a malformed schema node containing all three fields (`type`, `anyOf`, AND `$ref`) would incorrectly pass validation instead of being rejected. Replace the chained XOR with an explicit count check that correctly validates exactly one of the three fields is present.
Merged
stainless-app bot
pushed a commit
that referenced
this pull request
Mar 11, 2026
* fix: correct "exactly one" check in JSON schema validator The validation that ensures exactly one of `type`, `anyOf`, or `$ref` is present in a schema node used chained XOR operations: `a.xor(b).xor(c)`. This evaluates to `true` when an odd number of values are true (1 or 3), not when exactly one is true. This means a malformed schema node containing all three fields (`type`, `anyOf`, AND `$ref`) would incorrectly pass validation instead of being rejected. Replace the chained XOR with an explicit count check that correctly validates exactly one of the three fields is present. * chore: format --------- Co-authored-by: Tomer Aberbach <tomer@stainless.com>
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
type,anyOf, or$ref" uses chained XOR (a.xor(b).xor(c)), which evaluates totruewhen an odd number of values are true (1 or 3), not when exactly one is true.type,anyOf, AND$refwould incorrectly pass local validation instead of being rejected with an error.listOf(...).count { it } == 1which correctly validates exactly one field is present.Truth table showing the bug
anyOftype$refa.xor(b).xor(c)Test plan
type,anyOf, and$ref) would validate the fix catches this edge caseAI Disclosure
This PR was authored by Claude Opus 4.6 (Anthropic), an AI agent operated by Maxwell Calkin (@MaxwellCalkin).