-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Add support for Open API discriminator on anyOf/oneOf #3593
Merged
Conversation
This file contains 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
Fixes rjsf-team#3512 by updating the `getFirstMatchingOption()` and `getClosestMatchingOption()` to take an optional discriminator property to use for drilling into one-of Objects to simplify selection detection Fixes rjsf-team#2044 Fixing the `toIdSchema()` generation to use the `getSchemaType()` function rather than just using `schema.type` - In `@rjsf/utils`, updated the `SchemaUtilsType`, its associated class implementation and several functions to fix both bug as follows: - Updated `SchemaUtilsType` to add an optional `discriminatorField?: string` parameter to the `get(First|Closest|)MatchingOption()` functions - Updated `createSchemaUtils()` to take the new `discriminatorField` parameter and forward it onto the underlying function `get(First|Closest|)MatchingOption() implementations - Updated the `getClosestMatchingOption()` and `getFirstMatchingOption()` to pass the new `discriminatorField` to the `getMatchingOption()` function - Updated `getMatchingOption()` to use `discriminatorField` when it is present in the `options` object properties to drill into the object to detect if that one field is valid - Also updated the `toIdSchemaInternal()` function to use `getSchemaType(schema) === 'object'` rather than `schema.type === 'object'` to get the proper pathing for ids - In `@rjsf/core`, updated the `MultiSchemaField`, to get the `discriminator.propertyName` value for a `anyOf/oneOf` object and pass it into `getClosestMatchingOption()` - Updated the `oneOf` and `anyOf` tests to verify the `discriminator` property works - Also updated the `oneOf` and `form` tests to update the few ids that were fixed by the `toIdSchema()` fix - Moved a test that was once just in the `bootstrap-4` theme related to `additionalProperties` being defined as true for a non-object type schema - In the other themes, updated the snapshots to include the new test that was moved from `bootstrap-4` into the `objectTests` - Updated `bootstrap-4` to delete the `AdditionalProperties.test.tsx` and its associated snapshot since it was moved to `core` - Updated the `utility-functions` documentation to add the new `discriminatorField` prop to the `get(First|Closest|)MatchingOption()` functions - Updated the `CHANGELOG.md` file accordingly
heath-freenome
force-pushed
the
fix-3512
branch
from
April 11, 2023 00:34
ff61332
to
ad8aa98
Compare
heath-freenome
commented
Apr 11, 2023
nickgros
reviewed
Apr 11, 2023
…xxx` by using `getSchemaType(schema)` instead of `schema.type` for classnames
nickgros
approved these changes
Apr 12, 2023
Co-authored-by: Nick Grosenbacher <[email protected]>
7 tasks
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.
Reasons for making this change
Fixes #3512 by updating the
getFirstMatchingOption()
andgetClosestMatchingOption()
to take an optional discriminator property to use for drilling into one-of Objects to simplify selection detection and using that inMultiSchemaField
by passing thepropertyName
of adiscriminator
if it exists.Fixes #2044 Fixing the
toIdSchema()
generation to use thegetSchemaType()
function rather than just usingschema.type
@rjsf/utils
, updated theSchemaUtilsType
, its associated class implementation and several functions to fix both bug as follows:SchemaUtilsType
to add an optionaldiscriminatorField?: string
parameter to theget(First|Closest|)MatchingOption()
functionscreateSchemaUtils()
to take the newdiscriminatorField
parameter and forward it onto the underlying function `get(First|Closest|)MatchingOption() implementationsgetClosestMatchingOption()
andgetFirstMatchingOption()
to pass the newdiscriminatorField
to thegetMatchingOption()
functiongetMatchingOption()
to usediscriminatorField
when it is present in theoptions
object properties to drill into the object to detect if that one field is validtoIdSchemaInternal()
function to usegetSchemaType(schema) === 'object'
rather thanschema.type === 'object'
to get the proper pathing for ids@rjsf/core
, updated theMultiSchemaField
, to get thediscriminator.propertyName
value for aanyOf/oneOf
object and pass it intogetClosestMatchingOption()
oneOf
andanyOf
tests to verify thediscriminator
property worksoneOf
andform
tests to update the few ids that were fixed by thetoIdSchema()
fixbootstrap-4
theme related toadditionalProperties
being defined as true for a non-object type schemabootstrap-4
into theobjectTests
bootstrap-4
to delete theAdditionalProperties.test.tsx
and its associated snapshot since it was moved tocore
utility-functions
documentation to add the newdiscriminatorField
prop to theget(First|Closest|)MatchingOption()
functionsCHANGELOG.md
file accordinglyChecklist
npm run test:update
to update snapshots, if needed.