diff --git a/languages/cpp/src/shared/cmake/HelperFunctions.cmake b/languages/cpp/src/shared/cmake/HelperFunctions.cmake index eb2ae296..4b5c4e09 100644 --- a/languages/cpp/src/shared/cmake/HelperFunctions.cmake +++ b/languages/cpp/src/shared/cmake/HelperFunctions.cmake @@ -62,7 +62,7 @@ function(InstallHeaders) if (headers) install( DIRECTORY "${source}/${directory}/${subdir}" - DESTINATION include/${dest} + DESTINATION include/${dest} FILES_MATCHING PATTERN "*.h") endif() endif() diff --git a/languages/cpp/src/shared/src/Logger/Logger.h b/languages/cpp/src/shared/src/Logger/Logger.h index ffe5a455..c88b87e8 100644 --- a/languages/cpp/src/shared/src/Logger/Logger.h +++ b/languages/cpp/src/shared/src/Logger/Logger.h @@ -53,7 +53,7 @@ namespace FireboltSDK { static void Log(LogLevel logLevel, Category category, const std::string& module, const std::string file, const std::string function, const uint16_t line, const std::string& format, ...); public: - template + template static const string Module() { return WPEFramework::Core::ClassNameOnly(typeid(CLASS).name()).Text(); diff --git a/languages/cpp/src/shared/src/Properties/Properties.h b/languages/cpp/src/shared/src/Properties/Properties.h index 52051397..3729ba6b 100644 --- a/languages/cpp/src/shared/src/Properties/Properties.h +++ b/languages/cpp/src/shared/src/Properties/Properties.h @@ -80,7 +80,7 @@ namespace FireboltSDK { } - template + template static Firebolt::Error Get(const string& propertyName, RESPONSETYPE& response) { Firebolt::Error status = Firebolt::Error::General; diff --git a/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp b/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp index ddd85ed9..1e549298 100644 --- a/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp +++ b/languages/cpp/templates/callback-context-instantiation/sub-property/object.cpp @@ -1,3 +1,4 @@ -${if.impl.optional} - ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} -${properties} \ No newline at end of file +${if.impl.optional} ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} + { +${properties} + } \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/generic.cpp b/languages/cpp/templates/callback-result-instantiation/generic.cpp index 6d8fa873..4a22d102 100644 --- a/languages/cpp/templates/callback-result-instantiation/generic.cpp +++ b/languages/cpp/templates/callback-result-instantiation/generic.cpp @@ -1 +1 @@ - ${property} = proxyResponse->Value(); \ No newline at end of file + ${property} = proxyResponse->Value(); diff --git a/languages/cpp/templates/callback-result-instantiation/object.cpp b/languages/cpp/templates/callback-result-instantiation/object.cpp index c4569c3e..c04d0a50 100644 --- a/languages/cpp/templates/callback-result-instantiation/object.cpp +++ b/languages/cpp/templates/callback-result-instantiation/object.cpp @@ -1 +1 @@ -${properties} \ No newline at end of file +${properties} diff --git a/languages/cpp/templates/callback-result-instantiation/property.cpp b/languages/cpp/templates/callback-result-instantiation/property.cpp index db30050c..bb62934b 100644 --- a/languages/cpp/templates/callback-result-instantiation/property.cpp +++ b/languages/cpp/templates/callback-result-instantiation/property.cpp @@ -1 +1,3 @@ -${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}.${property} = proxyResponse->${Property};${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}${if.optional}if (proxyResponse->${Property}.IsSet()) { + ${base.title}.${property} = proxyResponse->${Property}; + }${end.if.optional}${if.non.optional}${base.title}.${property} = proxyResponse->${Property};${end.if.non.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/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp index 56f90f5b..0c62eef4 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/anyOfSchemaShape.cpp @@ -1,3 +1,7 @@ - string ${property}Str; + ${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) { + string ${property}Str; + proxyResponse->${Property.dependency}${Property}.ToString(${property}Str); + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; + }${end.if.optional}${if.non.optional}string ${property}Str; proxyResponse->${Property.dependency}${Property}.ToString(${property}Str); - ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; \ No newline at end of file + ${base.title}${property.dependency}.${property} = ${property}Str;${end.if.non.optional} diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp index 8bf38da1..b2131f27 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/array.cpp @@ -1,5 +1,10 @@ - ${if.impl.array.optional}${base.title}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional} - auto index(proxyResponse->${Property}.Elements()); + ${if.optional}if (proxyResponse->${Property}.IsSet()) { + ${base.title}.${property} = std::make_optional<${type}>(); + auto index(proxyResponse->${Property}.Elements()); + while (index.Next() == true) { + ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object} + } + }${end.if.optional}${if.non.optional}auto index(proxyResponse->${Property}.Elements()); while (index.Next() == true) { -${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object} - } \ No newline at end of file +${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object} + }${end.if.non.optional} diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp index e84a8c35..b005a326 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/const.cpp @@ -1 +1,3 @@ - ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property}; \ No newline at end of file + ${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) { + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property}; + }${end.if.optional}${if.non.optional}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.optional} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp index b134dafe..cd86ff1a 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/object.cpp @@ -1,3 +1,6 @@ -${if.impl.optional} - ${base.title}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} -${properties} \ No newline at end of file +${if.optional} if (proxyResponse->${Property.dependency}IsSet()) { + ${base.title}${property.dependency} = std::make_optional<${type}>(); +${properties} + }${end.if.optional}${if.non.optional} { +${properties} + }${end.if.non.optional} \ No newline at end of file diff --git a/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp b/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp index beff7b1e..f8bfa268 100644 --- a/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp +++ b/languages/cpp/templates/callback-result-instantiation/sub-property/property.cpp @@ -1 +1,3 @@ -${shape} ${if.non.const}${if.non.anyOf}${if.non.array}${if.non.object}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${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}${if.optional}if (proxyResponse->${Property.dependency}${Property}.IsSet()) { + ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property}; + }${end.if.optional}${if.non.optional}${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = proxyResponse->${Property.dependency}${Property};${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf}${end.if.non.const} diff --git a/languages/cpp/templates/codeblocks/interface.cpp b/languages/cpp/templates/codeblocks/interface.cpp index dff9252d..b62df483 100644 --- a/languages/cpp/templates/codeblocks/interface.cpp +++ b/languages/cpp/templates/codeblocks/interface.cpp @@ -23,25 +23,25 @@ WPEFramework::Core::JSON::Variant CorrelationId(correlationId); jsonParameters.Set(_T("correlationId"), CorrelationId); - ProviderInvokeSession(methodName, jsonParameters, err); + ProviderInvokeSession(methodName, jsonParameters, err); } static void ProviderResultSession(std::string methodName, std::string& correlationId, ${provider.xresponse.name} result, Firebolt::Error *err = nullptr) { JsonObject jsonParameters; - WPEFramework::Core::JSON::Variant CorrelationId(correlationId); + WPEFramework::Core::JSON::Variant CorrelationId(correlationId); jsonParameters.Set(_T("correlationId"), CorrelationId); ${provider.xresponse.serialization} - ProviderInvokeSession(methodName, jsonParameters, err); + ProviderInvokeSession(methodName, jsonParameters, err); } static void ProviderErrorSession(std::string methodName, std::string& correlationId, ${provider.xerror.name} result, Firebolt::Error *err = nullptr) { JsonObject jsonParameters; - WPEFramework::Core::JSON::Variant CorrelationId(correlationId); + WPEFramework::Core::JSON::Variant CorrelationId(correlationId); jsonParameters.Set(_T("correlationId"), CorrelationId); ${provider.xerror.serialization} - ProviderInvokeSession(methodName, jsonParameters, err); + ProviderInvokeSession(methodName, jsonParameters, err); } ${methods} diff --git a/languages/cpp/templates/codeblocks/module-init.cpp b/languages/cpp/templates/codeblocks/module-init.cpp index 034ff7fe..4d166513 100644 --- a/languages/cpp/templates/codeblocks/module-init.cpp +++ b/languages/cpp/templates/codeblocks/module-init.cpp @@ -1,14 +1,14 @@ ${if.modules} ${info.Title}::I${info.Title}& ${info.Title}Interface() const override { auto module = _moduleMap.find("${info.Title}"); - ${info.Title}::I${info.Title}* ${info.title.lowercase} = nullptr; + ${info.Title}::I${info.Title}* ${info.title.lowercase} = nullptr; if (module != _moduleMap.end()) { ${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(module->second); } else { ${info.title.lowercase} = reinterpret_cast<${info.Title}::I${info.Title}*>(new ${info.Title}::${info.Title}Impl()); _moduleMap.emplace("${info.Title}", reinterpret_cast(${info.title.lowercase})); - } + } return *${info.title.lowercase}; } diff --git a/languages/cpp/templates/methods/polymorphic-pull-event.cpp b/languages/cpp/templates/methods/polymorphic-pull-event.cpp index ef7a837b..54da22d6 100644 --- a/languages/cpp/templates/methods/polymorphic-pull-event.cpp +++ b/languages/cpp/templates/methods/polymorphic-pull-event.cpp @@ -14,7 +14,7 @@ Firebolt::Error status = Firebolt::Error::NotConnected; FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); if (transport != nullptr) { - JsonObject jsonParameters; + JsonObject jsonParameters; WPEFramework::Core::JSON::Variant CorrelationId = proxyResponse->CorrelationId.Value(); jsonParameters.Set(_T("correlationId"), CorrelationId); ${method.pulls.json.type} ${method.pulls.result.title}Container; diff --git a/languages/cpp/templates/parameter-serialization/additionalProperties.cpp b/languages/cpp/templates/parameter-serialization/additionalProperties.cpp index 88c832d0..eea6f6a7 100644 --- a/languages/cpp/templates/parameter-serialization/additionalProperties.cpp +++ b/languages/cpp/templates/parameter-serialization/additionalProperties.cpp @@ -9,4 +9,4 @@ jsonContainer.Set(element.first.c_str(), jsonElement); ${property}Variant = jsonContainer; } - jsonParameters.Set(_T("${property}"), ${property}Variant); \ No newline at end of file + jsonParameters.Set(_T("${property}"), ${property}Variant); diff --git a/languages/cpp/templates/parameter-serialization/enum.cpp b/languages/cpp/templates/parameter-serialization/enum.cpp index 167761a0..478e1d8e 100644 --- a/languages/cpp/templates/parameter-serialization/enum.cpp +++ b/languages/cpp/templates/parameter-serialization/enum.cpp @@ -4,4 +4,4 @@ jsonParameters.Set(_T("${property}"), ${property}Variant); }${end.if.optional}${if.non.optional}${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonValue = ${property}; WPEFramework::Core::JSON::Variant ${property}Variant(jsonValue.Data()); - jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional} + jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/generic.cpp b/languages/cpp/templates/parameter-serialization/generic.cpp index 5ab016c3..69893434 100644 --- a/languages/cpp/templates/parameter-serialization/generic.cpp +++ b/languages/cpp/templates/parameter-serialization/generic.cpp @@ -2,4 +2,4 @@ WPEFramework::Core::JSON::Variant ${property}Variant(${property}.value()); jsonParameters.Set(_T("${property}"), ${property}Variant); }${end.if.optional}${if.non.optional}WPEFramework::Core::JSON::Variant ${property}Variant(${property}); - jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional} + jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.non.optional} \ 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 baedcd30..a8426a59 100644 --- a/languages/cpp/templates/parameter-serialization/object-array.cpp +++ b/languages/cpp/templates/parameter-serialization/object-array.cpp @@ -6,4 +6,4 @@ ${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; + ${property}Array.Add() = ${property}Variant; \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/object.cpp b/languages/cpp/templates/parameter-serialization/object.cpp index 4d0cbc08..877b0d13 100644 --- a/languages/cpp/templates/parameter-serialization/object.cpp +++ b/languages/cpp/templates/parameter-serialization/object.cpp @@ -16,4 +16,4 @@ ${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);${end.if.impl.non.optional} + jsonParameters.Set(_T("${property}"), ${property}Variant);${end.if.impl.non.optional} \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/array.cpp b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp index d04f5448..cf5bb5f2 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/array.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/array.cpp @@ -10,4 +10,4 @@ for (auto& element : ${property}) { ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}Array.Add() = element;${end.if.non.object} } - ${base.title}Container.${Property.dependency}Add(_T("${property}"), &${property}Array);${end.if.impl.array.non.optional} \ No newline at end of file + ${base.title}Container.${Property.dependency}Add(_T("${property}"), &${property}Array);${end.if.impl.array.non.optional} diff --git a/languages/cpp/templates/parameter-serialization/sub-property/const.cpp b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp index 8d41229f..fa81c8f4 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/const.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/const.cpp @@ -1,3 +1,3 @@ ${if.optional}if (element${property.dependency}.${property}.has_value()) { ${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property}.value(); - }${end.if.optional}${if.non.optional}${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property};${end.if.non.optional} + }${end.if.optional}${if.non.optional}${base.title}Container.${Property.dependency}${Property} = element${property.dependency}.${property};${end.if.non.optional} \ 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 a8bca812..11c5b76b 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/object-array.cpp @@ -1,3 +1,5 @@ ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} ${property}Container; + { ${properties} + } ${property}Array.Add() = ${property}Container; \ No newline at end of file diff --git a/languages/cpp/templates/parameter-serialization/sub-property/object.cpp b/languages/cpp/templates/parameter-serialization/sub-property/object.cpp index c04d0a50..086f7169 100644 --- a/languages/cpp/templates/parameter-serialization/sub-property/object.cpp +++ b/languages/cpp/templates/parameter-serialization/sub-property/object.cpp @@ -1 +1,3 @@ + { ${properties} + } \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/array.cpp b/languages/cpp/templates/result-instantiation/array.cpp index 2fab5f07..0e2f01ef 100644 --- a/languages/cpp/templates/result-instantiation/array.cpp +++ b/languages/cpp/templates/result-instantiation/array.cpp @@ -1,4 +1,4 @@ auto index(jsonResult.Elements()); while (index.Next() == true) { -${if.object}${items.with.indent}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object} + ${if.object}${items}${end.if.object}${if.non.object} ${property}.push_back(index.Current().Value());${end.if.non.object} } \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/object-array.cpp b/languages/cpp/templates/result-instantiation/object-array.cpp index 0c396b43..f992be35 100644 --- a/languages/cpp/templates/result-instantiation/object-array.cpp +++ b/languages/cpp/templates/result-instantiation/object-array.cpp @@ -1,4 +1,4 @@ - ${type} ${property}Result${level}; - ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); + ${type} ${property}Result${level}; + ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); ${properties} - ${property}.push_back(${property}Result${level}); \ No newline at end of file + ${property}.push_back(${property}Result${level}); \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/property.cpp b/languages/cpp/templates/result-instantiation/property.cpp index fb6ca4d4..5d3c2db8 100644 --- a/languages/cpp/templates/result-instantiation/property.cpp +++ b/languages/cpp/templates/result-instantiation/property.cpp @@ -1 +1,3 @@ -${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} +${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (jsonResult.${Property}.IsSet()) { + ${base.title}Result${level}.${property} = jsonResult.${Property}.Value(); + }${end.if.optional}${if.non.optional}${base.title}Result${level}.${property} = jsonResult.${Property}.Value();${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp b/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp index 1d5afa9b..75d9be83 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/anyOfSchemaShape.cpp @@ -1,3 +1,7 @@ - string ${property}Str; + ${if.optional}if (jsonResult.${Property.dependency}${Property}.IsSet()) { + string ${property}Str; + jsonResult.${Property.dependency}${Property}.ToString(${property}Str); + ${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; + }${end.if.optional}${if.non.optional}string ${property}Str; jsonResult.${Property.dependency}${Property}.ToString(${property}Str); - ${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str; + ${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = ${property}Str;${end.if.non.optional} diff --git a/languages/cpp/templates/result-instantiation/sub-property/array.cpp b/languages/cpp/templates/result-instantiation/sub-property/array.cpp index 5d401ef3..a9badd14 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/array.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/array.cpp @@ -1,5 +1,10 @@ - ${if.impl.array.optional}${base.title}Result${level}.${property} = std::make_optional<${type}>();${end.if.impl.array.optional} - auto index(jsonResult.${Property}.Elements()); + ${if.optional}if (jsonResult.${Property}.IsSet()) { + ${base.title}Result${level}.${property} = std::make_optional<${type}>(); + auto index(jsonResult.${Property}.Elements()); + while (index.Next() == true) { + ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.value().push_back(index.Current().Value());${end.if.non.object} + } + }${end.if.optional}${if.non.optional}auto index(jsonResult.${Property}.Elements()); while (index.Next() == true) { -${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(index.Current().Value());${end.if.non.object} - } \ No newline at end of file + ${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}Result${level}.${property}.push_back(index.Current().Value());${end.if.non.object} + }${end.if.non.optional} diff --git a/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp b/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp index 87f0971d..1274a0da 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/object-array.cpp @@ -1,4 +1,6 @@ ${type} ${property}Result${level}; ${if.namespace.notsame}Firebolt::${info.Title}::${end.if.namespace.notsame}JsonData_${title} jsonResult = index.Current(); + { ${properties} + } ${property}Result.${property}${if.impl.array.optional}.value()${end.if.impl.array.optional}.push_back(${property}Result${level}); \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/object.cpp b/languages/cpp/templates/result-instantiation/sub-property/object.cpp index 2f526fef..bb793a66 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/object.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/object.cpp @@ -1,3 +1,6 @@ -${if.impl.optional} - ${base.title}Result${level}${property.dependency} = std::make_optional<${type}>();${end.if.impl.optional} -${properties} \ No newline at end of file +${if.optional} if (jsonResult.${Property.dependency}IsSet()) { + ${base.title}Result${level}${property.dependency} = std::make_optional<${type}>(); +${properties} + }${end.if.optional}${if.non.optional} { +${properties} + }${end.if.non.optional} \ No newline at end of file diff --git a/languages/cpp/templates/result-instantiation/sub-property/property.cpp b/languages/cpp/templates/result-instantiation/sub-property/property.cpp index 6e938509..83d14805 100644 --- a/languages/cpp/templates/result-instantiation/sub-property/property.cpp +++ b/languages/cpp/templates/result-instantiation/sub-property/property.cpp @@ -1 +1,3 @@ -${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} \ No newline at end of file +${shape} ${if.non.anyOf}${if.non.array}${if.non.object}${if.optional}if (jsonResult.${Property.dependency}${Property}.IsSet()) { + ${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property}; + }${end.if.optional}${if.non.optional}${base.title}Result${level}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = jsonResult.${Property.dependency}${Property};${end.if.non.optional}${end.if.non.object}${end.if.non.array}${end.if.non.anyOf} diff --git a/languages/cpp/templates/sdk/scripts/install.sh b/languages/cpp/templates/sdk/scripts/install.sh index 2c4663af..2e8a956c 100755 --- a/languages/cpp/templates/sdk/scripts/install.sh +++ b/languages/cpp/templates/sdk/scripts/install.sh @@ -18,7 +18,7 @@ do case "${flag}" in i) InstallPath="${OPTARG}";; s) SdkPath="${OPTARG}";; - m) ModuleName="${OPTARG}";; + m) ModuleName="${OPTARG}";; h) usage && exit 1;; esac done diff --git a/languages/cpp/templates/types/object.h b/languages/cpp/templates/types/object.h index 88d35c97..4bf36f8e 100644 --- a/languages/cpp/templates/types/object.h +++ b/languages/cpp/templates/types/object.h @@ -1,3 +1,3 @@ struct ${title} { - ${properties} +${properties} }; \ No newline at end of file diff --git a/languages/cpp/templates/types/property.h b/languages/cpp/templates/types/property.h index 92de9ade..a0ea4ab1 100644 --- a/languages/cpp/templates/types/property.h +++ b/languages/cpp/templates/types/property.h @@ -1 +1 @@ -${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property}; + ${if.optional}std::optional<${end.if.optional}${title}${if.optional}>${end.if.optional} ${property}; diff --git a/languages/javascript/templates/types/object.mjs b/languages/javascript/templates/types/object.mjs index 9c30308e..78965d52 100644 --- a/languages/javascript/templates/types/object.mjs +++ b/languages/javascript/templates/types/object.mjs @@ -1,3 +1,3 @@ { - ${properties} +${properties} } diff --git a/languages/javascript/templates/types/property.mjs b/languages/javascript/templates/types/property.mjs index 5d3db0f5..2fc6076f 100644 --- a/languages/javascript/templates/types/property.mjs +++ b/languages/javascript/templates/types/property.mjs @@ -1 +1 @@ -${property}${if.optional}?${end.if.optional}: ${title} // ${summary} \ No newline at end of file + ${property}${if.optional}?${end.if.optional}: ${title} // ${summary} \ No newline at end of file diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 523b297b..70023eb1 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -68,13 +68,27 @@ const state = { const capitalize = str => str[0].toUpperCase() + str.substr(1) -const indent = (str, padding) => { +const indent = (str, paddingStr, repeat = 1, endRepeat = 0) => { let first = true - return str.split('\n').map(line => { + let padding = '' + for (let i = 0; i < repeat; i++) { + padding += paddingStr + } + + let length = str.split('\n').length - 1 + let endPadding = '' + for (let i = 0; length && i < endRepeat; i++) { + endPadding += paddingStr + } + + return str.split('\n').map((line, index) => { if (first) { first = false return line } + else if (index === length && endPadding) { + return endPadding + line + } else { return padding + line } @@ -1288,7 +1302,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) let paramInstantiation = event.params.map(param => types.getSchemaShape(param.schema, json, { templateDir: 'callback-context-instantiation', property: param.name, required: param.required, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true })).join('\n') let resultInstantiation = types.getSchemaShape(event.result.schema, json, { templateDir: 'callback-context-instantiation', property: result.name, destination: state.destination, section: state.section, primitive: true, skipTitleOnce: true }) callbackInstantiation = callbackInstantiation - .replace(/\$\{callback\.param\.instantiation\.with\.indent\}/g, indent(paramInstantiation, ' ')) + .replace(/\$\{callback\.param\.instantiation\.with\.indent\}/g, indent(paramInstantiation, ' ', 2)) .replace(/\$\{callback\.result\.instantiation\}/g, resultInstantiation) } else { @@ -1412,7 +1426,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) .replace(/\$\{method\.pulls\.param\.json\.type\}/g, pullsForParamJsonType) .replace(/\$\{method\.pulls\.response\.initialization\}/g, pullsResponseInit) .replace(/\$\{method\.pulls\.response\.instantiation}/g, pullsResponseInst) - .replace(/\$\{method\.pulls\.result\.serialization\.with\.indent\}/g, indent(pullsResultSerialize, ' ')) + .replace(/\$\{method\.pulls\.result\.serialization\.with\.indent\}/g, indent(pullsResultSerialize, ' ', 3, 2)) .replace(/\$\{method\.setter\.for\}/g, setterFor) .replace(/\$\{method\.puller\}/g, pullerTemplate) // must be last!! .replace(/\$\{method\.setter\}/g, setterTemplate) // must be last!! diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index 9acc285a..b8b76016 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -267,6 +267,7 @@ const insertObjectAdditionalPropertiesMacros = (content, schema, module, title, return content } +const getIndents = level => level ? ' ' : '' const insertObjectMacros = (content, schema, module, title, property, options) => { const options2 = options ? JSON.parse(JSON.stringify(options)) : {} options2.parent = title @@ -274,9 +275,9 @@ const insertObjectMacros = (content, schema, module, title, property, options) = options2.level = options.level + 1 options2.templateDir = options.templateDir ;(['properties', 'properties.register', 'properties.assign']).forEach(macro => { - const indent = (content.split('\n').find(line => line.includes("${" + macro + "}")) || '').match(/^\s+/) || [''][0] + const indent = getIndents(options.parentLevel || (options.level ? 1 : 0)) const templateType = macro.split('.').slice(1).join('') - const template = getTemplate(path.join(options.templateDir, 'property' + (templateType ? `-${templateType}` : ''))).replace(/\n/gms, indent + '\n') + const template = getTemplate(path.join(options.templateDir, 'property' + (templateType ? `-${templateType}` : ''))).replace(/\n/gms, '\n' + indent) const properties = [] if (schema.properties) { Object.entries(schema.properties).forEach(([name, prop], i) => { @@ -286,11 +287,12 @@ const insertObjectMacros = (content, schema, module, title, property, options) = const objSeparator = getTemplate(path.join(options2.templateDir, 'object-separator')) if (localizedProp.type === 'array' || localizedProp.anyOf || localizedProp.oneOf || (typeof localizedProp.const === 'string')) { options2.property = name + options2.required = schema.required } else { options2.property = options.property + options2.required = schema.required && schema.required.includes(name) } - options2.required = schema.required - const schemaShape = getSchemaShape(localizedProp, module, options2) + const schemaShape = indent + getSchemaShape(localizedProp, module, options2).replace(/\n/gms, '\n' + indent) const type = getSchemaType(localizedProp, module, options2) // don't push properties w/ unsupported types if (type) { @@ -331,7 +333,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = .replace(/\$\{obj\.separator}/g, objSeparator) .replace(/\$\{base.title\}/g, (baseTitle ? (baseTitle)[0].toLowerCase() + (baseTitle).substr(1) : '')).trimEnd() .replace(/\$\{base.Title\}/g, (baseTitle ? (baseTitle)[0].toUpperCase() + (baseTitle).substr(1) : '')).trimEnd() - properties.push((i !== 0 ? indent : '') + replacedTemplate) + properties.push(replacedTemplate) } }) } @@ -363,7 +365,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = if (type) { options2.property = prop const schemaShape = getSchemaShape(type, module, options2) - properties.push((i !== 0 ? indent : '') + template + properties.push(template .replace(/\$\{property\}/g, safeName(prop)) .replace(/\$\{Property\}/g, capitalize(safeName(prop))) .replace(/\$\{parent\.title\}/g, title)