diff --git a/languages/c/Types.mjs b/languages/c/Types.mjs index 0886d3dc..72912930 100644 --- a/languages/c/Types.mjs +++ b/languages/c/Types.mjs @@ -18,8 +18,8 @@ import deepmerge from 'deepmerge' import { getPath } from '../../src/shared/json-schema.mjs' -import { getTypeName, getModuleName, description, getObjectHandleManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, getArrayElementSchema, getPropertyGetterSignature, getPropertyEventCallbackSignature, getPropertyEventRegisterSignature, getPropertyEventUnregisterSignature, getPropertySetterSignature } from './src/types/NativeHelpers.mjs' -import { getArrayAccessorsImpl, getMapAccessorsImpl, getObjectHandleManagementImpl, getParameterInstantiation, getPropertyAccessorsImpl, getResultInstantiation } from './src/types/ImplHelpers.mjs' +import { getTypeName, getModuleName, description, getObjectHandleManagement, getNativeType, getPropertyAccessors, capitalize, isOptional, generateEnum, getMapAccessors, getArrayAccessors, getArrayElementSchema, getPropertyGetterSignature, getPropertyEventCallbackSignature, getPropertyEventRegisterSignature, getPropertyEventUnregisterSignature, getPropertySetterSignature, getFireboltStringType } from './src/types/NativeHelpers.mjs' +import { getArrayAccessorsImpl, getMapAccessorsImpl, getObjectHandleManagementImpl, getParameterInstantiation, getPropertyAccessorsImpl, getResultInstantiation, getCallbackParametersInstantiation, getCallbackResultInstantiation, getCallbackResponseInstantiation } from './src/types/ImplHelpers.mjs' import { getJsonContainerDefinition, getJsonDataStructName } from './src/types/JSONHelpers.mjs' const getSdkNameSpace = () => 'FireboltSDK' @@ -170,44 +170,50 @@ const hasTag = (method, tag) => { return method.tags && method.tags.filter(t => t.name === tag).length > 0 } -function getMethodSignature(method, module, { destination, isInterface = false }) { - - let signature = '' +function getParamList(schema, module) { let paramList = [] - if(hasTag(method, 'property') || hasTag(method, 'property:readonly') || hasTag(method, 'property:immutable')) { - - method.params.map(param => { + if (schema.params.length > 0) { + schema.params.map(p => { /* - paramList = [{name='', nativeType='', jsonType='', required=boolean}] + param = {name='', nativeType='', jsonType='', required=boolean} */ - paramList['nativeType'] = getSchemaType(param.schema, module, { title: true, name: param.name }) - paramList['jsonType'] = getJsonType(param.schema, module, {name: param.name}) - paramList['name'] = param.name - paramList['required'] = param.required - + let param = {} + param['nativeType'] = getSchemaType(p.schema, module, { title: true, name: p.name }) + param['jsonType'] = getJsonType(p.schema, module, {name: p.name}) + param['name'] = p.name + param['required'] = p.required + paramList.push(param) }) + } + return paramList +} + +function getMethodSignature(method, module, { destination, isInterface = false }) { + + let signature = '' + if (hasTag(method, 'property') || hasTag(method, 'property:readonly') || hasTag(method, 'property:immutable')) { + let paramList = getParamList(method, module) let resultType = method.result && getSchemaType(method.result.schema, module, { title: true, name: method.result.name, resultSchema: true}) || '' signature = getPropertyGetterSignature(method, module, resultType, paramList) + ';\n\n' - if(hasTag(method, 'property') || hasTag(method, 'property:readonly')) { - signature += getPropertyEventCallbackSignature(method, module, resultType, paramList) + ';\n\n' - signature += getPropertyEventRegisterSignature(method, module, paramList) + ';\n\n' - signature += getPropertyEventUnregisterSignature(method, module) + ';\n\n' - } - - if(hasTag(method, 'property')) { + if (hasTag(method, 'property')) { signature += getPropertySetterSignature(method, module, resultType, paramList) + ';\n\n' } } return signature } +function getMethodSignatureParams(method, module, { destination, callback= false } = {}) { -function getMethodSignatureParams(method, module, { destination }) { - - return method.params.map(param => getSchemaType(param.schema, module, { name: param.name, title: true, destination }) + (!param.required ? '* ' : ' ') + param.name ).join(', ') + return method.params.map(param => { + let type = getSchemaType(param.schema, module, { name: param.name, title: true, destination }) + if ((callback === true) && (type === 'char*')) { + type = getFireboltStringType() + } + return type + (!param.required ? '* ' : ' ') + param.name + }).join(', ') } const safeName = prop => prop.match(/[.+]/) ? '"' + prop + '"' : prop @@ -723,34 +729,32 @@ const enumReducer = (acc, val, i, arr) => { function getSchemaInstantiation(schema, module, name, { instantiationType = '' } = {}) { - if(instantiationType === 'params') { - if (schema.params.length > 0) { - let paramList = [] - schema.params.map(param => { - /* - paramList = [{name='', nativeType='', jsonType='', required=boolean}] - */ - const parameter = {} - parameter['nativeType'] = getSchemaType(param.schema, module, { title: true, name: param.name }) - parameter['jsonType'] = getJsonType(param.schema, module, {name: param.name}) - parameter['name'] = param.name - parameter['required'] = param.required - paramList.push(parameter) - - }) - return getParameterInstantiation(paramList) - } - } else if(instantiationType === 'result') { + if (instantiationType === 'params') { + return getParameterInstantiation(getParamList(schema, module)) + } + else if (instantiationType === 'result') { let resultType = getSchemaType(schema, module, { title: true, name: name, resultSchema: true}) || '' let resultJsonType = getJsonType(schema, module, {name: name}) || '' - return getResultInstantiation(name, resultType, resultJsonType) } + else if (instantiationType === 'callback.params') { + let resultJsonType = getJsonType(schema.result.schema, module, {name: schema.result.name}) || '' + return getCallbackParametersInstantiation(getParamList(schema, module), resultJsonType) + } + else if (instantiationType === 'callback.result') { + let resultType = getSchemaType(schema.result.schema, module, { title: true, name: schema.result.name, resultSchema: true}) || '' + let resultJsonType = getJsonType(schema.result.schema, module, {name: schema.result.name}) || '' + return getCallbackResultInstantiation(resultType, resultJsonType) + } + else if (instantiationType === 'callback.response') { + let resultType = getSchemaType(schema.result.schema, module, { title: true, name: schema.result.name, resultSchema: true}) || '' + let resultJsonType = getJsonType(schema.result.schema, module, {name: schema.result.name}) || '' + return getCallbackResponseInstantiation(getParamList(schema, module), resultType, resultJsonType) + } return '' } - export default { getMethodSignature, getMethodSignatureParams, diff --git a/languages/c/src/types/ImplHelpers.mjs b/languages/c/src/types/ImplHelpers.mjs index a39af0b6..6509375a 100644 --- a/languages/c/src/types/ImplHelpers.mjs +++ b/languages/c/src/types/ImplHelpers.mjs @@ -1,10 +1,9 @@ -import { capitalize } from "./NativeHelpers.mjs" +import { capitalize, getFireboltStringType } from "./NativeHelpers.mjs" const Indent = '\t' const getSdkNameSpace = () => 'FireboltSDK' const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON' -const getFireboltStringType = () => 'FireboltTypes_StringHandle' const getObjectHandleManagementImpl = (varName, jsonDataName) => { @@ -320,12 +319,138 @@ function getParameterInstantiation(paramList, container = '') { impl += ` jsonParameters.Set(_T("${param.name}"), ${capitalize(param.name)});\n` impl += ` }` } + impl += '\n' } }) return impl } +const isNativeType = (type) => (type === 'float' || type === 'char*' || type === 'int32_t' || type === 'bool') + +function getCallbackParametersInstantiation(paramList, container = '') { + + let impl = '' + + if (paramList.length > 0) { + paramList.forEach(param => { + if (param.required !== undefined) { + if (param.nativeType !== 'char*') { + impl += ` ${param.nativeType} ${param.name};\n` + if (param.required === false) { + impl += ` ${param.nativeType}* ${param.name}Ptr = nullptr;\n` + } + } + else { + impl += ` ${getFireboltStringType()} ${param.name};\n` + } + } + }) + impl += `\n WPEFramework::Core::ProxyType<${container}>* jsonResponse;\n` + impl += ` WPEFramework::Core::ProxyType& var = *(static_cast*>(response)); + + ASSERT(var.IsValid() == true); + if (var.IsValid() == true) { + WPEFramework::Core::JSON::VariantContainer::Iterator elements = var->Variants(); + + while (elements.Next()) { + if (strcmp(elements.Label(), "value") == 0) { + + jsonResponse = new WPEFramework::Core::ProxyType<${container}>(); + string objectStr; + elements.Current().Object().ToString(objectStr); + (*jsonResponse)->FromString(objectStr); + } else if (strcmp(elements.Label(), "context") == 0) { + + WPEFramework::Core::JSON::VariantContainer::Iterator params = elements.Current().Object().Variants(); + while (params.Next()) {\n` + let contextParams = '' + + paramList.forEach(param => { + if (param.required !== undefined) { + if (isNativeType(param.nativeType) === true) { + if (contextParams.length > 0) { + contextParams += ` else if (strcmp(elements.Label(), "${param.name}") == 0) {\n` + } + else { + contextParams += ` if (strcmp(elements.Label(), "${param.name}") == 0) {\n` + } + if (param.nativeType === 'char*') { + contextParams += ` ${getSdkNameSpace()}::JSON::String* ${param.name}Value = new ${getSdkNameSpace()}::JSON::String(); + *${param.name}Value = elements.Current().Value().c_str(); + ${param.name} = ${param.name}Value;\n` + } + else if (param.nativeType === 'bool') { + contextParams += ` ${param.name} = elements.Current().Boolean();\n` + } + else if ((param.nativeType === 'float') || (param.nativeType === 'int32_t')) { + contextParams += ` ${param.name} = elements.Current().Number();\n` + } + if ((param.nativeType !== 'char*') && (param.required === false)) { + contextParams += ` ${param.name}Ptr = &${param.name};\n` + } + contextParams += ` }\n` + } + } + }) + impl += contextParams + impl += ` } + } else { + ASSERT(false); + } + } + }\n` + } else { + + impl +=` WPEFramework::Core::ProxyType<${container}>* jsonResponse = static_cast*>(response);\n` + } + + return impl +} + +function getCallbackResultInstantiation(nativeType, container = '') { + let impl = '' + if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { + impl +=` + ${container}* jsonStrResponse = new ${container}(); + *jsonStrResponse = *(*jsonResponse); + jsonResponse->Release();` + '\n' + } + return impl +} + +function getCallbackResponseInstantiation(paramList, nativeType, container = '') { + let impl = '' + + if (paramList.length > 0) { + paramList.forEach(param => { + if (param.required !== undefined) { + if (param.nativeType === 'char*') { + impl += `static_cast<${getFireboltStringType()}>(${param.name}), ` + } + else if (param.required === true) { + impl += `${param.name}, ` + } + else if (param.required === false) { + impl += `${param.name}Ptr, ` + } + } + }) + } + + if (nativeType === 'char*' || nativeType === 'FireboltTypes_StringHandle') { + impl += `static_cast<${nativeType}>(jsonStrResponse)` + } + else if (nativeType.includes('Handle')) { + impl += `static_cast<${nativeType}>(jsonResponse)` + } + else { + impl += `static_cast<${nativeType}>((*jsonResponse)->Value())` + } + + return impl +} + function getResultInstantiation (name, nativeType, container, indentLevel = 3) { let impl = '' @@ -353,5 +478,8 @@ export { getObjectHandleManagementImpl, getPropertyAccessorsImpl, getParameterInstantiation, + getCallbackParametersInstantiation, + getCallbackResultInstantiation, + getCallbackResponseInstantiation, getResultInstantiation } diff --git a/languages/c/src/types/NativeHelpers.mjs b/languages/c/src/types/NativeHelpers.mjs index 65a78443..022437e8 100644 --- a/languages/c/src/types/NativeHelpers.mjs +++ b/languages/c/src/types/NativeHelpers.mjs @@ -120,7 +120,7 @@ const getNativeType = (json, stringAsHandle = false) => { let jsonType = json.const ? typeof json.const : json.type if (jsonType === 'string') { type = 'char*' - if(stringAsHandle) { + if (stringAsHandle) { type = getFireboltStringType() } } @@ -140,7 +140,6 @@ const getNativeType = (json, stringAsHandle = false) => { return type } - const getObjectHandleManagement = varName => { let result = `typedef void* ${varName}Handle; @@ -229,13 +228,16 @@ function getPropertyGetterSignature(property, module, propType, paramList = []) let contextParams = '' contextParams = getContextParams(paramList) - return `uint32_t ${capitalize(getModuleName(module))}_Get${capitalize(property.name)}( ${contextParams}${contextParams.length > 0 ? ', ':''}${propType}* ${property.result.name || property.name})` + return `uint32_t ${capitalize(getModuleName(module))}_Get${capitalize(property.name)}( ${contextParams}${contextParams.length > 0 ? ', ':''}${propType}* ${property.result.name || property.name} )` } function getPropertySetterSignature(property, module, propType, paramList = []) { let contextParams = '' contextParams = getContextParams(paramList) - return `uint32_t ${capitalize(getModuleName(module))}_Set${capitalize(property.name)}( ${contextParams}${contextParams.length > 0 ? ', ':''}${propType} ${property.result.name || property.name})` + if (propType === getFireboltStringType()) { + propType = 'char*' + } + return `uint32_t ${capitalize(getModuleName(module))}_Set${capitalize(property.name)}( ${contextParams}${contextParams.length > 0 ? ', ':''}${propType} ${property.result.name || property.name} )` } function getPropertyEventCallbackSignature(property, module, propType, paramList = []) { @@ -288,5 +290,6 @@ export { getPropertyAccessors, isOptional, generateEnum, - getArrayElementSchema + getArrayElementSchema, + getFireboltStringType } diff --git a/languages/c/templates/declarations/event.c b/languages/c/templates/declarations/event.c new file mode 100644 index 00000000..45e4b608 --- /dev/null +++ b/languages/c/templates/declarations/event.c @@ -0,0 +1,4 @@ +/* ${method.name} - ${method.description} */ +typedef void (*${info.Title}${method.Name}Callback)( const void* userData, ${event.signature.callback.params}${if.event.params}, ${end.if.event.params}${event.result.type} ); +uint32_t ${info.Title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}${info.Title}${method.Name}Callback userCB, const void* userData ); +uint32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB); diff --git a/languages/c/templates/methods/default.c b/languages/c/templates/methods/default.c index 49f76ce1..6a023534 100644 --- a/languages/c/templates/methods/default.c +++ b/languages/c/templates/methods/default.c @@ -21,4 +21,4 @@ uint32_t ${info.title}_${method.Name}(${method.params.list}${if.params}, ${end.i } return status; -} \ No newline at end of file +} diff --git a/languages/c/templates/methods/event.c b/languages/c/templates/methods/event.c new file mode 100644 index 00000000..ec868cd5 --- /dev/null +++ b/languages/c/templates/methods/event.c @@ -0,0 +1,26 @@ +/* ${method.name} - ${method.description} */ +static void ${info.Title}${method.Name}InnerCallback( void* userCB, const void* userData, void* response ) +{ +${event.callback.params.serialization} + ASSERT(jsonResponse->IsValid() == true); + if (jsonResponse->IsValid() == true) { +${event.callback.result.instantiation} + ${info.Title}${method.Name}Callback callback = reinterpret_cast<${info.Title}${method.Name}Callback>(userCB); + callback(userData, ${event.callback.response.instantiation}); + } +} +uint32_t ${info.Title}_Register_${method.Name}( ${event.signature.params}${if.event.params}, ${end.if.event.params}${info.Title}${method.Name}Callback userCB, const void* userData ) +{ + const string eventName = _T("${info.title}.${method.name}"); + uint32_t status = FireboltSDKErrorNone; + + if (userCB != nullptr) { + ${event.params.serialization} + status = FireboltSDK::Event::Instance().Subscribe<${event.result.json.type}>(eventName, jsonParameters, ${info.Title}${method.Name}InnerCallback, reinterpret_cast(userCB), userData); + } + return status; +} +uint32_t ${info.Title}_Unregister_${method.Name}( ${info.Title}${method.Name}Callback userCB) +{ + return FireboltSDK::Event::Instance().Unsubscribe(_T("${info.title}.${method.name}"), reinterpret_cast(userCB)); +} diff --git a/languages/c/templates/methods/property.c b/languages/c/templates/methods/property.c index 0b2843a8..c7510da9 100644 --- a/languages/c/templates/methods/property.c +++ b/languages/c/templates/methods/property.c @@ -2,14 +2,10 @@ uint32_t ${info.title}_Get${method.Name}( ${method.signature.params}${if.params}, ${end.if.params}${method.result.type}* ${method.result.name} ) { const string method = _T("${info.title}.${method.name}"); - JsonObject jsonParameters; - ${if.params} -${method.params.serialization} - ${end.if.params} - +${if.params}${method.params.serialization}${end.if.params} ${method.result.json} jsonResult; - - uint32_t status = FireboltSDK::Properties::Get(method, jsonParameters, jsonResult); + ${if.params}uint32_t status = FireboltSDK::Properties::Get(method, jsonParameters, jsonResult);${end.if.params} + ${if.params.empty}uint32_t status = FireboltSDK::Properties::Get(method, jsonResult);${end.if.params.empty} if (status == FireboltSDKErrorNone) { if (${method.result.name} != nullptr) { ${method.result.instantiation} @@ -17,5 +13,4 @@ uint32_t ${info.title}_Get${method.Name}( ${method.signature.params}${if.params} } return status; } - -${method.setter} \ No newline at end of file +${method.setter} diff --git a/languages/c/templates/modules/src/Module.cpp b/languages/c/templates/modules/src/Module.cpp index d34c1da5..65721f1e 100644 --- a/languages/c/templates/modules/src/Module.cpp +++ b/languages/c/templates/modules/src/Module.cpp @@ -35,6 +35,7 @@ extern "C" { /* ${ACCESSORS} */ /* ${METHODS} */ +/* ${EVENTS} */ #ifdef __cplusplus } diff --git a/languages/c/templates/schemas/src/Module_Common.cpp b/languages/c/templates/schemas/src/Module_Common.cpp index e2389d50..0ccdfc28 100644 --- a/languages/c/templates/schemas/src/Module_Common.cpp +++ b/languages/c/templates/schemas/src/Module_Common.cpp @@ -28,6 +28,7 @@ extern "C" { /* ${ACCESSORS} */ /* ${METHODS} */ + /* ${EVENTS} */ #ifdef __cplusplus } diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 50c10667..85cb67e2 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -47,7 +47,7 @@ const _inspector = obj => { // getSchemaType(schema, module, options = { destination: 'file.txt', title: true }) // getSchemaShape(schema, module, options = { name: 'Foo', destination: 'file.txt' }) // getJsonType(schema, module, options = { name: 'Foo', prefix: '', descriptions: false, level: 0 }) -// getSchemaInstantiation(schema, module, options = {type: 'params' | 'result' | 'event' | 'callback'}) +// getSchemaInstantiation(schema, module, options = {type: 'params' | 'result' | 'callback.params'| 'callback.result' | 'callback.response'}) let types = { getMethodSignature: ()=>null, @@ -70,6 +70,19 @@ const state = { const capitalize = str => str[0].toUpperCase() + str.substr(1) const hasMethodsSchema = (json, options) => json.methods && json.methods.length +const indent = (str, padding) => { + let first = true + return str.split('\n').map(line => { + if (first) { + first = false + return line + } + else { + return padding + line + } + }).join('\n') +} + const setTyper = (t) => { types = t } @@ -1022,9 +1035,9 @@ function insertMethodMacros(template, methodObj, json, templates, examples={}) { const capabilities = getTemplate('/sections/capabilities', templates) + insertCapabilityMacros(getTemplate('/capabilities/default', templates), methodObj.tags.find(t => t.name === "capabilities"), methodObj, json) const result = JSON.parse(JSON.stringify(methodObj.result)) - const event = JSON.parse(JSON.stringify(methodObj)) + const event = isEventMethod(methodObj) ? JSON.parse(JSON.stringify(methodObj)) : '' - if (isEventMethod(methodObj)) { + if (event) { result.schema = JSON.parse(JSON.stringify(getPayloadFromEvent(methodObj))) event.result.schema = getPayloadFromEvent(event) event.params = event.params.filter(p => p.name !== 'listen') @@ -1052,6 +1065,12 @@ function insertMethodMacros(template, methodObj, json, templates, examples={}) { const pullsParamsType = pullsParams ? types.getSchemaShape(pullsParams, json, { destination: state.destination, section: state.section }) : '' const serializedParams = types.getSchemaInstantiation(methodObj, json, methodObj.name, {instantiationType: 'params'}) const resultInst = types.getSchemaInstantiation(result.schema, json, result.name, { instantiationType: 'result' } ) + const serializedEventParams = event ? indent(types.getSchemaInstantiation(event, json, event.name, {instantiationType: 'params'}), ' ') : '' + const callbackSerializedParams = event ? types.getSchemaInstantiation(event, json, event.name, {instantiationType: 'callback.params'}) : '' + const callbackResultInst = event ? types.getSchemaInstantiation(event, json, event.name, {instantiationType: 'callback.result'}) : '' + const callbackResponseInst = event ? types.getSchemaInstantiation(event, json, event.name, {instantiationType: 'callback.response'}) : '' + const resultType = result.schema ? types.getSchemaType(result.schema, json, { name: result.name }) : '' + const resultJsonType = result.schema ? types.getJsonType(result.schema, json, { name: result.name }) : '' let seeAlso = '' if (isPolymorphicPullMethod(methodObj) && pullsForType) { @@ -1083,8 +1102,9 @@ function insertMethodMacros(template, methodObj, json, templates, examples={}) { .replace(/\$\{method\.params\.array\}/g, JSON.stringify(methodObj.params.map(p => p.name))) .replace(/\$\{method\.params\.count}/g, methodObj.params ? methodObj.params.length : 0) .replace(/\$\{if\.params\}(.*?)\$\{end\.if\.params\}/gms, method.params.length ? '$1' : '') - .replace(/\$\{if\.context\}(.*?)\$\{end\.if\.context\}/gms, event.params.length ? '$1' : '') - .replace(/\$\{method\.params\.serialization\}/g, serializedParams) + .replace(/\$\{if\.params.empty\}(.*?)\$\{end\.if\.params.empty\}/gms, method.params.length === 0 ? '$1' : '') + .replace(/\$\{if\.context\}(.*?)\$\{end\.if\.context\}/gms, event && event.params.length ? '$1' : '') + .replace(/\$\{method\.params\.serialization\}/g, serializedParams) // Typed signature stuff .replace(/\$\{method\.signature\}/g, types.getMethodSignature(methodObj, json, { isInterface: false, destination: state.destination, section: state.section })) .replace(/\$\{method\.signature\.params\}/g, types.getMethodSignatureParams(methodObj, json, { destination: state.destination, section: state.section })) @@ -1095,8 +1115,15 @@ function insertMethodMacros(template, methodObj, json, templates, examples={}) { .replace(/\$\{event\.name\}/g, method.name.toLowerCase()[2] + method.name.substr(3)) .replace(/\$\{event\.params\}/g, eventParams) .replace(/\$\{event\.params\.table\.rows\}/g, eventParamsRows) - .replace(/\$\{event\.signature\.params\}/g, types.getMethodSignatureParams(event, json, { destination: state.destination, section: state.section })) + .replace(/\$\{if\.event\.params\}(.*?)\$\{end\.if\.event\.params\}/gms, event && event.params.length ? '$1' : '') + .replace(/\$\{event\.signature\.params\}/g, event ? types.getMethodSignatureParams(event, json, { destination: state.destination, section: state.section }) : '') + .replace(/\$\{event\.signature\.callback\.params\}/g, event ? types.getMethodSignatureParams(event, json, { destination: state.destination, section: state.section, callback: true }) : '') + .replace(/\$\{event\.params\.serialization\}/g, serializedEventParams) + .replace(/\$\{event\.callback\.params\.serialization\}/g, callbackSerializedParams) + .replace(/\$\{event\.callback\.result\.instantiation\}/g, callbackResultInst) + .replace(/\$\{event\.callback\.response\.instantiation\}/g, callbackResponseInst) .replace(/\$\{info\.title\}/g, info.title) + .replace(/\$\{info\.Title\}/g, capitalize(info.title)) .replace(/\$\{info\.TITLE\}/g, info.title.toUpperCase()) .replace(/\$\{method\.property\.immutable\}/g, hasTag(methodObj, 'property:immutable')) .replace(/\$\{method\.property\.readonly\}/g, !getSetterFor(methodObj.name, json)) @@ -1112,9 +1139,10 @@ function insertMethodMacros(template, methodObj, json, templates, examples={}) { .replace(/\$\{method\.result\.link\}/g, getLinkForSchema(result.schema, json, {name : result.name})) //, baseUrl: options.baseUrl .replace(/\$\{method\.result\.type\}/g, types.getSchemaType(result.schema, json, {name: result.name, title: true, asPath: false, destination: state.destination, resultSchema: true })) //, baseUrl: options.baseUrl .replace(/\$\{method\.result\.json\}/, types.getJsonType(result.schema, json, { name: result.name, destination: state.destination, section: state.section, code: false, link: false, title: true, asPath: false, expandEnums: false })) - .replace(/\$\{event\.result\.type\}/, isEventMethod(methodObj) ? types.getSchemaType(result.schema, json, { name: result.name, destination: state.destination, event: true, description: methodObj.result.summary, asPath: false }): '') //, baseUrl: options.baseUrl + .replace(/\$\{event\.result\.type\}/, isEventMethod(methodObj) ? types.getSchemaType(result.schema, json, { name: result.name, destination: state.destination, event: true, description: methodObj.result.summary, asPath: false }): '') + .replace(/\$\{event\.result\.json\.type\}/g, resultJsonType) .replace(/\$\{method\.result\}/g, generateResult(result.schema, json, templates, { name : result.name })) - .replace(/\$\{method\.result\.instantiation\}/g, resultInst) + .replace(/\$\{method\.result\.instantiation\}/g, resultInst) .replace(/\$\{method\.example\.value\}/g, JSON.stringify(methodObj.examples[0].result.value)) .replace(/\$\{method\.alternative\}/g, method.alternative) .replace(/\$\{method\.alternative.link\}/g, '#'+(method.alternative || "").toLowerCase()) @@ -1408,19 +1436,6 @@ function insertProviderInterfaceMacros(template, capability, moduleJson = {}, te while (match = template.match(regex)) { let methodsBlock = '' - const indent = (str, padding) => { - let first = true - return str.split('\n').map(line => { - if (first) { - first = false - return line - } - else { - return padding + line - } - }).join('\n') - } - let i = 1 iface.forEach(method => { @@ -1489,7 +1504,7 @@ export { generateMacros, insertMacros, generateAggregateMacros, - insertAggregateMacros, + insertAggregateMacros } export default {