Skip to content

Commit b743fea

Browse files
committed
backport PR #2631 to take into account additionalProperties set to false in schema
# Conflicts: # packages/utils/src/schema/toPathSchema.ts # packages/utils/test/schema/toPathSchemaTest.ts
1 parent bd35c03 commit b743fea

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ should change the heading of the (upcoming) version to include a major version b
1616
1717
-->
1818
# v5.0.0 (coming soon)
19+
## @rjsf/utils
20+
- clear errors on formData change when liveOmit=true when "additionalProperties: false" [issue 1507](https://github.com/rjsf-team/react-jsonschema-form/issues/1507) (https://github.com/rjsf-team/react-jsonschema-form/pull/2631)
1921

2022
# 4.2.1 (upcoming)
2123

packages/utils/src/schema/toPathSchema.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ export default function toPathSchema<T = any>(
3737
$name: name.replace(/^\./, ""),
3838
} as PathSchema;
3939

40-
if (ADDITIONAL_PROPERTIES_KEY in schema) {
41-
set(pathSchema, "__rjsf_additionalProperties", true);
40+
if (ADDITIONAL_PROPERTIES_KEY in schema &&
41+
schema[ADDITIONAL_PROPERTIES_KEY] !== false) {
42+
set(pathSchema, '__rjsf_additionalProperties', true);
4243
}
4344

4445
if (ITEMS_KEY in schema && Array.isArray(formData)) {

packages/utils/test/schema/toPathSchemaTest.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ export default function toPathSchemaTest(testValidator: TestValidatorType) {
1515
$name: "",
1616
__rjsf_additionalProperties: true,
1717
});
18+
it('should return a pathSchema for root field, without additional properties', () => {
19+
const schema: RJSFSchema = { type: 'string', additionalProperties: false };
20+
21+
expect(toPathSchema(testValidator, schema)).toEqual({ $name: ''});
1822
});
19-
it("should return a pathSchema for nested objects", () => {
23+
it('should return a pathSchema for nested objects', () => {
2024
const schema: RJSFSchema = {
2125
type: "object",
2226
properties: {

0 commit comments

Comments
 (0)