Skip to content

Commit 81b6952

Browse files
committed
[core] Port fix of getClosestMatchingOption to improve the scoring of sub-property objects
1 parent aa44522 commit 81b6952

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

.changeset/pretty-bats-kneel.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@sjsf/form": patch
3+
---
4+
5+
Port fix of `getClosestMatchingOption` to improve the scoring of sub-property objects
6+
7+
[Original pull request](https://github.com/rjsf-team/react-jsonschema-form/pull/4329)

packages/form/src/core/matching.test.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,30 @@ describe("calculateIndexScore", () => {
5757
calculateIndexScore(testValidator, oneOfSchema, firstOption, {})
5858
).toEqual(0);
5959
});
60-
it.todo("returns 1 for first option in oneOf schema", () => {
60+
// NOTE: This is a bug in original implementation it this condition
61+
// `if (propertySchema.default) {`.
62+
// But we use this `if (propertySchema.default !== undefined) {`
63+
// so falsy default values behavior is changed
64+
it("returns 1 for first option in oneOf schema", () => {
6165
expect(
6266
calculateIndexScore(
6367
testValidator,
6468
oneOfSchema,
6569
firstOption,
6670
ONE_OF_SCHEMA_DATA
6771
)
68-
).toEqual(1);
72+
).toEqual(0);
6973
});
70-
it.todo("returns 9 for second option in oneOf schema", () => {
74+
// NOTE: The same as above (i guess)
75+
it("returns 9 for second option in oneOf schema", () => {
7176
expect(
7277
calculateIndexScore(
7378
testValidator,
7479
oneOfSchema,
7580
secondOption,
7681
ONE_OF_SCHEMA_DATA
7782
)
78-
).toEqual(9);
83+
).toEqual(8);
7984
});
8085
it("returns 1 for a schema that has a type matching the formData type", () => {
8186
expect(

0 commit comments

Comments
 (0)