Skip to content

Commit

Permalink
required array is removed when changing types and removing a property
Browse files Browse the repository at this point in the history
  • Loading branch information
Gmin2 committed Jun 4, 2024
1 parent a08b46d commit 3648dc0
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions packages/ui/components/VisualEditor/SchemaObject.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,26 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({
} else {
_.unset(updatedSchema, normalizedPath);
}

const propertyName = normalizedPath.split(".").pop();
console.log("propertyName", propertyName)
console.log("updatedSchema.properties.required", updatedSchema)
console.log("normalizedPath", normalizedPath)
const parentPath = normalizedPath.slice(
0,
normalizedPath.lastIndexOf(".")
);
const schemaPath = parentPath.split('.properties');
const requiredPath = schemaPath.slice(0, -1).join('.properties') + '.required';
const nestedRequired = _.get(updatedSchema, requiredPath, []);

if (nestedRequired.includes(propertyName)) {
_.set(
updatedSchema,
requiredPath,
nestedRequired.filter((requiredProp: string) => requiredProp !== propertyName)
);
}
console.log("updatedSchema", JSON.stringify(updatedSchema))
onSchemaChange(updatedSchema);
};
Expand All @@ -68,6 +88,15 @@ const SchemaObject: React.FC<SchemaObjectProps> = ({
_.set(currentSchema, typePath , newTypeValue);
const itemsPath = `${normalizedPath}.items`;
_.unset(currentSchema, itemsPath);

const propertyName = normalizedPath.split(".").slice(-1)[0];
const parentPath = normalizedPath.slice(0, normalizedPath.lastIndexOf('.'));
const requiredPath = `${parentPath}.${propertyName}.required`;
const nestedRequired = _.get(currentSchema, requiredPath, []);

if (nestedRequired?.length > 0 ) {
_.unset(currentSchema, requiredPath);
}
}
_.unset(currentSchema, `${normalizedPath}.properties`)

Expand Down

0 comments on commit 3648dc0

Please sign in to comment.