Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect path selection for oneOf cases in jsonschema #10883

Merged
merged 2 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions airbyte-webapp/src/core/jsonSchema/schemaToYup.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,10 @@ test("should build schema for conditional case with inner schema and selected ui
},
},
},
{ "key.credentials": { selectedItem: "oauth" } },
{ "topKey.subKey.credentials": { selectedItem: "oauth" } },
undefined,
"key"
"topKey",
"topKey.subKey"
);

const expectedSchema = yup.object().shape({
Expand Down
18 changes: 10 additions & 8 deletions airbyte-webapp/src/core/jsonSchema/schemaToYup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,22 @@ export const buildYupFormForJsonSchema = (
| null = null;

if (jsonSchema.oneOf && uiConfig && propertyPath) {
const selectedSchema =
jsonSchema.oneOf.find((condition) => {
if (typeof condition !== "boolean") {
return uiConfig[propertyPath]?.selectedItem === condition.title;
}
return false;
}) ?? jsonSchema.oneOf[0];
let selectedSchema = jsonSchema.oneOf.find(
(condition) =>
typeof condition !== "boolean" &&
uiConfig[propertyPath]?.selectedItem === condition.title
);

// Select first oneOf path if no item selected
selectedSchema = selectedSchema ?? jsonSchema.oneOf[0];

if (selectedSchema && typeof selectedSchema !== "boolean") {
return buildYupFormForJsonSchema(
{ type: jsonSchema.type, ...selectedSchema },
uiConfig,
jsonSchema,
propertyKey,
propertyPath ? `${propertyPath}.${propertyKey}` : propertyKey
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're having the same logic two times more further down. Once inside an object and once inside the array branch. For the object the propertyKey we're actually having is not the one passed into this method, but for array it's the same as passed into, and thus the logic the same as here. Could you please explain (and give some example schemas to illustrate it), why the logic needs adjustment in this place, but for the other two calls to buildYupFormForJsonSchema further down it's the correct behavior?

Copy link
Contributor Author

@jamakase jamakase Mar 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we don't need it for oneOf case and need it for object and array cases, as we handle oneOf same way as object and array based on selected value, so we do not want to add propertyPath for oneOf cases. So we sort of try to get rid of oneOf and continue to working as with a usual schema. That's why we don't need it for oneOf.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timroes let me know if it's still unclear. I will try to provide a more accurate answer

propertyPath
);
}
}
Expand Down