Skip to content
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

Add openAPI discriminator support #3512

Closed
1 task done
heath-freenome opened this issue Mar 16, 2023 · 0 comments · Fixed by #3593
Closed
1 task done

Add openAPI discriminator support #3512

heath-freenome opened this issue Mar 16, 2023 · 0 comments · Fixed by #3593
Assignees
Labels
feature Is a feature request

Comments

@heath-freenome
Copy link
Member

Prerequisites

What theme are you using?

other

Is your feature request related to a problem? Please describe.

Build openAPI discriminator support into the utils, validator-ajv8 and core UI's MultiSchemaField. Do so by adding a supportsDiscriminator() onto the ValidatorType interface, implement it as false in validator-ajv6, allow the customizeValidator in validator-ajv8 to turn it on and update the appropriate utils to read the validator and use the discriminator if it exists in the schema. Same for MultiSchemaField

Describe the solution you'd like

No response

Describe alternatives you've considered

No response

@heath-freenome heath-freenome added needs triage Initial label given, to be assigned correct labels and assigned feature Is a feature request labels Mar 16, 2023
@heath-freenome heath-freenome self-assigned this Mar 16, 2023
@heath-freenome heath-freenome removed the needs triage Initial label given, to be assigned correct labels and assigned label Mar 16, 2023
heath-freenome added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 11, 2023
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 added a commit to heath-freenome/react-jsonschema-form that referenced this issue Apr 11, 2023
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 added a commit that referenced this issue Apr 12, 2023
* fix: Add support for Open API discriminator on anyOf/oneOf
Fixes #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 #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

* - Fixed snapshots to replace `field-undefined` classname with `field-xxx` by using `getSchemaType(schema)` instead of `schema.type` for classnames

* Update CHANGELOG.md

Co-authored-by: Nick Grosenbacher <[email protected]>

---------

Co-authored-by: Nick Grosenbacher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Is a feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant