From 12c05621be07f5785215480aee465656c9401424 Mon Sep 17 00:00:00 2001 From: HaseenaSainul Date: Tue, 10 Oct 2023 06:28:07 -0400 Subject: [PATCH] CPPSDK: getMethodSignatureResult updates based on latest changes --- .../cpp/templates/result-callback/default.h | 1 + .../templates/result-callback/nonprimitive.h | 1 + .../cpp/templates/result-callback/string.h | 1 + languages/cpp/templates/result/default.h | 1 + src/macrofier/engine.mjs | 4 +-- src/macrofier/types.mjs | 28 +++++++++++-------- 6 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 languages/cpp/templates/result-callback/default.h create mode 100644 languages/cpp/templates/result-callback/nonprimitive.h create mode 100644 languages/cpp/templates/result-callback/string.h create mode 100644 languages/cpp/templates/result/default.h diff --git a/languages/cpp/templates/result-callback/default.h b/languages/cpp/templates/result-callback/default.h new file mode 100644 index 00000000..d66fdb8a --- /dev/null +++ b/languages/cpp/templates/result-callback/default.h @@ -0,0 +1 @@ +const ${method.result.type} \ No newline at end of file diff --git a/languages/cpp/templates/result-callback/nonprimitive.h b/languages/cpp/templates/result-callback/nonprimitive.h new file mode 100644 index 00000000..84b86816 --- /dev/null +++ b/languages/cpp/templates/result-callback/nonprimitive.h @@ -0,0 +1 @@ +const ${method.result.type}& \ No newline at end of file diff --git a/languages/cpp/templates/result-callback/string.h b/languages/cpp/templates/result-callback/string.h new file mode 100644 index 00000000..84b86816 --- /dev/null +++ b/languages/cpp/templates/result-callback/string.h @@ -0,0 +1 @@ +const ${method.result.type}& \ No newline at end of file diff --git a/languages/cpp/templates/result/default.h b/languages/cpp/templates/result/default.h new file mode 100644 index 00000000..d66fdb8a --- /dev/null +++ b/languages/cpp/templates/result/default.h @@ -0,0 +1 @@ +const ${method.result.type} \ No newline at end of file diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 80173a48..b5527ac6 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1207,7 +1207,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) // todo: what does prefix do in Types.mjs? need to account for it somehow const callbackResultJsonType = event && result.schema ? types.getSchemaType(result.schema, json, { name: result.name, prefix: method.alternative, templateDir: 'json-types' }) : '' - const pullsForParamType = pullsParams ? types.getSchemaType(pullsParams, json, { destination: state.destination, section: state.section }) : '' + const pullsForParamType = pullsParams ? types.getSchemaType(pullsParams, json, { destination: state.destination, section: state.section }) : '' const pullsForJsonType = pullsResult ? types.getSchemaType(pullsResult, json, { name: result.name, templateDir: 'json-types' }) : '' const pullsForParamJsonType = pullsParams ? types.getSchemaType(pullsParams, json, { name: pullsParams.title , templateDir: 'json-types' }) : '' @@ -1289,7 +1289,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {}) .replace(/\$\{method\.result\.type\}/g, types.getSchemaType(result.schema, json, { name: result.name, templateDir: state.typeTemplateDir, title: true, asPath: false, destination: state.destination, result: true })) //, baseUrl: options.baseUrl .replace(/\$\{method\.result\.json\}/, types.getSchemaType(result.schema, json, { name: result.name, templateDir: 'json-types', destination: state.destination, section: state.section, title: true, code: false, link: false, asPath: false, expandEnums: false, namespace: true })) // todo: what does prefix do? - .replace(/\$\{event\.result\.type\}/g, isEventMethod(methodObj) ? types.getMethodSignatureResult(event, json, { destination: state.destination, section: state.section }) : '') + .replace(/\$\{event\.result\.type\}/g, isEventMethod(methodObj) ? types.getMethodSignatureResult(event, json, { destination: state.destination, section: state.section, callback: true }) : '') .replace(/\$\{event\.result\.json\.type\}/g, resultJsonType) .replace(/\$\{event\.result\.json\.type\}/g, callbackResultJsonType) .replace(/\$\{event\.pulls\.param\.name\}/g, pullsEventParamName) diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index 4ac00b73..996d8a7d 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -78,22 +78,26 @@ function getMethodSignatureParams(method, module, { destination, callback }) { }).join(', ') } -function getMethodSignatureResult(method, module, { destination, callback }) { +function getMethodSignatureResult(method, module, { destination, callback, overrideRule = false }) { let type = getSchemaType(method.result.schema, module, { destination, namespace : true }) - let result = '' - let jsonType = getJsonType(method.result.schema, module, { destination }) - if (!isVoid(type) && !isPrimitiveType(jsonType) && getTemplate('/result/nonprimitive')) { - result = getTemplate('/result/nonprimitive') - } - else if ((jsonType === 'string') && getTemplate('/result/string')) { - result = getTemplate('/result/string') + if (callback) { + let jsonType = getJsonType(method.result.schema, module, { destination }) + + if (!isVoid(type) && !isPrimitiveType(jsonType) && getTemplate('/result-callback/nonprimitive')) { + result = getTemplate('/result-callback/nonprimitive') + } + else if ((jsonType === 'string') && getTemplate('/result-callback/string')) { + result = getTemplate('/result-callback/string') + } + else { + result = getTemplate('/result-callback/default') + } } else { result = getTemplate('/result/default') } - return result.replace(/\$\{method\.result\.type\}/g, type) } @@ -230,7 +234,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = } // TODO: add language config feature for 'unknown' type let type; // = { type: "null" } - + if (schema.additionalProperties && (typeof schema.additionalProperties === 'object')) { type = schema.additionalProperties } @@ -243,7 +247,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) = } }) } - + if (type) { options2.property = prop const schemaShape = getSchemaShape(type, module, options2) @@ -354,7 +358,7 @@ function getSchemaShape(schema = {}, module = {}, { templateDir = 'types', name if (level === 0 && !schema.title) { return '' } - + const suffix = destination && ('.' + destination.split('.').pop()) || '' const theTitle = insertSchemaMacros(getTemplate(path.join(templateDir, 'title' + suffix)), schema, module, schema.title || name, parent, property, false)