Repository navigation
Conversation
… in ruby-nextgen Polymorphism.cast_raw accepted a nil array/hash element for a model candidate but rejected it for primitive candidates, so casting [1, nil] as Array<Integer> produced NO_MATCH while Array<Pet> matched with the element preserved. Handle nil data once at the top of cast_raw so a null value legitimately matches every candidate type, as already documented on the NO_MATCH sentinel, and drop the model-specific nil special case. Signed-off-by: Inf1mum <vadimlazuk5@gmail.com>
This branch has not been deployed
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.
Fixes #25720
Polymorphism.cast_raw(the anyOf/oneOf resolution runtime) treated anilarray/hash element asymmetrically: a model candidate accepted it (returnednil), a primitive candidate returnedNO_MATCH— socast('Array<Integer>', [1, nil])failed the whole resolution withnil, whilecast('Array<Pet>', [pet, nil])returned[Pet, nil]. This contradicted the sentinel's own doc that a nullable element is a legitimate match.cast_rawnow returnsniluniformly fordata.nil?at the top (null matches every candidate), and the model-specificdata.nil? ? nil :special case in the else branch is removed. Both committed generated runtimes (petstore, ruby-nextgen-qdrant) carry the identical 2-hunk change.5-case rspec fixture: nil elements kept for
Array<Integer/String/Boolean>andHash<String, Integer>, model candidates against a real validatingPet, rejection guards (wrong-type element, invalid model element, non-array), nil top-level data on every candidate type. Verified pre-fix reproduction (exact issue output) and post-fix match ([1, nil]/[Pet, NilClass]); full petstore rspec suite green (28 examples).Summary by cubic
Fixes #25720 by making
Polymorphism.cast_rawtreat nil data as a legitimate match for every candidate type, so a nil element in anArray<Integer>orHash<String, Integer>no longer causes the whole anyOf/oneOf resolution to fail. Previously primitive candidates rejected nil while model candidates accepted it, leading to inconsistent results like[1, nil]failing but[Pet, nil]succeeding. The change adds a single early return fordata.nil?and removes the model-specific special case.Samples for petstore and ruby-nextgen-qdrant are regenerated from the same two-hunk template change, and a new spec covers nil elements for primitive and model candidates plus rejection guards.
Written for commit 835f0bf. Summary will update on new commits.