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: Fixes #3825 Precompiled validator resolve root schema #3826

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ should change the heading of the (upcoming) version to include a major version b
-->
# 5.12.1

## @rjsf/validator-ajv8

- Updated `AJV8PrecompiledValidator.rawValidation()` to resolve root schema with formData when comparing input schema, fixing [#3825](https://github.com/rjsf-team/react-jsonschema-form/issues/3825)

## @rjsf/core

- Updated `MultiSchemaField` to merge all top level fields except properties for anyOf/oneOf options, fixing [#3808](https://github.com/rjsf-team/react-jsonschema-form/issues/3808) and [#3787](https://github.com/rjsf-team/react-jsonschema-form/issues/3787)
Expand Down
10 changes: 2 additions & 8 deletions packages/validator-ajv8/src/precompiledValidator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,6 @@ export default class AJV8PrecompiledValidator<
*/
readonly rootSchema: S;

/** The root schema resolved top level refs
*
* @private
*/
readonly resolvedRootSchema: S;

/** The `ValidatorFunctions` map used to construct this validator
*
* @private
Expand Down Expand Up @@ -72,7 +66,6 @@ export default class AJV8PrecompiledValidator<
this.validateFns = validateFns;
this.localizer = localizer;
this.mainValidator = this.getValidator(rootSchema);
this.resolvedRootSchema = retrieveSchema(this, rootSchema, rootSchema);
}

/** Returns the precompiled validator associated with the given `schema` from the map of precompiled validator
Expand Down Expand Up @@ -109,7 +102,8 @@ export default class AJV8PrecompiledValidator<
* @throws - Error when the schema provided does not match the base schema of the precompiled validator
*/
rawValidation<Result = any>(schema: S, formData?: T): RawValidationErrorsType<Result> {
if (!isEqual(schema, this.resolvedRootSchema)) {
const resolvedRootSchema = retrieveSchema(this, this.rootSchema, this.rootSchema, formData);
if (!isEqual(schema, resolvedRootSchema)) {
throw new Error(
'The schema associated with the precompiled schema differs from the schema provided for validation'
);
Expand Down