Skip to content

Commit 1b85ff7

Browse files
authored
Fix incorrect path selection for oneOf cases in jsonschema (#10883)
* Fix incorrect path selection for oneOf cases in jsonschema
1 parent 56bf982 commit 1b85ff7

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

airbyte-webapp/src/core/jsonSchema/schemaToYup.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ test("should build schema for conditional case with inner schema and selected ui
138138
},
139139
},
140140
},
141-
{ "key.credentials": { selectedItem: "oauth" } },
141+
{ "topKey.subKey.credentials": { selectedItem: "oauth" } },
142142
undefined,
143-
"key"
143+
"topKey",
144+
"topKey.subKey"
144145
);
145146

146147
const expectedSchema = yup.object().shape({

airbyte-webapp/src/core/jsonSchema/schemaToYup.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,22 @@ export const buildYupFormForJsonSchema = (
3434
| null = null;
3535

3636
if (jsonSchema.oneOf && uiConfig && propertyPath) {
37-
const selectedSchema =
38-
jsonSchema.oneOf.find((condition) => {
39-
if (typeof condition !== "boolean") {
40-
return uiConfig[propertyPath]?.selectedItem === condition.title;
41-
}
42-
return false;
43-
}) ?? jsonSchema.oneOf[0];
37+
let selectedSchema = jsonSchema.oneOf.find(
38+
(condition) =>
39+
typeof condition !== "boolean" &&
40+
uiConfig[propertyPath]?.selectedItem === condition.title
41+
);
42+
43+
// Select first oneOf path if no item selected
44+
selectedSchema = selectedSchema ?? jsonSchema.oneOf[0];
45+
4446
if (selectedSchema && typeof selectedSchema !== "boolean") {
4547
return buildYupFormForJsonSchema(
4648
{ type: jsonSchema.type, ...selectedSchema },
4749
uiConfig,
4850
jsonSchema,
4951
propertyKey,
50-
propertyPath ? `${propertyPath}.${propertyKey}` : propertyKey
52+
propertyPath
5153
);
5254
}
5355
}

0 commit comments

Comments
 (0)