From a75350874b82e977e548be298cc476b2992df9a3 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Fri, 10 Jan 2025 15:58:49 -0700 Subject: [PATCH] coerce string and array empty values to null/None --- app/packages/core/src/plugins/SchemaIO/index.tsx | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/packages/core/src/plugins/SchemaIO/index.tsx b/app/packages/core/src/plugins/SchemaIO/index.tsx index 6dc463ba9d..1ebcd196d4 100644 --- a/app/packages/core/src/plugins/SchemaIO/index.tsx +++ b/app/packages/core/src/plugins/SchemaIO/index.tsx @@ -20,6 +20,7 @@ export function SchemaIOComponent(props) { const onIOChange = useCallback( (path, value, schema, ancestors) => { + value = coerceValue(value, schema); const currentState = stateRef.current; const updatedState = cloneDeep(currentState); set(updatedState, path, cloneDeep(value)); @@ -63,6 +64,17 @@ export function SchemaIOComponent(props) { ); } +function coerceValue(value, schema) { + // coerce the value to None if it is an empty string or empty array + if (schema.type === "array" && Array.isArray(value) && value.length === 0) { + return null; + } + if (schema.type === "string" && value === "") { + return null; + } + return value; +} + registerComponent({ name: "SchemaIOComponent", label: "SchemaIOComponent",