Skip to content

Commit ffc77e7

Browse files
committed
[ajv] Migrate to isSchemaDeepEqual
1 parent d68a37f commit ffc77e7

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

.changeset/fast-icons-protect.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@sjsf/ajv8-validator": patch
3+
---
4+
5+
Migrate to `isSchemaDeepEqual`

packages/ajv8-validator/src/validator.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Ajv, type AsyncValidateFunction, type ValidateFunction } from "ajv";
22
import type { ErrorObject, AnySchema } from "ajv";
3+
import type { AnyValidateFunction } from "ajv/dist/core.js";
34

4-
import type { MaybePromise } from '@sjsf/form/lib/types';
5-
import { deepEqual } from "@sjsf/form/lib/deep-equal";
5+
import type { MaybePromise } from "@sjsf/form/lib/types";
66
import { getValueByPath } from "@sjsf/form/lib/object";
77
import { weakMemoize } from "@sjsf/form/lib/memoize";
88
import {
99
ID_KEY,
1010
prefixSchemaRefs,
1111
ROOT_SCHEMA_PREFIX,
12+
isSchemaDeepEqual,
1213
type Schema,
1314
type SchemaDefinition,
1415
type SchemaValue,
@@ -25,7 +26,6 @@ import {
2526
type UiSchema,
2627
type UiSchemaRoot,
2728
} from "@sjsf/form";
28-
import type { AnyValidateFunction } from "ajv/dist/core.js";
2929

3030
const trueSchema: Schema = {};
3131
const falseSchema: Schema = {
@@ -58,9 +58,12 @@ export function makeSchemaCompiler<A extends boolean>(ajv: Ajv, _async: A) {
5858
return (schema: Schema, rootSchema: Schema) => {
5959
rootSchemaId = rootSchema[ID_KEY] ?? ROOT_SCHEMA_PREFIX;
6060
let ajvSchema = ajv.getSchema(rootSchemaId)?.schema;
61-
// @deprecated
62-
// TODO: Replace deep equality comparison with reference equality by default
63-
if (ajvSchema !== undefined && !deepEqual(ajvSchema, rootSchema)) {
61+
if (
62+
ajvSchema !== undefined &&
63+
// @deprecated
64+
// TODO: Replace deep equality comparison with reference equality by default
65+
!isSchemaDeepEqual(ajvSchema as Schema, rootSchema)
66+
) {
6467
ajv.removeSchema(rootSchemaId);
6568
validatorsCache.delete(schema);
6669
ajvSchema = undefined;

0 commit comments

Comments
 (0)