diff --git a/forward_engineering/dbtProvider.js b/forward_engineering/dbtProvider.js index 5aeaea9..30aaabb 100644 --- a/forward_engineering/dbtProvider.js +++ b/forward_engineering/dbtProvider.js @@ -21,9 +21,8 @@ class DbtProvider { */ decorateType({ columnDefinition }) { const type = columnHelper.getTypeByProperty([], '')(columnDefinition); - const isComplexType = /^(array|struct)/i.test(type); - return isComplexType ? type.replace(/<[\s\S]+>$/, '<>') : type; + return columnHelper.clearComplexStructure({ type }); } /** diff --git a/forward_engineering/helpers/columnHelper.js b/forward_engineering/helpers/columnHelper.js index 490a34f..f274725 100644 --- a/forward_engineering/helpers/columnHelper.js +++ b/forward_engineering/helpers/columnHelper.js @@ -385,9 +385,30 @@ const getDescription = (definitions, property) => { return property.refDescription || property.description || definitionDescription; }; +/** + * @param {{ type: string }} + * @returns {string} + */ +const clearComplexStructure = ({ type }) => { + const isArray = /^array/i.test(type); + const isStruct = /^struct/i.test(type); + const isComplexType = isArray || isStruct; + + if (!isComplexType) { + return type; + } + + const structureRegExp = /<([\s\S]+)>$/; + const [, subType] = structureRegExp.exec(type) ?? ['', '']; + const structure = isArray ? clearComplexStructure({ type: subType }) : ''; + + return type.replace(structureRegExp, () => `<${structure}>`); +}; + module.exports = { getColumns, getColumnsStatement, getColumnStatement, getTypeByProperty, + clearComplexStructure, };