From 08c21cdd801eff93cd7f262f1ccfef85fdf2f994 Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 16 Dec 2024 09:29:08 +0100 Subject: [PATCH 1/5] Revert "fix: Switch to using isValid() for oneOf schema detection in retrieveSchema() (#3575)" This reverts commit ff46301dbbeb951758c5ee1b2ec0f95a459b4dfe. --- packages/core/test/Form.test.jsx | 1 + packages/utils/src/schema/retrieveSchema.ts | 3 +- .../test/schema/getDefaultFormStateTest.ts | 12 ++-- .../utils/test/schema/retrieveSchemaTest.ts | 56 +++++++++---------- 4 files changed, 37 insertions(+), 35 deletions(-) diff --git a/packages/core/test/Form.test.jsx b/packages/core/test/Form.test.jsx index 52eb0128eb..181d44ef64 100644 --- a/packages/core/test/Form.test.jsx +++ b/packages/core/test/Form.test.jsx @@ -218,6 +218,7 @@ describeRepeated('Form common', (createFormComponent) => { it('should work with oneOf', function () { const schema = { + $schema: 'http://json-schema.org/draft-06/schema#', type: 'object', properties: { connector: { diff --git a/packages/utils/src/schema/retrieveSchema.ts b/packages/utils/src/schema/retrieveSchema.ts index 17439cf396..fd40c0fb0b 100644 --- a/packages/utils/src/schema/retrieveSchema.ts +++ b/packages/utils/src/schema/retrieveSchema.ts @@ -815,7 +815,8 @@ export function withExactlyOneSubschema< [dependencyKey]: conditionPropertySchema, }, } as S; - return validator.isValid(conditionSchema, formData, rootSchema) || expandAllBranches; + const { errors } = validator.validateFormData(formData, conditionSchema); + return errors.length === 0 || expandAllBranches; } return false; }); diff --git a/packages/utils/test/schema/getDefaultFormStateTest.ts b/packages/utils/test/schema/getDefaultFormStateTest.ts index cf3ef4cd6a..0cebf66c6a 100644 --- a/packages/utils/test/schema/getDefaultFormStateTest.ts +++ b/packages/utils/test/schema/getDefaultFormStateTest.ts @@ -3930,13 +3930,13 @@ export default function getDefaultFormStateTest(testValidator: TestValidatorType ]); }); it('should populate defaults for nested dependencies in arrays when matching enum values in oneOf', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - true, // First oneOf... first === first - false, // Second oneOf... second !== first - false, // First oneOf... first !== second - true, // Second oneOf... second === second + data: [ + { errors: [], errorSchema: {} }, // First oneOf... first === first + { errors: [{ stack: 'error' }], errorSchema: {} }, // Second oneOf... second !== first + { errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... first !== second + { errors: [], errorSchema: {} }, // Second oneOf... second === second ], }); const schema: RJSFSchema = { diff --git a/packages/utils/test/schema/retrieveSchemaTest.ts b/packages/utils/test/schema/retrieveSchemaTest.ts index ca245d5e27..32d3185d09 100644 --- a/packages/utils/test/schema/retrieveSchemaTest.ts +++ b/packages/utils/test/schema/retrieveSchemaTest.ts @@ -508,11 +508,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { describe('with $ref in oneOf', () => { it('should retrieve referenced schemas', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - false, // First oneOf... second !== first - true, // Second oneOf... second === second + data: [ + { errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... second !== first + { errors: [], errorSchema: {} }, // Second oneOf... second === second ], }); const schema: RJSFSchema = { @@ -576,11 +576,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { describe('true condition', () => { it('should add `first` properties given `first` data', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - true, // First dependency... first === first - false, // Second dependency... second !== first + data: [ + { errors: [], errorSchema: {} }, // First dependency... first === first + { errors: [{ stack: 'error' }], errorSchema: {} }, // Second dependency... second !== first ], }); const schema: RJSFSchema = { @@ -598,11 +598,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { }); it('should add `second` properties given `second` data', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - false, // First dependency... first !== second - true, // Second dependency... second === second + data: [ + { errors: [{ stack: 'error' }], errorSchema: {} }, // First dependency... first !== second + { errors: [], errorSchema: {} }, // Second dependency... second === second ], }); const schema: RJSFSchema = { @@ -628,13 +628,13 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { }); it('should not include nested dependencies that should be hidden', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - false, // employee_accounts oneOf ... - fail - true, // update_absences first oneOf... success - false, // update_absences second oneOf... fail - false, // update_absences third oneOf... fail + data: [ + { errors: [{ stack: 'error' }], errorSchema: {} }, // employee_accounts oneOf ... - fail + { errors: [], errorSchema: {} }, // update_absences first oneOf... success + { errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences second oneOf... fail + { errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences third oneOf... fail ], }); const formData = { @@ -656,13 +656,13 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { }); it('should include nested dependencies that should not be hidden', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - true, // employee_accounts oneOf... success - true, // update_absences first oneOf... success - false, // update_absences second oneOf... fail - false, // update_absences third oneOf... fail + data: [ + { errors: [], errorSchema: {} }, // employee_accounts oneOf... success + { errors: [], errorSchema: {} }, // update_absences first oneOf... success + { errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences second oneOf... fail + { errors: [{ stack: 'error' }], errorSchema: {} }, // update_absences third oneOf... fail ], }); const formData = { @@ -698,11 +698,11 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { describe('with $ref in dependency', () => { it('should retrieve the referenced schema', () => { - // Mock isValid so that withExactlyOneSubschema works as expected + // Mock errors so that withExactlyOneSubschema works as expected testValidator.setReturnValues({ - isValid: [ - false, // First oneOf... fail - true, // Second oneOf... success + data: [ + { errors: [{ stack: 'error' }], errorSchema: {} }, // First oneOf... fail + { errors: [], errorSchema: {} }, // Second oneOf... success ], }); const schema: RJSFSchema = { From b49667828870d9397f0e673a9fdd4a8250392d5f Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 16 Dec 2024 09:43:29 +0100 Subject: [PATCH 2/5] chore: update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b014249c06..161fc4807d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ should change the heading of the (upcoming) version to include a major version b ## @rjsf/utils - Short-circuit `File` and `Date` constructor access in isObject to optimize performance in scenarios where `globalThis` is a `Proxy` that incurs overhead for each class constructor access ([#4413](https://github.com/rjsf-team/react-jsonschema-form/pull/4413)). Fixes [#4409](https://github.com/rjsf-team/react-jsonschema-form/issues/4409) +- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies. Fixes [#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418) ## @rjsf/validator-ajv8 From e41dc5b6bddd80ec481286b73ff74c66ce157e8b Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 16 Dec 2024 09:45:24 +0100 Subject: [PATCH 3/5] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 161fc4807d..77d92607ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ should change the heading of the (upcoming) version to include a major version b ## @rjsf/utils - Short-circuit `File` and `Date` constructor access in isObject to optimize performance in scenarios where `globalThis` is a `Proxy` that incurs overhead for each class constructor access ([#4413](https://github.com/rjsf-team/react-jsonschema-form/pull/4413)). Fixes [#4409](https://github.com/rjsf-team/react-jsonschema-form/issues/4409) -- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies. Fixes [#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418) +- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies ([#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418)). Fixes [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357) ## @rjsf/validator-ajv8 From 4c45995912681fdfce629310a48aafd1f9b22aa5 Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 13 Jan 2025 07:56:01 +0100 Subject: [PATCH 4/5] chore: update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f0b7e7c52..052495e46e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ should change the heading of the (upcoming) version to include a major version b ## @rjsf/utils - Fixed documentation for `getChangedFields()` +- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies ([#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418)). Fixes [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357) ## Dev / docs / playground @@ -56,7 +57,6 @@ should change the heading of the (upcoming) version to include a major version b ## @rjsf/utils - Short-circuit `File` and `Date` constructor access in isObject to optimize performance in scenarios where `globalThis` is a `Proxy` that incurs overhead for each class constructor access ([#4413](https://github.com/rjsf-team/react-jsonschema-form/pull/4413)). Fixes [#4409](https://github.com/rjsf-team/react-jsonschema-form/issues/4409) -- Rollback `isValid()` in `retrieveSchema()` to `validateFormData()` to prevent a bug with empty enums blocking dependencies ([#4418](https://github.com/rjsf-team/react-jsonschema-form/pull/4418)). Fixes [#4357](https://github.com/rjsf-team/react-jsonschema-form/issues/4357) ## @rjsf/validator-ajv8 From c7fafe1422663be590c7f8123e253ea7418ea572 Mon Sep 17 00:00:00 2001 From: cewald Date: Mon, 13 Jan 2025 07:56:27 +0100 Subject: [PATCH 5/5] fix: remove unnecessary JSON schema declaration from Form test --- packages/core/test/Form.test.jsx | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/test/Form.test.jsx b/packages/core/test/Form.test.jsx index 26b69e4265..b774049fd9 100644 --- a/packages/core/test/Form.test.jsx +++ b/packages/core/test/Form.test.jsx @@ -218,7 +218,6 @@ describeRepeated('Form common', (createFormComponent) => { it('should work with oneOf', function () { const schema = { - $schema: 'http://json-schema.org/draft-06/schema#', type: 'object', properties: { connector: {