fix: render discriminator selector when variants omit the discriminator property#2802
Open
tabilzad wants to merge 1 commit into
Open
fix: render discriminator selector when variants omit the discriminator property#2802tabilzad wants to merge 1 commit into
tabilzad wants to merge 1 commit into
Conversation
…or property When a schema uses oneOf + discriminator but the variant schemas don't declare the discriminator property themselves (no allOf inheritance from a parent that does), the selector was mounted only as a side effect of a field row whose name matched the discriminator property. With no such field, nothing rendered the selector, so only the first variant was shown. ObjectSchema now renders the DiscriminatorDropdown standalone when no matching field exists. Specs that declare the property keep the existing inline behaviour, so the common path is unchanged.
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.
What/Why/How?
When a schema uses
oneOf+discriminatorand the variant schemas don't declare the discriminator property themselves (i.e. noallOfinheritance from a parent that declares it), the variant selector silently disappears and only the first variant is rendered.The dropdown was only mounted as a side effect of a field row whose name matched
discriminator.propertyName. When no such field exists on the active variant, nothing rendered the selector.ObjectSchemanow renders theDiscriminatorDropdownstandalone in that case, so the variants stay switchable. Specs that declare the discriminator property keep the existing inline behaviour, so the common render path is unchanged.Reference
Closes #2571. Related: #2562.
Tests
Added a fixture and unit tests for the no-property case, plus a regression guard for the
allOf-inheritance case. Full unit suite passes (npm run unit).Check yourself