From fd832f4c50fb6f2220e82b6c79e7aa51aa41270d Mon Sep 17 00:00:00 2001 From: Vitalii Yarmus Date: Thu, 6 Mar 2025 14:14:30 +0200 Subject: [PATCH] HCK-10291: fix FE of default value for numeric types --- .../helpers/convertJsonSchemaToAvro.js | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/forward_engineering/helpers/convertJsonSchemaToAvro.js b/forward_engineering/helpers/convertJsonSchemaToAvro.js index 510023b..df04e49 100644 --- a/forward_engineering/helpers/convertJsonSchemaToAvro.js +++ b/forward_engineering/helpers/convertJsonSchemaToAvro.js @@ -317,7 +317,7 @@ const handleField = (name, field) => { { name: prepareName(name), type: _.isArray(typeSchema.type) ? typeSchema.type : typeSchema, - default: getEnumDefaultValue(field, udt, typeSchema), + default: getDefaultValue(field, udt, typeSchema), doc: getDoc({ field, refDescription, description }), order, aliases, @@ -337,6 +337,12 @@ const getDoc = ({ field, refDescription, description }) => { return refDescription; }; +const getDefaultValue = (field, udt, typeSchema) => { + const defaultValue = getEnumDefaultValue(field, udt, typeSchema); + + return convertDefaultValueToTypeOfField(field, defaultValue); +}; + const getEnumDefaultValue = (field, udt, typeSchema) => { if (!_.isUndefined(field?.default) || typeSchema?.type === 'enum') { return field?.default; @@ -349,6 +355,18 @@ const getEnumDefaultValue = (field, udt, typeSchema) => { return typeSchema?.default; }; +const convertDefaultValueToTypeOfField = (field, defaultValue) => { + if (!defaultValue) { + return defaultValue; + } + + if (field.type === 'number') { + return _.toNumber(defaultValue); + } + + return defaultValue; +}; + const resolveFieldDefaultValue = (field, type) => { let udtItem = _.isString(type) && getUdtItem(type);