Skip to content

Commit

Permalink
Ensure: method schemaShape generation is doing only for Modules
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jan 24, 2024
1 parent 6a648fa commit 310636d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion languages/cpp/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"templateExtensionMap": {
"methods": [ "impl.cpp", "cpp" ],
"declarations": ["h"],
"declarations-override": ["impl.h"]
"declarations-override": [ "impl.h" ]
}
}
27 changes: 20 additions & 7 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -363,9 +363,22 @@ const makeProviderMethod = x => x.name["onRequest".length].toLowerCase() + x.nam
//import { default as platform } from '../Platform/defaults'
const generateAggregateMacros = (openrpc, modules, templates, library) => Object.values(modules)
.reduce((acc, module) => {
acc.exports += insertMacros(getTemplate('/codeblocks/export', templates) + '\n', generateMacros(module, templates))
acc.mockImports += insertMacros(getTemplate('/codeblocks/mock-import', templates) + '\n', generateMacros(module, templates))
acc.mockObjects += insertMacros(getTemplate('/codeblocks/mock-parameter', templates) + '\n', generateMacros(module, templates))

let template = getTemplate('/codeblocks/export', templates)
if (template) {
acc.exports += insertMacros(template + '\n', generateMacros(module, templates))
}

template = getTemplate('/codeblocks/mock-import', templates)
if (template) {
acc.mockImports += insertMacros(template + '\n', generateMacros(module, templates))
}

template = getTemplate('/codeblocks/mock-parameter', templates)
if (template) {
acc.mockObjects += insertMacros(template + '\n', generateMacros(module, templates))
}

return acc
}, {
exports: '',
Expand Down Expand Up @@ -560,7 +573,7 @@ const generateMacros = (obj, templates, languages, options = {}) => {
const eventsEnum = generateEvents(obj, templates)

const examples = generateExamples(obj, templates, languages)
const allMethodsArray = generateMethods(obj, examples, templates)
const allMethodsArray = generateMethods(obj, examples, templates, options.type)

Array.from(new Set(['methods'].concat(config.additionalMethodTemplates))).filter(dir => dir).forEach(dir => {

Expand Down Expand Up @@ -1169,7 +1182,7 @@ function generateMethodResult(type, templates) {
return result
}

function generateMethods(json = {}, examples = {}, templates = {}) {
function generateMethods(json = {}, examples = {}, templates = {}, type = '') {
const methods = compose(
option([]),
getMethods
Expand All @@ -1192,13 +1205,13 @@ function generateMethods(json = {}, examples = {}, templates = {}) {
if (dir.includes('declarations') && (suffix && config.templateExtensionMap[dir] ? config.templateExtensionMap[dir].includes(suffix) : true)) {
const template = getTemplateForDeclaration(methodObj, templates, dir)
if (template && template.length) {
result.declaration[dir] = insertMethodMacros(template, methodObj, json, templates, 'declarations', examples)
result.declaration[dir] = insertMethodMacros(template, methodObj, json, templates, '', examples)
}
}
else if (dir.includes('methods') && (suffix && config.templateExtensionMap[dir] ? config.templateExtensionMap[dir].includes(suffix) : true)) {
const template = getTemplateForMethod(methodObj, templates, dir)
if (template && template.length) {
result.body[dir] = insertMethodMacros(template, methodObj, json, templates, 'methods', examples)
result.body[dir] = insertMethodMacros(template, methodObj, json, templates, type, examples)
}
}
})
Expand Down
2 changes: 1 addition & 1 deletion src/macrofier/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const macrofy = async (

// Pick the index and defaults templates for each module.
templatesPerModule.forEach(t => {
const macros = engine.generateMacros(module, templates, exampleTemplates, {hideExcluded: hideExcluded, copySchemasIntoModules: copySchemasIntoModules, createPolymorphicMethods: createPolymorphicMethods, destination: t})
const macros = engine.generateMacros(module, templates, exampleTemplates, {hideExcluded: hideExcluded, copySchemasIntoModules: copySchemasIntoModules, createPolymorphicMethods: createPolymorphicMethods, destination: t, type: 'methods'})
let content = getTemplateForModule(module.info.title, t, templates)

// NOTE: whichever insert is called first also needs to be called again last, so each phase can insert recursive macros from the other
Expand Down

0 comments on commit 310636d

Please sign in to comment.