fix(parse): demote composition keywords instead of dropping them - #1834
Open
Swastikbhat-lab wants to merge 2 commits into
Open
fix(parse): demote composition keywords instead of dropping them#1834Swastikbhat-lab wants to merge 2 commits into
Swastikbhat-lab wants to merge 2 commits into
Conversation
transform_schema pops type/anyOf/oneOf/allOf before deciding which one to emit, so when a schema combines `type` with a composition keyword (or two composition keywords), the non-selected keywords were silently discarded — the transformed schema no longer matched the user's constraints. Keep them in the leftover set so they flow through the existing demote-to-description path, matching how every other unsupported property is handled. Only the previously-dropped constraint is added; output for single-keyword schemas is unchanged.
Adds fuzz-style property tests (seeded random generator + exhaustive bounded sweep) asserting every input schema key survives the transform either as an equal-valued key or demoted into the description, per the policy documented in _transform.py. The property tests exposed one remaining gap: sibling keywords of a $ref (title, enum, ...) were silently dropped by the early return. They are now demoted to the description like every other unsupported property, so a $ref schema carries all of its original information.
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
transform_schemasilently drops user constraints when a JSON schema combines keywords that the API treats as mutually exclusive at a given level.transform_schemapopstype/anyOf/oneOf/allOfup front, then emits only the winner:{"type": "string", "anyOf": [...]}→ thetypeconstraint is discarded entirely{"anyOf": [...], "oneOf": [...]}→oneOfis discarded (not even preserved in the description){"anyOf": [...], "allOf": [...]}→allOfis discardedThe transformed schema therefore no longer matches the user's original constraints — and unlike every other unsupported property, the dropped keyword isn't even demoted to the description, so the model never "sees" the constraint either.
Fix
When a composition keyword is selected, the coexisting
typeand any secondary composition keyword are put back into the leftover set so they flow through the file's existing demote-to-description path (description: "{type: string}"), the same mechanism used forminimum,default, etc. The comment above that path states the intent: unsupported props are appended to the description "so that the model might follow them."The change is strictly additive: nothing that was previously emitted changes. Schemas with a single keyword (the only case with existing tests) produce byte-identical output; only previously-dropped constraints are now preserved.
Tests
4 regression tests added to
tests/lib/_parse/test_transform.py, one per dropped-keyword combination (type+anyOf,anyOf+oneOf,anyOf+allOf,type+oneOf). All 4 fail on the unpatched tree and pass with the fix; the fulltests/lib/_parse+tests/lib/streamingsuites (88 tests) remain green.pyright,mypyandruffreport no new issues.