diff --git a/CHANGELOG.md b/CHANGELOG.md index 7d7116e0ea..6c08c9d1df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,23 +15,30 @@ it according to semantic versioning. For example, if your PR adds a breaking cha should change the heading of the (upcoming) version to include a major version bump. --> + # 6.1.2 ## @rjsf/antd - Updated `SelectWidget` to add a static `getPopupContainerCallback` to the `SelectWidget` component, partially fixing [#3609](https://github.com/rjsf-team/react-jsonschema-form/issues/3609) - - Also, added the explicit `open` state to the `Select` in conjunction with providing the `setOpen` as the `onOpenChange` prop + - Also, added the explicit `open` state to the `Select` in conjunction with providing the `setOpen` as the `onOpenChange` prop +- In `BaseInputTemplate` added comments explaining why `step='1'` is returned, closing [#4022](https://github.com/rjsf-team/react-jsonschema-form/issues/4022) ## @rjsf/mantine - Align Mantine’s behavior with other themes when clearing string fields: clearing an input now removes the key from formData instead of setting it to an empty string. ([#4875](https://github.com/rjsf-team/react-jsonschema-form/pull/4875)) +## @rjsf/utils + +- Replace json-schema-merge-allof with [@x0k/json-schema-merge](https://github.com/x0k/json-schema-merge/) ([#4774](https://github.com/rjsf-team/react-jsonschema-form/issues/4774)) + ## Dev / docs / playground - Updated `DemoFrame` as follows to fix [#3609](https://github.com/rjsf-team/react-jsonschema-form/issues/3609) - Override `antd`'s `SelectWidget.getPopupContainerCallback` callback function to return undefined - Added a `AntdSelectPatcher` component that observes the creation of `antd` select dropdowns and makes sure they open in the correct location - Update the `antd` theme wrapper to render the `AntdSelectPatcher`, `AntdStyleProvider` and `ConfigProvider` with it's own `getPopupContainer()` function inside of a `FrameContextConsumer` +- Updated TypeScript configuration to use `"moduleResolution": "bundler"` # 6.1.1 @@ -197,7 +204,7 @@ should change the heading of the (upcoming) version to include a major version b - Updated the `OptionsDrawer` of the playground to add `idPrefix` and `idSeparator` fields - Updated test files to switch to using the React Testing library instead of `react-test-renderer`, updating all snapshots accordingly - Updated Fluent libraries to latest, with updated snapshots -- Added Node 24 to `ci.yml`, removing `v5` and old Node 14 non-docs builds +- Added Node 24 to `ci.yml`, removing `v5` and old Node 14 non-docs builds # 6.0.1 @@ -218,7 +225,7 @@ should change the heading of the (upcoming) version to include a major version b ## @rjsf/core - Updated `SchemaField` to add a new optional property `childFieldPathId` to the `FieldComponent` render to prevent duplicate ids, fixing (#4819)[https://github.com/rjsf-team/react-jsonschema-form/issues/4819] - - Also updated `ObjectField` and `ArrayField` to make children use the `childFieldPathId` if present, falling back to the `fieldPathId` if not + - Also updated `ObjectField` and `ArrayField` to make children use the `childFieldPathId` if present, falling back to the `fieldPathId` if not ## Dev / docs / playground @@ -245,7 +252,7 @@ should change the heading of the (upcoming) version to include a major version b - Updated `Form` to support the new feature to do `onBlur` handling of `liveValidate` and `liveOmit` - Updated `FormProps` to add the new `initialFormData` prop - Updated `Form` so that is behaves as a "controlled" form when `formData` is passed and uncontrolled when `initialFormData` is passed, fixing [#391](https://github.com/rjsf-team/react-jsonschema-form/issues/391) - - Also fixed an issue where live validation was called on the initial form render, causing errors to show immediately, partially fixing [#512](https://github.com/rjsf-team/react-jsonschema-form/issues/512) + - Also fixed an issue where live validation was called on the initial form render, causing errors to show immediately, partially fixing [#512](https://github.com/rjsf-team/react-jsonschema-form/issues/512) - Updated `Form` to add a new programmatic function, `setFieldValue(fieldPath: string | FieldPathList, newValue?: T): void`, fixing [#2099](https://github.com/rjsf-team/react-jsonschema-form/issues/2099) - Added new `FallbackField` to add opt-in functionality to control form data that is of an unsupported or unknown type ([#4736](https://github.com/rjsf-team/react-jsonschema-form/issues/4736)). - Refactored much of the `FileWidget` implementation into a new `useFileWidgetProps()` hook, fixing [#3146](https://github.com/rjsf-team/react-jsonschema-form/issues/3146) @@ -384,7 +391,7 @@ should change the heading of the (upcoming) version to include a major version b - Updated the `customArray` sample to refactor out a `ArrayFieldItemButtonsTemplate` - Updated the `custom-templates.md` documentation to reflect the `additionalProperties`-based interface props replacement and `ArrayField` conversion changes - Updated the `utility-functions.md` documentation to add the new `useDeepCompareMemo()` hook -- Updated the `v6.x upgrade guide.md` documentation to add the BREAKING CHANGES to the `ArrayFieldTemplateProps`, `ArrayFieldItemTemplateType`, `ArrayFieldItemButtonsTemplateType`, `FieldTemplateProps`, `ObjectFieldTemplateProps` and `WrapIfAdditionalTemplateProps` interface props changes and the `useDeepCompareMemo()` hook +- Updated the `v6.x upgrade guide.md` documentation to add the BREAKING CHANGES to the `ArrayFieldTemplateProps`, `ArrayFieldItemTemplateType`, `ArrayFieldItemButtonsTemplateType`, `FieldTemplateProps`, `ObjectFieldTemplateProps` and `WrapIfAdditionalTemplateProps` interface props changes and the `useDeepCompareMemo()` hook - Added documentation for the `nameGenerator` prop in `form-props.md` and v6.x upgrade guide - Updated `@rjsf/snapshot-tests` package to explicitly depend on `@rjsf/core` to build first, fixing an error with parallelized builds @@ -411,11 +418,11 @@ should change the heading of the (upcoming) version to include a major version b - Updated `ArrayFieldTemplate`, `ObjectFieldTemplate`, `TitleField` to add support for the new `optionalDataControl` feature - Added the new `OptionalDataControlTemplate` to the theme, adding it to the `templates` list - Updated `Form` as follows to fix [#4796](https://github.com/rjsf-team/react-jsonschema-form/issues/4796) - - Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()` - - Added new, optional `customErrors?: ErrorSchemaBuilder` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables - - Reworked the `newErrorSchema` handling in `processPendingChange()` to simplify the handling since `newErrorSchema` is now path-specific, adding `newErrorSchema` to `customErrors` when they don't match an existing validator-based validation - - This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage - - Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods + - Refactored the `liveValidate()` and `mergeErrors()` functions out of `getStateFromProp()` and `processPendingChange()` + - Added new, optional `customErrors?: ErrorSchemaBuilder` to the `FormState`, updating the `IChangeEvent` interface to remove all of the private variables + - Reworked the `newErrorSchema` handling in `processPendingChange()` to simplify the handling since `newErrorSchema` is now path-specific, adding `newErrorSchema` to `customErrors` when they don't match an existing validator-based validation + - This rework resulted in any custom errors passed from custom widgets/fields will now be remembered during the validation stage + - Removed the now unused `getPreviousCustomValidateErrors()` and `filterErrorsBasedOnSchema()` methods - Updated `LayoutGridField` to simplify `onFieldChange()` to just return the given `errorSchema` now that it is path-specific, fixing [#4796](https://github.com/rjsf-team/react-jsonschema-form/issues/4796) - Updated `NullField` to pass `fieldPathId.path` for the `onChange()` instead of `[name]` @@ -476,7 +483,7 @@ should change the heading of the (upcoming) version to include a major version b - Updated `GlobalFormOptions` to add new `enableOptionalDataFieldForType?: ('object' | 'array')[]` prop - Updated `SchemaUtilsType`'s `retrieveSchema()` function to add an additional, property `resolveAnyOfOrOneOfRefs?: boolean` - Updated the `Templates` interface to add a new required template `OptionalDataControlsTemplate: ComponentType>` -- Updated `retrieveSchema()` to add an additional property `resolveAnyOfOrOneOfRefs?: boolean` which causes `resolveAllSchemas()` to resolve `$ref`s inside of the options of `anyOf`/`oneOf` schemas +- Updated `retrieveSchema()` to add an additional property `resolveAnyOfOrOneOfRefs?: boolean` which causes `resolveAllSchemas()` to resolve `$ref`s inside of the options of `anyOf`/`oneOf` schemas - Updated `getDefaultFormState` to fix an issue where optional array props had their default set to an empty array when they shouldn't be - Updated the `TranslatableString` enum to add three new strings in support of the new feature: `OptionalObjectAdd`, `OptionalObjectRemove` and `OptionalObjectEmptyMsg` - Added four new utility functions: `isFormDataAvailable()`, `isRootSchema()`, `optionalControlsId()`, and `shouldRenderOptionalField()` diff --git a/package-lock.json b/package-lock.json index 8be20673e3..a4ded2f55a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12999,16 +12999,6 @@ "integrity": "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==", "license": "MIT" }, - "node_modules/@types/json-schema-merge-allof": { - "version": "0.6.5", - "resolved": "https://registry.npmjs.org/@types/json-schema-merge-allof/-/json-schema-merge-allof-0.6.5.tgz", - "integrity": "sha512-5mS11ZUTyFNUVEMpK3uKoPb6BWL/nLgW/ln2VOiI8OOxKEYC4Gl9O3WjS5P49yqVTfkcbCAPKw3T1O4erUah5g==", - "dev": true, - "license": "MIT", - "dependencies": { - "@types/json-schema": "*" - } - }, "node_modules/@types/json5": { "version": "0.0.29", "resolved": "https://registry.npmjs.org/@types/json5/-/json5-0.0.29.tgz", @@ -14108,6 +14098,15 @@ "@xtuc/long": "4.2.2" } }, + "node_modules/@x0k/json-schema-merge": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/@x0k/json-schema-merge/-/json-schema-merge-1.0.2.tgz", + "integrity": "sha512-1734qiJHNX3+cJGDMMw2yz7R+7kpbAtl5NdPs1c/0gO5kYT6s4dMbLXiIfpZNsOYhGZI3aH7FWrj4Zxz7epXNg==", + "license": "MIT", + "dependencies": { + "@types/json-schema": "^7.0.15" + } + }, "node_modules/@xtuc/ieee754": { "version": "1.2.0", "resolved": "https://registry.npmjs.org/@xtuc/ieee754/-/ieee754-1.2.0.tgz", @@ -17489,27 +17488,6 @@ ], "license": "MIT" }, - "node_modules/compute-gcd": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/compute-gcd/-/compute-gcd-1.2.1.tgz", - "integrity": "sha512-TwMbxBNz0l71+8Sc4czv13h4kEqnchV9igQZBi6QUaz09dnz13juGnnaWWJTRsP3brxOoxeB4SA2WELLw1hCtg==", - "dependencies": { - "validate.io-array": "^1.0.3", - "validate.io-function": "^1.0.2", - "validate.io-integer-array": "^1.0.0" - } - }, - "node_modules/compute-lcm": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/compute-lcm/-/compute-lcm-1.1.2.tgz", - "integrity": "sha512-OFNPdQAXnQhDSKioX8/XYT6sdUlXwpeMjfd6ApxMJfyZ4GxmLR1xvMERctlYhlHwIiz6CSpBc2+qYKjHGZw4TQ==", - "dependencies": { - "compute-gcd": "^1.2.1", - "validate.io-array": "^1.0.3", - "validate.io-function": "^1.0.2", - "validate.io-integer-array": "^1.0.0" - } - }, "node_modules/compute-scroll-into-view": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/compute-scroll-into-view/-/compute-scroll-into-view-3.1.1.tgz", @@ -24733,29 +24711,6 @@ "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==", "license": "(AFL-2.1 OR BSD-3-Clause)" }, - "node_modules/json-schema-compare": { - "version": "0.2.2", - "resolved": "https://registry.npmjs.org/json-schema-compare/-/json-schema-compare-0.2.2.tgz", - "integrity": "sha512-c4WYmDKyJXhs7WWvAWm3uIYnfyWFoIp+JEoX34rctVvEkMYCPGhXtvmFFXiffBbxfZsvQ0RNnV5H7GvDF5HCqQ==", - "license": "MIT", - "dependencies": { - "lodash": "^4.17.4" - } - }, - "node_modules/json-schema-merge-allof": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/json-schema-merge-allof/-/json-schema-merge-allof-0.8.1.tgz", - "integrity": "sha512-CTUKmIlPJbsWfzRRnOXz+0MjIqvnleIXwFTzz+t9T86HnYX/Rozria6ZVGLktAU9e+NygNljveP+yxqtQp/Q4w==", - "license": "MIT", - "dependencies": { - "compute-lcm": "^1.1.2", - "json-schema-compare": "^0.2.2", - "lodash": "^4.17.20" - }, - "engines": { - "node": ">=12.0.0" - } - }, "node_modules/json-schema-traverse": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz", @@ -37335,39 +37290,6 @@ "spdx-expression-parse": "^3.0.0" } }, - "node_modules/validate.io-array": { - "version": "1.0.6", - "resolved": "https://registry.npmjs.org/validate.io-array/-/validate.io-array-1.0.6.tgz", - "integrity": "sha512-DeOy7CnPEziggrOO5CZhVKJw6S3Yi7e9e65R1Nl/RTN1vTQKnzjfvks0/8kQ40FP/dsjRAOd4hxmJ7uLa6vxkg==", - "license": "MIT" - }, - "node_modules/validate.io-function": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/validate.io-function/-/validate.io-function-1.0.2.tgz", - "integrity": "sha512-LlFybRJEriSuBnUhQyG5bwglhh50EpTL2ul23MPIuR1odjO7XaMLFV8vHGwp7AZciFxtYOeiSCT5st+XSPONiQ==" - }, - "node_modules/validate.io-integer": { - "version": "1.0.5", - "resolved": "https://registry.npmjs.org/validate.io-integer/-/validate.io-integer-1.0.5.tgz", - "integrity": "sha512-22izsYSLojN/P6bppBqhgUDjCkr5RY2jd+N2a3DCAUey8ydvrZ/OkGvFPR7qfOpwR2LC5p4Ngzxz36g5Vgr/hQ==", - "dependencies": { - "validate.io-number": "^1.0.3" - } - }, - "node_modules/validate.io-integer-array": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/validate.io-integer-array/-/validate.io-integer-array-1.0.0.tgz", - "integrity": "sha512-mTrMk/1ytQHtCY0oNO3dztafHYyGU88KL+jRxWuzfOmQb+4qqnWmI+gykvGp8usKZOM0H7keJHEbRaFiYA0VrA==", - "dependencies": { - "validate.io-array": "^1.0.3", - "validate.io-integer": "^1.0.4" - } - }, - "node_modules/validate.io-number": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/validate.io-number/-/validate.io-number-1.0.3.tgz", - "integrity": "sha512-kRAyotcbNaSYoDnXvb4MHg/0a1egJdLwS6oJ38TJY7aw9n93Fl/3blIXdyYvPOp55CNxywooG/3BcrwNrBpcSg==" - }, "node_modules/value-equal": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/value-equal/-/value-equal-1.0.1.tgz", @@ -39512,8 +39434,8 @@ "version": "6.1.1", "license": "Apache-2.0", "dependencies": { + "@x0k/json-schema-merge": "^1.0.2", "fast-uri": "^3.1.0", - "json-schema-merge-allof": "^0.8.1", "jsonpointer": "^5.0.1", "lodash": "^4.17.21", "lodash-es": "^4.17.21", @@ -39521,7 +39443,6 @@ }, "devDependencies": { "@types/json-schema": "^7.0.15", - "@types/json-schema-merge-allof": "^0.6.5", "@types/react-is": "^18.3.1", "deep-freeze-es6": "^4.0.1", "eslint": "^8.57.1" diff --git a/packages/antd/jest.config.json b/packages/antd/jest.config.json index 483e2e9995..cbc5cacf01 100644 --- a/packages/antd/jest.config.json +++ b/packages/antd/jest.config.json @@ -8,5 +8,5 @@ "moduleNameMapper": { "\\.(css|less)$": "/__mocks__/styleMock.js" }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/chakra-ui/jest.config.json b/packages/chakra-ui/jest.config.json index a02e49efed..35eb7e3ffa 100644 --- a/packages/chakra-ui/jest.config.json +++ b/packages/chakra-ui/jest.config.json @@ -5,5 +5,5 @@ "browsers": ["chrome", "firefox", "safari"] }, "setupFilesAfterEnv": ["./test/setup-jest-env.js", "../../testing/testSetup.ts"], - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/core/jest.config.json b/packages/core/jest.config.json index fe2278893a..bb89ed3107 100644 --- a/packages/core/jest.config.json +++ b/packages/core/jest.config.json @@ -3,5 +3,5 @@ "testEnvironment": "jsdom", "setupFilesAfterEnv": ["./test/setup-jest-env.js", "../../testing/testSetup.ts"], "testMatch": ["**/test/**/*.test.[jt]s?(x)"], - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/daisyui/jest.config.json b/packages/daisyui/jest.config.json index 2560a52ee6..ec3b767fe2 100644 --- a/packages/daisyui/jest.config.json +++ b/packages/daisyui/jest.config.json @@ -6,9 +6,7 @@ "^.+\\.(t|j)sx?$": "babel-jest" }, "coveragePathIgnorePatterns": ["/node_modules/", "/test/"], - "transformIgnorePatterns": [ - "/node_modules/(?!(@fortawesome|yup|react-day-picker|dayjs|deep-freeze-es6)/)" - ], + "transformIgnorePatterns": ["/node_modules/(?!(@x0k|@fortawesome|yup|react-day-picker|dayjs|deep-freeze-es6)/)"], "moduleNameMapper": { "\\.(css|less|scss|sass)$": "/test/fileMock.js" } diff --git a/packages/docs/docs/advanced-customization/internals.md b/packages/docs/docs/advanced-customization/internals.md index 79130b4152..1aba2a38d9 100644 --- a/packages/docs/docs/advanced-customization/internals.md +++ b/packages/docs/docs/advanced-customization/internals.md @@ -16,7 +16,7 @@ This component follows [JSON Schema](http://json-schema.org/documentation.html) You can also use `oneOf` with [schema dependencies](../json-schema/dependencies.md#schema-dependencies) to dynamically add schema properties based on input data. - The `allOf` keyword is supported; it uses [json-schema-merge-allof](https://github.com/mokkabonna/json-schema-merge-allof) to merge subschemas to render the final combined schema in the form. When these subschemas are incompatible, though (or if the library has an error merging it), the `allOf` keyword is dropped from the schema. + The `allOf` keyword is supported; it uses [@x0k/json-schema-merge](https://github.com/x0k/json-schema-merge/) to merge subschemas to render the final combined schema in the form. When these subschemas are incompatible, though (or if the library has an error merging it), the `allOf` keyword is dropped from the schema. - `"additionalProperties":false` produces incorrect schemas when used with [schema dependencies](../json-schema/dependencies.md#schema-dependencies). This library does not remove extra properties, which causes validation to fail. It is recommended to avoid setting `"additionalProperties":false` when you use schema dependencies. See [#848](https://github.com/rjsf-team/react-jsonschema-form/issues/848) [#902](https://github.com/rjsf-team/react-jsonschema-form/issues/902) [#992](https://github.com/rjsf-team/react-jsonschema-form/issues/992) diff --git a/packages/docs/docs/api-reference/form-props.md b/packages/docs/docs/api-reference/form-props.md index 0b4c5eca9d..5c34688aef 100644 --- a/packages/docs/docs/api-reference/form-props.md +++ b/packages/docs/docs/api-reference/form-props.md @@ -284,7 +284,7 @@ NOTE: If there is a default for a field and the `formData` is unspecified, the d ## experimental_customMergeAllOf -The `experimental_customMergeAllOf` function allows you to provide a custom implementation for merging `allOf` schemas. This can be particularly useful in scenarios where the default [json-schema-merge-allof](https://github.com/mokkabonna/json-schema-merge-allof) library becomes a performance bottleneck, especially with large and complex schemas or doesn't satisfy your needs. +The `experimental_customMergeAllOf` function allows you to provide a custom implementation for merging `allOf` schemas. This can be particularly useful in case the where the default merge library ([@x0k/json-schema-merge](https://github.com/x0k/json-schema-merge/)) doesn't satisfy your functional or performance requirements. By providing your own implementation, you can potentially achieve significant performance improvements. For instance, if your use case only requires a subset of JSON Schema features, you can implement a faster, more tailored merging strategy. diff --git a/packages/docs/docs/json-schema/oneof.md b/packages/docs/docs/json-schema/oneof.md index d2545af72c..fb2f93858f 100644 --- a/packages/docs/docs/json-schema/oneof.md +++ b/packages/docs/docs/json-schema/oneof.md @@ -72,7 +72,7 @@ render(
, document.getElementById(' ## allOf -When `allOf` is specified in a schema, react-jsonschema-form uses the [json-schema-merge-allof](https://github.com/mokkabonna/json-schema-merge-allof) library to merge the specified subschemas to create a combined subschema that is valid. For example, the below schema evaluates to a combined subschema of `{type: "boolean"}`: +When `allOf` is specified in a schema, react-jsonschema-form uses the [@x0k/json-schema-merge](https://github.com/x0k/json-schema-merge/) library to merge the specified subschemas to create a combined subschema that is valid. For example, the below schema evaluates to a combined subschema of `{type: "boolean"}`: ```tsx import { RJSFSchema } from '@rjsf/utils'; diff --git a/packages/fluentui-rc/jest.config.json b/packages/fluentui-rc/jest.config.json index 94800ea7c9..a6d665e177 100644 --- a/packages/fluentui-rc/jest.config.json +++ b/packages/fluentui-rc/jest.config.json @@ -5,5 +5,5 @@ "testEnvironmentOptions": { "browsers": ["chrome", "firefox", "safari"] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/mantine/jest.config.json b/packages/mantine/jest.config.json index faa94b40a0..9144c40f49 100644 --- a/packages/mantine/jest.config.json +++ b/packages/mantine/jest.config.json @@ -7,5 +7,5 @@ "testEnvironmentOptions": { "browsers": ["chrome", "firefox", "safari"] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/mui/jest.config.json b/packages/mui/jest.config.json index 94800ea7c9..a6d665e177 100644 --- a/packages/mui/jest.config.json +++ b/packages/mui/jest.config.json @@ -5,5 +5,5 @@ "testEnvironmentOptions": { "browsers": ["chrome", "firefox", "safari"] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/primereact/jest.config.json b/packages/primereact/jest.config.json index e2187d7daa..b1c38fec77 100644 --- a/packages/primereact/jest.config.json +++ b/packages/primereact/jest.config.json @@ -3,7 +3,7 @@ "transform": { "^.+\\.(ts|tsx|js|jsx)$": ["babel-jest", { "configFile": "./babel.config.json" }] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"], + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"], "moduleNameMapper": { "^@/(.*)$": "/src/$1" }, diff --git a/packages/react-bootstrap/jest.config.json b/packages/react-bootstrap/jest.config.json index 63e821c7fe..ff0a06c4b7 100644 --- a/packages/react-bootstrap/jest.config.json +++ b/packages/react-bootstrap/jest.config.json @@ -4,5 +4,5 @@ "testEnvironmentOptions": { "browsers": ["chrome", "firefox", "safari"] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/semantic-ui/jest.config.json b/packages/semantic-ui/jest.config.json index 958c02aed1..cad31fd986 100644 --- a/packages/semantic-ui/jest.config.json +++ b/packages/semantic-ui/jest.config.json @@ -2,5 +2,5 @@ "verbose": true, "setupFilesAfterEnv": ["../../testing/testSetup.ts"], "testEnvironment": "jsdom", - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"] + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"] } diff --git a/packages/shadcn/jest.config.json b/packages/shadcn/jest.config.json index cd30dafd16..ed2ee9d8c4 100644 --- a/packages/shadcn/jest.config.json +++ b/packages/shadcn/jest.config.json @@ -4,7 +4,7 @@ "transform": { "^.+\\.(ts|tsx|js|jsx)$": ["babel-jest", { "configFile": "./babel.config.json" }] }, - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"], + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"], "moduleNameMapper": { "^@/(.*)$": "/src/$1" } diff --git a/packages/utils/jest.config.json b/packages/utils/jest.config.json index 0ea1b41ecb..e781a46b3c 100644 --- a/packages/utils/jest.config.json +++ b/packages/utils/jest.config.json @@ -6,7 +6,7 @@ "browsers": ["chrome", "firefox", "safari"] }, "testMatch": ["**/test/**/*.test.ts?(x)"], - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"], + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6)/)"], "coverageDirectory": "/coverage/", "collectCoverage": true, "coveragePathIgnorePatterns": ["/node_modules/", "/test"], diff --git a/packages/utils/package.json b/packages/utils/package.json index 3fe111ff04..18320221d6 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -65,8 +65,8 @@ "react": ">=18" }, "dependencies": { + "@x0k/json-schema-merge": "^1.0.2", "fast-uri": "^3.1.0", - "json-schema-merge-allof": "^0.8.1", "jsonpointer": "^5.0.1", "lodash": "^4.17.21", "lodash-es": "^4.17.21", @@ -74,7 +74,6 @@ }, "devDependencies": { "@types/json-schema": "^7.0.15", - "@types/json-schema-merge-allof": "^0.6.5", "@types/react-is": "^18.3.1", "deep-freeze-es6": "^4.0.1", "eslint": "^8.57.1" diff --git a/packages/utils/src/schema/retrieveSchema.ts b/packages/utils/src/schema/retrieveSchema.ts index f46d7b4a80..9725df265b 100644 --- a/packages/utils/src/schema/retrieveSchema.ts +++ b/packages/utils/src/schema/retrieveSchema.ts @@ -5,7 +5,9 @@ import transform from 'lodash/transform'; import merge from 'lodash/merge'; import flattenDeep from 'lodash/flattenDeep'; import uniq from 'lodash/uniq'; -import mergeAllOf, { Options } from 'json-schema-merge-allof'; +import isEmpty from 'lodash/isEmpty'; +import { createComparator, createMerger, createShallowAllOfMerge } from '@x0k/json-schema-merge'; +import { createDeduplicator, createIntersector } from '@x0k/json-schema-merge/lib/array'; import { ADDITIONAL_PROPERTIES_KEY, @@ -36,7 +38,6 @@ import { } from '../types'; import getFirstMatchingOption from './getFirstMatchingOption'; import deepEquals from '../deepEquals'; -import isEmpty from 'lodash/isEmpty'; /** Retrieves an expanded schema that has had all of its conditions, additional properties, references and dependencies * resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` that is used to do the @@ -512,6 +513,24 @@ export function stubExistingAdditionalProperties< return schema; } +// Set up @x0k/json-schema-merge utilities +const { compareSchemaDefinitions, compareSchemaValues } = createComparator(); +const { mergeArrayOfSchemaDefinitions } = createMerger({ + intersectJson: createIntersector(compareSchemaValues), + deduplicateJsonSchemaDef: createDeduplicator(compareSchemaDefinitions), +}); + +const shallowAllOfMerge = createShallowAllOfMerge(mergeArrayOfSchemaDefinitions); + +/** + * Internal helper that merges allOf schemas using @x0k/json-schema-merge's shallow allOf merge + * @param schema - The schema containing an `allOf` keyword + * @returns The schema with allOf schemas merged + */ +function mergeAllOf(schema: S): S { + return shallowAllOfMerge(schema) as S; +} + /** Internal handler that retrieves an expanded schema that has had all of its conditions, additional properties, * references and dependencies resolved and merged into the `schema` given a `validator`, `rootSchema` and `rawFormData` * that is used to do the potentially recursive resolution. If `expandAllBranches` is true, then all possible branches @@ -590,12 +609,7 @@ export function retrieveSchemaInternal< } resolvedSchema = experimental_customMergeAllOf ? experimental_customMergeAllOf(resolvedSchema) - : (mergeAllOf(resolvedSchema, { - deep: false, - resolvers: { - $defs: mergeAllOf.options.resolvers.definitions, - }, - } as Options) as S); + : mergeAllOf(resolvedSchema); if (withContainsSchemas.length) { resolvedSchema.allOf = withContainsSchemas; } diff --git a/packages/utils/test/schema/retrieveSchemaTest.ts b/packages/utils/test/schema/retrieveSchemaTest.ts index 705ada8146..ec65dfce59 100644 --- a/packages/utils/test/schema/retrieveSchemaTest.ts +++ b/packages/utils/test/schema/retrieveSchemaTest.ts @@ -1097,7 +1097,7 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { }, food: { type: 'string', enum: ['meat', 'grass', 'fish'] }, }, - required: ['animal', 'food'], + required: ['food', 'animal'], }); }); it('should resolve multiple conditions in nested allOf blocks', () => { @@ -1262,7 +1262,7 @@ export default function retrieveSchemaTest(testValidator: TestValidatorType) { }, food: { type: 'string', enum: ['meat', 'grass', 'fish'] }, }, - required: ['animal', 'food'], + required: ['food', 'animal'], }); }); it('handles nested if then else', () => { diff --git a/packages/validator-ajv8/jest.config.json b/packages/validator-ajv8/jest.config.json index 0bd26445aa..670b57a42b 100644 --- a/packages/validator-ajv8/jest.config.json +++ b/packages/validator-ajv8/jest.config.json @@ -5,7 +5,7 @@ "browsers": ["chrome", "firefox", "safari"] }, "testMatch": ["**/test/**/*.test.ts?(x)"], - "transformIgnorePatterns": ["/node_modules/(?!deep-freeze-es6)"], + "transformIgnorePatterns": ["/node_modules/(?!(@x0k/json-schema-merge|deep-freeze-es6))"], "coverageDirectory": "/coverage/", "collectCoverage": true, "coveragePathIgnorePatterns": ["/node_modules/", "/test"], diff --git a/packages/validator-ajv8/test/utilsTests/getTestValidator.ts b/packages/validator-ajv8/test/utilsTests/getTestValidator.ts index 1f2e9589f5..937e94f4cb 100644 --- a/packages/validator-ajv8/test/utilsTests/getTestValidator.ts +++ b/packages/validator-ajv8/test/utilsTests/getTestValidator.ts @@ -1,6 +1,5 @@ import { CustomValidator, ErrorTransformer, RJSFSchema, ValidationData } from '@rjsf/utils'; -// With Lerna active, the test world has access to the test suite via the symlink -import { TestValidatorType } from '@rjsf/utils/test/schema'; +import { TestValidatorType } from '../../../utils/test/schema'; import { customizeValidator, CustomValidatorOptionsType } from '../../src'; /** In this environment, a test validator merely creates an internal `AJV8` validator with the custom `options` and diff --git a/tsconfig.base.json b/tsconfig.base.json index f118c6fe64..c5ed96db58 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -20,7 +20,7 @@ "noImplicitReturns": true, "noFallthroughCasesInSwitch": true, "allowSyntheticDefaultImports": true, - "moduleResolution": "node", + "moduleResolution": "bundler", "isolatedModules": true, "jsx": "react-jsx", "esModuleInterop": true,