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

feature: Added better support for testing with AJV having discriminator option turned on #4257

Conversation

heath-freenome
Copy link
Member

Reasons for making this change

A recent issue made it clear that we didn't make it easy for users to turn on discriminator support from AJV

  • In @rjsf/utils improved support for discriminator as follows:
    • Updated the ValidatorType to add support for an optional reset() method
    • Updated the ParserValidator to implement reset() to clear the schema map, including a test to verify that
    • Updated the tests that used discriminator to remove the mapping block that AJV doesn't support
    • Updated the getFirstMatchingOption() test to deal with the situation where AJV doesn't support discriminator for array types
    • Updated the retrieveSchema() test to call reset() on validators that have it in an afterEach()
    • Updated the getTestValidator() implementation to implement a reset() that empties the arrays
  • In @rjsf/validator-ajv8 improved support for discriminator as follows:
    • Updated the createAjvInstance() function to denote that we want to make discriminator: true the default in v6
    • Updated the AJV8Validator to make reset do ajv.removeSchema() to clear the cached schemas
    • Updated the getTestValidator() implementation to call reset()` on the validator if it exists
    • Updated the schema.test.ts file to run a set of test with discriminator: true set on the AJV8Validator
  • Updated the CHANGELOG.md file accordingly

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run npx nx run-many --target=build --exclude=@rjsf/docs && npm run test:update to update snapshots, if needed.
    • I've updated docs if needed
    • I've updated the changelog with a description of the PR
  • I'm adding a new feature
    • I've updated the playground with an example use of the feature

…or option turned on

A recent issue made it clear that we didn't make it easy for users to turn on `discriminator` support from AJV
- In `@rjsf/utils` improved support for `discriminator` as follows:
  - Updated the `ValidatorType` to add support for an optional `reset()` method
  - Updated the `ParserValidator` to implement `reset()` to clear the schema map, including a test to verify that
  - Updated the tests that used `discriminator` to remove the `mapping` block that AJV doesn't support
  - Updated the `getFirstMatchingOption()` test to deal with the situation where AJV doesn't support discriminator for array types
  - Updated the `retrieveSchema()` test to call `reset()` on validators that have it in an `afterEach()`
  - Updated the `getTestValidator()` implementation to implement a `reset()` that empties the arrays
- In `@rjsf/validator-ajv8` improved support for `discriminator` as follows:
  - Updated the `createAjvInstance()` function to denote that we want to make `discriminator: true` the default in v6
  - Updated the `AJV8Validator` to make reset do `ajv.removeSchema()` to clear the cached schemas
  - Updated the `getTestValidator() implementation to call `reset()` on the validator if it exists
  - Updated the `schema.test.ts` file to run a set of test with `discriminator: true` set on the `AJV8Validator`
- Updated the `CHANGELOG.md` file accordingly
CHANGELOG.md Outdated Show resolved Hide resolved
@heath-freenome heath-freenome force-pushed the added-support-for-ajv8-discriminator branch from 85245ba to ed8dc41 Compare July 26, 2024 23:55
CHANGELOG.md Outdated Show resolved Hide resolved
@heath-freenome heath-freenome force-pushed the added-support-for-ajv8-discriminator branch from 2b72d9f to 471ffc3 Compare July 27, 2024 00:38
@heath-freenome heath-freenome force-pushed the added-support-for-ajv8-discriminator branch from 471ffc3 to c2f5517 Compare July 27, 2024 00:40
@heath-freenome heath-freenome merged commit a2dc1cd into rjsf-team:main Jul 27, 2024
5 checks passed
@heath-freenome heath-freenome deleted the added-support-for-ajv8-discriminator branch July 27, 2024 00:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants