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: Fixed 3778 By Resolving all refs in oneOf/AnyOf options #3786

Merged
merged 5 commits into from
Jul 24, 2023

Conversation

cwendtxealth
Copy link
Contributor

Reasons for making this change

fixes #3778 by going through anyOne/oneOf option schema and resolving any $refs.

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

* @param rootSchema - The root schema that will be forwarded to all the APIs
* @returns - given schema will all references resolved
*/
export function resolveAllReferences<S extends StrictRJSFSchema = RJSFSchema>(schema: S, rootSchema: S): 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.

@heath-freenome I was debating making this util specifically for oneOf/anyOf options. This is already assuming that the schema went through resolveSchema and has been evaluated with formData. Its just getting the defined $ref and updating the schema.

This might not solve the core issue of oneOf/anyOf options not fully being resolved in resolveSchema but it does solve the existing issue with minimum impact on the whole resolve workflow.

Copy link
Member

@heath-freenome heath-freenome left a comment

Choose a reason for hiding this comment

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

Can you also update the CHANGELOG.md file for 5.11.1

@@ -258,6 +258,37 @@ export default function sanitizeDataForNewSchemaTest(testValidator: TestValidato
})
).toEqual({});
});
it('returns empty formData after resolving schema refs', () => {
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious about this test. What prompted you to write it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason the two changes to resolveAnyOrOneOfSchemas and getClosestMatchingOption caused lose of coverage in sanitizeDataForNewSchema. Maybe because the refs were being resolved and it not longer needed to in sanitizeDataForNewSchema?

@heath-freenome heath-freenome merged commit 0ecbeb6 into rjsf-team:main Jul 24, 2023
4 checks passed
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.

anyOf/oneOf error not resolving $ref schema of object properties
2 participants