Skip to content

Commit

Permalink
CPPSDK: getMethodSignatureResult updates based on latest changes
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Oct 10, 2023
1 parent 399d97e commit 12c0562
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 14 deletions.
1 change: 1 addition & 0 deletions languages/cpp/templates/result-callback/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const ${method.result.type}
1 change: 1 addition & 0 deletions languages/cpp/templates/result-callback/nonprimitive.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const ${method.result.type}&
1 change: 1 addition & 0 deletions languages/cpp/templates/result-callback/string.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const ${method.result.type}&
1 change: 1 addition & 0 deletions languages/cpp/templates/result/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
const ${method.result.type}
4 changes: 2 additions & 2 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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' }) : ''

Expand Down Expand Up @@ -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)
Expand Down
28 changes: 16 additions & 12 deletions src/macrofier/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}
Expand All @@ -243,7 +247,7 @@ const insertObjectMacros = (content, schema, module, title, property, options) =
}
})
}

if (type) {
options2.property = prop
const schemaShape = getSchemaShape(type, module, options2)
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 12c0562

Please sign in to comment.