diff --git a/languages/cpp/templates/parameter-serialization/array.cpp b/languages/cpp/templates/parameter-serialization/array.cpp index d45916ab..e6559cfb 100644 --- a/languages/cpp/templates/parameter-serialization/array.cpp +++ b/languages/cpp/templates/parameter-serialization/array.cpp @@ -1,7 +1,7 @@ - WPEFramework::Core::JSON::ArrayType ${Property}; + WPEFramework::Core::JSON::ArrayType ${property}Array; for (auto& element : ${property}) { -${if.object}${items.with.indent}${end.if.object}${if.non.object}${Property}.Add() = element;${end.if.non.object} +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}Array.Add() = element;${end.if.non.object} } - WPEFramework::Core::JSON::Variant ${Property}Variant; - ${Property}Variant.Array(${Property}); - jsonParameters.Set(_T("${property}"), ${Property}Variant); + WPEFramework::Core::JSON::Variant ${property}Variant; + ${property}Variant.Array(${property}Array); + jsonParameters.Set(_T("${property}"), ${property}Variant); \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/enum.cpp b/languages/cpp/templates/parameter-serialization/enum.cpp index 991ea807..015c6bc6 100644 --- a/languages/cpp/templates/parameter-serialization/enum.cpp +++ b/languages/cpp/templates/parameter-serialization/enum.cpp @@ -1,3 +1,3 @@ ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property}${if.optional}.value()${end.if.optional}; - WPEFramework::Core::JSON::Variant ${Property}(jsonValue.Data()); - jsonParameters.Set(_T("${property}"), ${Property}); + WPEFramework::Core::JSON::Variant ${property}Variant(jsonValue.Data()); + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/generic.cpp b/languages/cpp/templates/parameter-serialization/generic.cpp index 566c7354..a2e1525b 100644 --- a/languages/cpp/templates/parameter-serialization/generic.cpp +++ b/languages/cpp/templates/parameter-serialization/generic.cpp @@ -1,2 +1,2 @@ - WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional}); - jsonParameters.Set(_T("${property}"), ${Property}); + WPEFramework::Core::JSON::Variant ${property}Variant(${property}${if.optional}.value()${end.if.optional}); + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/namespace.cpp b/languages/cpp/templates/parameter-serialization/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/object-array.cpp b/languages/cpp/templates/parameter-serialization/object-array.cpp index 0965afae..e8d18cd4 100644 --- a/languages/cpp/templates/parameter-serialization/object-array.cpp +++ b/languages/cpp/templates/parameter-serialization/object-array.cpp @@ -1,7 +1,7 @@ - ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${property}Container; ${properties} - string ${Property}Str; - ${Property}Container.ToString(${Property}Str); - WPEFramework::Core::JSON::VariantContainer ${Property}VariantContainer(${Property}Str); - WPEFramework::Core::JSON::Variant ${Property}Variant = ${Property}VariantContainer; - ${Property}.Add() = ${Property}Variant; + string ${property}Str; + ${property}Container.ToString(${property}Str); + WPEFramework::Core::JSON::VariantContainer ${property}VariantContainer(${property}Str); + WPEFramework::Core::JSON::Variant ${property}Variant = ${property}VariantContainer; + ${property}Array.Add() = ${property}Variant; \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/object-empty-property.cpp b/languages/cpp/templates/parameter-serialization/object-empty-property.cpp index 566c7354..a2e1525b 100644 --- a/languages/cpp/templates/parameter-serialization/object-empty-property.cpp +++ b/languages/cpp/templates/parameter-serialization/object-empty-property.cpp @@ -1,2 +1,2 @@ - WPEFramework::Core::JSON::Variant ${Property}(${property}${if.optional}.value()${end.if.optional}); - jsonParameters.Set(_T("${property}"), ${Property}); + WPEFramework::Core::JSON::Variant ${property}Variant(${property}${if.optional}.value()${end.if.optional}); + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/object.cpp b/languages/cpp/templates/parameter-serialization/object.cpp index ef2aa794..bd627da6 100644 --- a/languages/cpp/templates/parameter-serialization/object.cpp +++ b/languages/cpp/templates/parameter-serialization/object.cpp @@ -1,8 +1,8 @@ auto element = ${property}${if.impl.optional}.value()${end.if.impl.optional}; - ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${property}Container; ${properties} - string ${Property}Str; - ${Property}Container.ToString(${Property}Str); - WPEFramework::Core::JSON::VariantContainer ${Property}VariantContainer(${Property}Str); - WPEFramework::Core::JSON::Variant ${Property} = ${Property}VariantContainer; - jsonParameters.Set(_T("${property}"), ${Property}); + string ${property}Str; + ${property}Container.ToString(${property}Str); + WPEFramework::Core::JSON::VariantContainer ${property}VariantContainer(${property}Str); + WPEFramework::Core::JSON::Variant ${property}Variant = ${property}VariantContainer; + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/property.cpp b/languages/cpp/templates/parameter-serialization/property.cpp index fbbe778a..e21d52c3 100644 --- a/languages/cpp/templates/parameter-serialization/property.cpp +++ b/languages/cpp/templates/parameter-serialization/property.cpp @@ -1 +1 @@ -${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.Title}Container.${Property} = element.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Container.${Property} = element.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp index ea65b36f..a2c3cdd1 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/anyOfSchemaShape.cpp @@ -1 +1 @@ - ${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional}; + ${base.title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional}; diff --git a/languages/cpp/templates/parameter-serialization/sub-property/array.cpp b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp index 50bbc39e..d71654b0 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/array.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp @@ -1,8 +1,6 @@ - WPEFramework::Core::JSON::ArrayType ${Property}; - ${type} ${property} = element.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}; + WPEFramework::Core::JSON::ArrayType<${json.type}> ${property}Array; + ${type} ${property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}; for (auto& element : ${property}) { -${if.object}${items.with.indent}${end.if.object}${if.non.object}${Property}.Add() = element;${end.if.non.object} +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}Array.Add() = element;${end.if.non.object} } - WPEFramework::Core::JSON::Variant ${Property}Variant; - ${Property}Variant.Array(${Property}); - jsonParameters.Set(_T("${property}"), ${Property}Variant); + ${base.title}Container.${Property.dependency}Add(_T("${property}"), &${property}Array); \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/const.cpp b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp index 498529d8..0b8a51ed 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/const.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp @@ -1 +1 @@ - ${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}.${property}${if.optional}.value()${end.if.optional}; + ${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property}${if.optional}.value()${end.if.optional}; diff --git a/languages/cpp/templates/parameter-serialization/sub-property/namespace.cpp b/languages/cpp/templates/parameter-serialization/sub-property/namespace.cpp new file mode 100644 index 00000000..b3afde8a --- /dev/null +++ b/languages/cpp/templates/parameter-serialization/sub-property/namespace.cpp @@ -0,0 +1 @@ +${if.namespace.notsame}${parent.Title}::${end.if.namespace.notsame} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp b/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp index f52f229e..bbb6fabb 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp @@ -1,7 +1,3 @@ - ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${Property}Container; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${property}Container; ${properties} - string ${Property}Str; - ${Property}Container.ToString(${Property}Str); - WPEFramework::Core::JSON::VariantContainer ${Property}VariantContainer(${Property}Str); - WPEFramework::Core::JSON::Variant ${Property}Variant = ${Property}VariantContainer; - ${Property}.Add() = ${Property}Variant; \ No newline at end of file + ${property}Array.Add() = ${property}Container; \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/property.cpp b/languages/cpp/templates/parameter-serialization/sub-property/property.cpp index a8ddffe4..81373225 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/property.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/property.cpp @@ -1 +1 @@ -${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.Title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} \ No newline at end of file +${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Container.${Property.dependency}${Property} = element${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}${if.optional}.value()${end.if.optional};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} diff --git a/languages/cpp/templates/result-instantiation/additionalProperties.cpp b/languages/cpp/templates/result-instantiation/additionalProperties.cpp index 7f10732d..2d5f03d0 100644 --- a/languages/cpp/templates/result-instantiation/additionalProperties.cpp +++ b/languages/cpp/templates/result-instantiation/additionalProperties.cpp @@ -1,4 +1,4 @@ - WPEFramework::Core::JSON::VariantContainer::Iterator variants = jsonResult.Variants(); + WPEFramework::Core::JSON::VariantContainer::Iterator variants = jsonResult.Variants(); while (variants.Next()) { ${if.not.default} ${namespace}${key} key = WPEFramework::Core::EnumerateType<${namespace}${key}>(variants.Label(), false).Value();${end.if.not.default}${if.default} ${key} key = variants.Label();${end.if.default} ${property}.emplace(std::piecewise_construct, diff --git a/languages/cpp/templates/types/anyOfSchemaShape.h b/languages/cpp/templates/types/anyOfSchemaShape.h index c239e142..93a91ea4 100644 --- a/languages/cpp/templates/types/anyOfSchemaShape.h +++ b/languages/cpp/templates/types/anyOfSchemaShape.h @@ -1 +1 @@ -/* anyOf schema shape is not supported right now */ \ No newline at end of file +/* anyOf schema shape is not supported right now */ diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index f2a8089e..a7192bcc 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -129,9 +129,10 @@ const getTemplate = (name) => { const getXSchemaGroupFromProperties = (schema, title, properties, group) => { if (properties) { Object.entries(properties).forEach(([name, prop]) => { - if (schema.title === prop.title) { + if ((schema.title === prop.title) || (prop.items && prop.items.title === schema.title)) { group = title - } else { + } + else { group = getXSchemaGroupFromProperties(schema, title, prop.properties, group) } }) @@ -173,7 +174,7 @@ function insertSchemaMacros(content, schema, module, { name = '', parent = '', p .replace(/\$\{if\.namespace\.notsame}(.*?)\$\{end\.if\.namespace\.notsame\}/g, (module.info.title !== (parent || moduleTitle)) ? '$1' : '') .replace(/\$\{parent\.title\}/g, parent || moduleTitle) .replace(/\$\{parent\.Title\}/g, capitalize(parent || moduleTitle)) - .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, required ? '' : '$1') + .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, (Array.isArray(required) ? required.includes(property) : required) ? '' : '$1') .replace(/\$\{description\}/g, schema.description ? schema.description : '') .replace(/\$\{summary\}/g, schema.description ? schema.description.split('\n')[0] : '') .replace(/\$\{name\}/g, title) @@ -282,7 +283,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = } else { options2.property = options.property } - options2.required = schema.required && schema.required.includes(name) + options2.required = schema.required const schemaShape = getSchemaShape(localizedProp, module, options2) const type = getSchemaType(localizedProp, module, options2) // don't push properties w/ unsupported types @@ -517,7 +518,9 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren shape = insertObjectMacros(getTemplate(path.join(templateDir, 'object' + (array ? '-array' : '') + suffix)) || genericTemplate, schema, module, theTitle, property, { parentLevel, level: objectLevel, parent, property, required, templateDir, descriptions, destination, section, enums, namespace: true, primitive }) } result = result.replace(/\$\{shape\}/g, shape) - result = result.replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, required ? '' : '$1') + if (level === 0) { + result = result.replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, (Array.isArray(required) ? required.includes(property) : required) ? '' : '$1') + } return insertSchemaMacros(result, schema, module, { name: theTitle, parent, property, required, templateDir }) } else if (schema.anyOf || schema.oneOf) { @@ -574,7 +577,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', paren else if (schema.type === "array" && schema.items && !Array.isArray(schema.items)) { // array const items = getSchemaShape(schema.items, module, { templateDir, parent, property, required, parentLevel: parentLevel + 1, level, summary, descriptions, destination, enums: false, array: true, primitive }) - const shape = insertArrayMacros(getTemplate(path.join(templateDir, 'array' + suffix)) || genericTemplate, schema, module, level, items, schema.required) + const shape = insertArrayMacros(getTemplate(path.join(templateDir, 'array' + suffix)) || genericTemplate, schema, module, level, items, Array.isArray(required) ? required.includes(property) : required) result = result.replace(/\$\{shape\}/g, shape) .replace(/\$\{if\.object\}(.*?)\$\{end\.if\.object\}/gms, (schema.items.type === 'object') ? '$1' : '') .replace(/\$\{if\.non\.object\}(.*?)\$\{end\.if\.non\.object\}/gms, (schema.items.type !== 'object') ? '$1' : '')