diff --git a/languages/cpp/templates/codeblocks/setter.cpp b/languages/cpp/templates/codeblocks/setter.cpp index fa0e0901..8038cf8a 100644 --- a/languages/cpp/templates/codeblocks/setter.cpp +++ b/languages/cpp/templates/codeblocks/setter.cpp @@ -1,8 +1,8 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ void ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) { - const string method = _T("${info.title.lowercase}.${method.rpc.name}"); + const string method = _T("${info.title.lowercase}.${method.name}"); JsonObject jsonParameters; ${if.params}${method.params.serialization}${end.if.params} diff --git a/languages/cpp/templates/declarations-override/setter.h b/languages/cpp/templates/declarations-override/setter.h index 8a843dc9..752833ff 100644 --- a/languages/cpp/templates/declarations-override/setter.h +++ b/languages/cpp/templates/declarations-override/setter.h @@ -1,5 +1,5 @@ /* - * ${method.rpc.name} + * ${method.name} * ${method.description} */ void ${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr ) override; diff --git a/languages/cpp/templates/declarations/event.h b/languages/cpp/templates/declarations/event.h index a29c245c..e9284523 100644 --- a/languages/cpp/templates/declarations/event.h +++ b/languages/cpp/templates/declarations/event.h @@ -1,6 +1,6 @@ /* ${method.name} - ${method.description} */ struct I${method.Name}Notification { - virtual void ${method.name}( ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${event.result.type} ) = 0; + virtual void ${method.rpc.name}( ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${event.result.type} ) = 0; }; // signature callback params: ${event.signature.callback.params} // method result properties : ${method.result.properties} diff --git a/languages/cpp/templates/declarations/polymorphic-pull-event.h b/languages/cpp/templates/declarations/polymorphic-pull-event.h index 7baed2cf..cb6e8dee 100644 --- a/languages/cpp/templates/declarations/polymorphic-pull-event.h +++ b/languages/cpp/templates/declarations/polymorphic-pull-event.h @@ -1,6 +1,6 @@ /* ${method.name} - ${method.description} */ struct I${method.Name}Notification { - virtual ${method.pulls.type} ${method.name}( ${method.pulls.param.type} ) = 0; + virtual ${method.pulls.type} ${method.rpc.name}( ${method.pulls.param.type} ) = 0; }; virtual void subscribe( I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) = 0; virtual void unsubscribe( I${method.Name}Notification& notification, Firebolt::Error *err = nullptr ) = 0; diff --git a/languages/cpp/templates/declarations/setter.h b/languages/cpp/templates/declarations/setter.h index 77659fcd..115f39f0 100644 --- a/languages/cpp/templates/declarations/setter.h +++ b/languages/cpp/templates/declarations/setter.h @@ -1,5 +1,5 @@ /* - ${method.rpc.name} + ${method.name} ${method.description} */ virtual void ${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err = nullptr ) = 0; diff --git a/languages/cpp/templates/methods/calls-metrics.cpp b/languages/cpp/templates/methods/calls-metrics.cpp index 67b67d22..1b6765c6 100644 --- a/languages/cpp/templates/methods/calls-metrics.cpp +++ b/languages/cpp/templates/methods/calls-metrics.cpp @@ -1,8 +1,8 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ static void ${method.name}Dispatcher(const void* result) { Metrics::MetricsImpl::${method.name}(${if.result.nonboolean}${if.result.nonvoid}(static_cast<${method.result.json.type}>(const_cast(result)))${end.if.result.nonvoid}${end.if.result.nonboolean}); } - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ ${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) ${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} { Firebolt::Error status = Firebolt::Error::NotConnected; @@ -13,9 +13,9 @@ JsonObject jsonParameters; ${method.params.serialization.with.indent} ${method.result.json.type} jsonResult; - status = transport->Invoke("${info.title.lowercase}.${method.rpc.name}", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.${method.name}", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.name} is successfully invoked"); ${if.result.nonvoid}${method.result.instantiation.with.indent}${end.if.result.nonvoid} WPEFramework::Core::ProxyType job = WPEFramework::Core::ProxyType(WPEFramework::Core::ProxyType::Create(${method.name}Dispatcher, nullptr)); WPEFramework::Core::IWorkerPool::Instance().Submit(job); diff --git a/languages/cpp/templates/methods/default.cpp b/languages/cpp/templates/methods/default.cpp index f1fb6e71..0b5b31bf 100644 --- a/languages/cpp/templates/methods/default.cpp +++ b/languages/cpp/templates/methods/default.cpp @@ -1,4 +1,4 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ ${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) ${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} { Firebolt::Error status = Firebolt::Error::NotConnected; @@ -9,9 +9,9 @@ JsonObject jsonParameters; ${method.params.serialization.with.indent} ${method.result.json.type} jsonResult; - status = transport->Invoke("${info.title.lowercase}.${method.rpc.name}", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.${method.name}", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.name} is successfully invoked"); ${if.result.nonvoid}${method.result.instantiation.with.indent}${end.if.result.nonvoid} } diff --git a/languages/cpp/templates/methods/event.cpp b/languages/cpp/templates/methods/event.cpp index b46f2208..ec3ba93f 100644 --- a/languages/cpp/templates/methods/event.cpp +++ b/languages/cpp/templates/methods/event.cpp @@ -1,4 +1,4 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ static void ${method.name}InnerCallback( void* notification, const void* userData, void* jsonResponse ) { ${event.callback.serialization} @@ -11,7 +11,7 @@ proxyResponse.Release(); I${info.Title}::I${method.Name}Notification& notifier = *(reinterpret_cast(notification)); - notifier.${method.name}(${event.callback.response.instantiation}); + notifier.${method.rpc.name}(${event.callback.response.instantiation}); } } void ${info.Title}Impl::subscribe( ${event.signature.params}${if.event.params}, ${end.if.event.params}I${info.Title}::I${method.Name}Notification& notification, Firebolt::Error *err ) diff --git a/languages/cpp/templates/methods/polymorphic-pull-event.cpp b/languages/cpp/templates/methods/polymorphic-pull-event.cpp index 54da22d6..43a33df5 100644 --- a/languages/cpp/templates/methods/polymorphic-pull-event.cpp +++ b/languages/cpp/templates/methods/polymorphic-pull-event.cpp @@ -1,4 +1,4 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ static void ${method.name}InnerCallback( void* notification, const void* userData, void* jsonResponse ) { ${event.callback.serialization} @@ -10,7 +10,7 @@ ${method.pulls.response.instantiation} I${info.Title}::I${method.Name}Notification& notifier = *(reinterpret_cast(notification)); - ${method.pulls.type} element = notifier.${method.name}(${method.pulls.param.title}); + ${method.pulls.type} element = notifier.${method.rpc.name}(${method.pulls.param.title}); Firebolt::Error status = Firebolt::Error::NotConnected; FireboltSDK::Transport* transport = FireboltSDK::Accessor::Instance().GetTransport(); if (transport != nullptr) { @@ -30,7 +30,7 @@ status = transport->Invoke("${info.title.lowercase}.${method.pulls.for}", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully pushed with status as %d", jsonResult.Value()); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.name} is successfully pushed with status as %d", jsonResult.Value()); } } else { diff --git a/languages/cpp/templates/methods/polymorphic-pull.cpp b/languages/cpp/templates/methods/polymorphic-pull.cpp index 7f8368d2..1146f2d1 100644 --- a/languages/cpp/templates/methods/polymorphic-pull.cpp +++ b/languages/cpp/templates/methods/polymorphic-pull.cpp @@ -1,4 +1,4 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ ${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) ${if.result.nonvoid}${if.params.empty} const${end.if.params.empty}${end.if.result.nonvoid} { Firebolt::Error status = Firebolt::Error::NotConnected; @@ -9,9 +9,9 @@ JsonObject jsonParameters; ${method.params.serialization.with.indent} ${method.result.json.type} jsonResult; - status = transport->Invoke("${info.title.lowercase}.${method.rpc.name}", jsonParameters, jsonResult); + status = transport->Invoke("${info.title.lowercase}.${method.name}", jsonParameters, jsonResult); if (status == Firebolt::Error::None) { - FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.rpc.name} is successfully invoked"); + FIREBOLT_LOG_INFO(FireboltSDK::Logger::Category::OpenRPC, FireboltSDK::Logger::Module(), "${info.Title}.${method.name} is successfully invoked"); ${if.result.nonvoid}${method.result.instantiation.with.indent}${end.if.result.nonvoid} } diff --git a/languages/cpp/templates/methods/property.cpp b/languages/cpp/templates/methods/property.cpp index 4fbe9fc4..607a6527 100644 --- a/languages/cpp/templates/methods/property.cpp +++ b/languages/cpp/templates/methods/property.cpp @@ -1,7 +1,7 @@ - /* ${method.rpc.name} - ${method.description} */ + /* ${method.name} - ${method.description} */ ${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) const { - const string method = _T("${info.title.lowercase}.${method.rpc.name}"); + const string method = _T("${info.title.lowercase}.${method.name}"); ${if.params}${method.params.serialization}${end.if.params} ${method.result.json} jsonResult; ${method.result.initialization} diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index f1f4e984..339c9785 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -503,10 +503,6 @@ return obj } const generateMacros = (obj, templates, languages, options = {}) => { - // for languages that don't support nested schemas, let's promote them to first-class schemas w/ titles - if (config.extractSubSchemas) { - obj = promoteAndNameSubSchemas(obj) - } if (options.createPolymorphicMethods) { let methods = [] obj.methods && obj.methods.forEach(method => { @@ -522,6 +518,10 @@ const generateMacros = (obj, templates, languages, options = {}) => { }) obj.methods = methods } + // for languages that don't support nested schemas, let's promote them to first-class schemas w/ titles + if (config.extractSubSchemas) { + obj = promoteAndNameSubSchemas(obj) + } // config.mergeAnyOfs = true // if (config.mergeAnyOfs) { @@ -1347,7 +1347,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) template = insertExampleMacros(template, examples[methodObj.name] || [], methodObj, json, templates) template = template.replace(/\$\{method\.name\}/g, method.name) - .replace(/\$\{method\.rpc\.name\}/g, methodObj.title || methodObj.name) + .replace(/\$\{method\.rpc\.name\}/g, methodObj.rpc_name || methodObj.name) .replace(/\$\{method\.summary\}/g, methodObj.summary) .replace(/\$\{method\.description\}/g, methodObj.description || methodObj.summary) diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index 1d2378c0..393a7e75 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -336,8 +336,8 @@ const insertObjectMacros = (content, schema, module, title, property, options) = .replace(/\$\{description\}/g, prop.description || '') .replace(/\$\{summary\}/g, prop.description ? prop.description.split('\n')[0] : '') .replace(/\$\{delimiter\}(.*?)\$\{end.delimiter\}/gms, i === schema.properties.length - 1 ? '' : '$1') - .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, schema.required && schema.required.includes(name) ? '' : '$1') - .replace(/\$\{if\.non.optional\}(.*?)\$\{end\.if\.non.optional\}/gms, schema.required && schema.required.includes(name) ? '$1' : '') + .replace(/\$\{if\.optional\}(.*?)\$\{end\.if\.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '' : '$1') + .replace(/\$\{if\.non.optional\}(.*?)\$\{end\.if\.non.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '$1' : '') .replace(/\$\{if\.base\.optional\}(.*?)\$\{end\.if\.base\.optional\}/gms, options.required ? '' : '$1') .replace(/\$\{if\.non\.object\}(.*?)\$\{end\.if\.non\.object\}/gms, isObject(localizedProp) ? '' : '$1') .replace(/\$\{if\.non\.array\}(.*?)\$\{end\.if\.non\.array\}/gms, (localizedProp.type === 'array') ? '' : '$1') @@ -346,8 +346,8 @@ const insertObjectMacros = (content, schema, module, title, property, options) = let baseTitle = options.property if (isObject(localizedProp)) { replacedTemplate = replacedTemplate - .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, schema.required && schema.required.includes(name) ? '' : '$1') - .replace(/\$\{if\.impl.non.optional\}(.*?)\$\{end\.if\.impl.non.optional\}/gms, schema.required && schema.required.includes(name) ? '$1' : '') + .replace(/\$\{if\.impl.optional\}(.*?)\$\{end\.if\.impl.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '' : '$1') + .replace(/\$\{if\.impl.non.optional\}(.*?)\$\{end\.if\.impl.non.optional\}/gms, ((schema.required && schema.required.includes(name)) || (localizedProp.required && localizedProp.required === true)) ? '$1' : '') .replace(/\$\{property.dependency\}/g, ((options.level > 0) ? '${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}' : '') + objSeparator + name) .replace(/\$\{Property.dependency\}/g, ((options.level > 0) ? '${Property.dependency}' : '') + (objSeparator) + capitalize(name)) } diff --git a/src/openrpc/index.mjs b/src/openrpc/index.mjs index 571429c6..b1f6175a 100644 --- a/src/openrpc/index.mjs +++ b/src/openrpc/index.mjs @@ -87,8 +87,6 @@ const run = async ({ } - - // add methods from this module openrpc.methods.push(...json.methods) @@ -113,4 +111,4 @@ const run = async ({ return Promise.resolve() } -export default run \ No newline at end of file +export default run diff --git a/src/shared/modules.mjs b/src/shared/modules.mjs index 02490c18..fc28aa66 100644 --- a/src/shared/modules.mjs +++ b/src/shared/modules.mjs @@ -886,7 +886,7 @@ const getAnyOfSchema = (inType, json) => { const generateAnyOfSchema = (anyOf, name, summary) => { let anyOfType = {} - anyOfType["name"] = name[0].toLowerCase() + name.substr(1) + anyOfType["name"] = name; anyOfType["summary"] = summary anyOfType["schema"] = anyOf return anyOfType @@ -896,7 +896,7 @@ const generateParamsAnyOfSchema = (methodParams, anyOf, anyOfTypes, title, summa let params = [] methodParams.forEach(p => { if (p.schema.anyOf === anyOfTypes) { - let anyOfType = generateAnyOfSchema(anyOf, title, summary) + let anyOfType = generateAnyOfSchema(anyOf, p.name, summary) anyOfType.required = p.required params.push(anyOfType) } @@ -937,6 +937,7 @@ const createPolymorphicMethods = (method, json) => { let anyOfTypes let methodParams = [] let methodResult = Object.assign({}, method.result) + method.params.forEach(p => { if (p.schema) { let param = getAnyOfSchema(p, json) @@ -979,12 +980,12 @@ const createPolymorphicMethods = (method, json) => { let localized = localizeDependencies(anyOf, json) let title = localized.title || localized.name || '' let summary = localized.summary || localized.description || '' - polymorphicMethodSchema.title = method.name - polymorphicMethodSchema.name = foundAnyOfParams ? `${method.name}With${title}` : `${method.name}${title}` + polymorphicMethodSchema.rpc_name = method.name + polymorphicMethodSchema.name = foundAnyOfResult && isEventMethod(method) ? `${method.name}${title}` : method.name polymorphicMethodSchema.tags = method.tags polymorphicMethodSchema.params = foundAnyOfParams ? generateParamsAnyOfSchema(methodParams, anyOf, anyOfTypes, title, summary) : methodParams polymorphicMethodSchema.result = Object.assign({}, method.result) - polymorphicMethodSchema.result.schema = foundAnyOfResult ? generateResultAnyOfSchema(method, methodResult, anyOf, anyOfTypes, title, summary) : methodResult + polymorphicMethodSchema.result.schema = foundAnyOfResult ? generateResultAnyOfSchema(method, methodResult, anyOf, anyOfTypes, title, summary) : methodResult.schema polymorphicMethodSchema.examples = method.examples polymorphicMethodSchemas.push(Object.assign({}, polymorphicMethodSchema)) })