diff --git a/packages/openneuro-server/src/datalad/description.ts b/packages/openneuro-server/src/datalad/description.ts index 0e8c23c07..4e321baf8 100644 --- a/packages/openneuro-server/src/datalad/description.ts +++ b/packages/openneuro-server/src/datalad/description.ts @@ -58,8 +58,22 @@ export const repairDescriptionTypes = (description) => { for (const field of arrayStringFields) { if (Object.hasOwn(description, field)) { if (!isArrayOfStrings(description[field])) { - // If it's not an array of strings (or not an array at all), replace with an empty array - newDescription[field] = [] + // Check if the array is corrupted + if (Array.isArray(description[field])) { + newDescription[field] = description[field] + .map((item) => { + // If item is an object with a 'name' field (DataCite contributor), extract the name. + if (typeof item === "object" && item !== null && item.name) { + return String(item.name) + } + // Otherwise, attempt to stringify the item + return String(item) + }) + .filter((s) => typeof s === "string" && s.trim().length > 0) + } else { + // If it's not an array at all (original logic) + newDescription[field] = [] + } } // If it is already a valid array of strings, no change is needed. }