Skip to content

core: Remove AJV usage from combinator mappers #2413

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lucas-koehler
Copy link
Contributor

  • Adapt algorithm to determine the fitting schema index for combinators to no longer use AJV
  • New heuristic uses identifying properties that should match a const value in the schema
  • Adapt MaterialOneOfRenderer.test.tsx to fit new heuristic
  • Describe changes and add examples to migration guide
  • Adapt some of the anyOf and oneOf examples to custom and new identification properties

In contrast to oneOf and anyOf rendererer, allOf renderers do not need the indexOfFittingSchema because all schemas apply at once.
Thus, remove using mapStateToCombinatorRendererProps from mapStateToAllOfProps and, with this, the unnecessary calculation of the index.

fix #2371

Copy link

netlify bot commented Jan 31, 2025

Deploy Preview for jsonforms-examples ready!

Name Link
🔨 Latest commit 80405a5
🔍 Latest deploy log https://app.netlify.com/sites/jsonforms-examples/deploys/68089be95151a80008f45760
😎 Deploy Preview https://deploy-preview-2413--jsonforms-examples.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@lucas-koehler lucas-koehler requested a review from sdirix February 4, 2025 09:33
- Adapt algorithm to determine the fitting schema index for combinators to no longer use AJV
- New heuristic uses identifying properties that should match a const value in the schema
- Adapt MaterialOneOfRenderer.test.tsx to fit new heuristic
- Describe changes and add examples to migration guide
- Adapt some of the anyOf and oneOf examples to custom and new identification properties

#2371
In contrast to oneOf and anyOf rendererer, allOf renderers do not need the `indexOfFittingSchema` because all schemas apply at once.
Thus, remove using mapStateToCombinatorRendererProps from mapStateToAllOfProps and, with this, the unnecessary calculation of the index.

Part of #2371
@lucas-koehler lucas-koehler force-pushed the lk/2371-remove-ajv-from-combinators branch from 07fe0f7 to d9b3550 Compare February 28, 2025 10:40
@lucas-koehler lucas-koehler requested a review from sdirix February 28, 2025 10:40
- remove usage of any number or string property as fallback
- choose type, kind default prop based on combinator schema with const entry instead of presence in the data object
- Adapt tests
- remove usage of id as a default prop
@lucas-koehler lucas-koehler force-pushed the lk/2371-remove-ajv-from-combinators branch from d9b3550 to cf3f154 Compare March 3, 2025 15:16
@lucas-koehler
Copy link
Contributor Author

@sdirix The tests are fixed and the review comments applied :)

@coveralls
Copy link

coveralls commented Mar 3, 2025

Coverage Status

coverage: 82.606% (+0.09%) from 82.517%
when pulling 80405a5 on lk/2371-remove-ajv-from-combinators
into 5218263 on master.

Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The preselection for primitives fails now (example #oneOf_1273_simple). However I think we can add primitive detection to our determinator.
  • All the oneOf validation examples no longer properly work with the new AJV-less approach in case the data is set to a valid initial data which is not the first entry. We should think about what we advice users for these cases.
  • The oneOf recursive example detection is also broken, we should add type/kind properties there I think.

For migration: We should provide a way to restore the old behavior. For this we can hand over a (by default unused) AJV to the determination function and show the user how they can customize this function to use AJV to restore the old behavior.

Comment on lines +23 to +24
Furthermore, subschemas can no longer automatically be selected based on validation results like
produced by different required properties between subschemas.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Furthermore, subschemas can no longer automatically be selected based on validation results like
produced by different required properties between subschemas.
Furthermore, subschemas can no longer automatically be selected based on validation results like produced by different required properties between subschemas.

@@ -36,6 +36,12 @@ export interface CombinatorSubSchemaRenderInfo {

export type CombinatorKeyword = 'anyOf' | 'oneOf' | 'allOf';

/** Custom schema keyword to define the property identifying different combinator schemas. */
export const COMBINATOR_TYPE_PROPERTY = 'x-jsf-type-property';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could place these two properties as well as getCombinatorIndexOfFittingSchema into a Combinators object. Then in all our code we should always refer to Combinators.COMBINATOR_TYPE_PROPERTY etc. This would allow adopters to easily globally override these two properties as well the actual determination function for easier customization.

@@ -2,6 +2,116 @@

## Migrating to JSON Forms 3.6

### Combinator (anyOf & oneOf) index selection now uses a heuristic instead of AJV
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should place this for JSON Forms 4.0 as this will break adopters

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.

Remove AJV usage from combinator mappers
3 participants