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

Fix incorrect allOf merging (fix #2923) (Reimplement #3025) #3227

Merged
merged 6 commits into from Dec 22, 2022

Conversation

nickgros
Copy link
Contributor

@nickgros nickgros commented Nov 4, 2022

See #3025 for more information.

It's currently hard to verify the issue in the playground because the examples seem to trigger an infinite loop of some sort that crash the page.

Fixes #2923

Checklist

  • I'm updating documentation
  • I'm adding or updating code
    • I've added and/or updated tests. I've run 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

AlimovSV and others added 3 commits December 21, 2022 12:36
…if/then/else statements fail to render correctly
- Fix a case where an invalid schema type (e.g. a string) may be passed to `computeDefaults`.
- Fix an issue where `toPathSchema` only recognized `additionalProperties` in schema objects if `additionalProperties` was strictly `true` when the value of `additionalProperties` could be a JSON Schema object.
parentDefaults?: T,
rootSchema: S = {} as S,
rawFormData?: T,
includeUndefinedValues: boolean | "excludeObjectChildren" = false
): T | T[] | undefined {
const formData = isObject(rawFormData) ? rawFormData : {};
let schema: S = isObject(rawSchema) ? rawSchema : ({} as S);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have a test that passes an invalid schema and expects a specific error message. The test fails without this change because a string ends up getting passed here as rawSchema, and we don't get to the error case that the test does expect.

The best fix would be to actually validate the schema before we get this far, but that would be a large change that would require a lot of effort.

schema[ADDITIONAL_PROPERTIES_KEY] === true
schema[ADDITIONAL_PROPERTIES_KEY] !== false
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use the path schema to decide which objects to drop when we use omitExtraData. For some reason, a change here uncovered a case where the additionalProperty fields would be dropped by omitExtraData + liveOmit if the additionalProperties schema was an object. This fixes that regression.

@heath-freenome
Copy link
Collaborator

heath-freenome commented Dec 21, 2022

@nickgros Can you list which actual issues this will fix in the description? Or do we just not know? Or at least list the ones that we think this MIGHT fix and let them reopen if it doesn't?

@nickgros
Copy link
Contributor Author

@nickgros Can you list which actual issues this will fix in the description? Or do we just not know? Or at least list the ones that we think this MIGHT fix and let them reopen if it doesn't?

I looked through and found that this fixes #2923. The gist is that the previous merge algorithm was incorrect, and @AlimovSV 's reproduction in #2923 proves it by showing a case where incorrectly-merged subschemas returned errors when the raw AJV validation resulted in no errors. After this change, RJSF creates correct subschemas, and no errors are returned for valid data.

CHANGELOG.md Outdated Show resolved Hide resolved
@nickgros nickgros changed the title Reimplement #3025 Fix incorrect allOf merging (fix #2923) (Reimplement #3025) Dec 22, 2022
@nickgros nickgros merged commit 8ebbb42 into rjsf-team:main Dec 22, 2022
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this pull request Jun 8, 2023
…am#3025) (rjsf-team#3227)

Co-authored-by: Sergey Alimov <sergey.alimov@gmail.com>
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Fixes rjsf-team#2923
shijistar pushed a commit to shijistar/react-jsonschema-form that referenced this pull request Jun 8, 2023
…am#3025) (rjsf-team#3227)

Co-authored-by: Sergey Alimov <sergey.alimov@gmail.com>
Co-authored-by: Heath C <51679588+heath-freenome@users.noreply.github.com>
Fixes rjsf-team#2923
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.

Wrong allOf behaviour
3 participants