Skip to content

Commit

Permalink
fix: Fixes #3825 Precompiled validator resolve root schema (#3826)
Browse files Browse the repository at this point in the history
* fix: Fixes #3825 Precompiled validator resolve root schema

* update changelog

---------

Co-authored-by: Heath C <[email protected]>
  • Loading branch information
cwendtxealth and heath-freenome authored Aug 15, 2023
1 parent 2a12401 commit 2a6ab23
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
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

0 comments on commit 2a6ab23

Please sign in to comment.