diff --git a/languages/c/language.config.json b/languages/c/language.config.json index 97e90519..4604ebdb 100644 --- a/languages/c/language.config.json +++ b/languages/c/language.config.json @@ -11,5 +11,6 @@ "/src/Module_Common.cpp", "/src/JsonData_Module.h" ], - "persistPermission": true + "persistPermission": true, + "includeAnonymousSchema": true } diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 5484c761..ec233f56 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -175,15 +175,15 @@ const getMethods = compose( getPath(['methods']) ) -const getComponentSchemas = compose( +const getSchemas = compose( map(Object.entries), // Maybe Array> chain(safe(isObject)), // Maybe Object getPath(['components', 'schemas']) // Maybe any ) -const getSchemas = (schema) => { +const getAllSchemas = (schema) => { let methods = getMethods(schema) - let components = getComponentSchemas(schema) + let components = getSchemas(schema) let allSchema = [] methods.map((schemas) => { @@ -386,7 +386,7 @@ const generateMacros = (obj, templates, languages, options = {}) => { const imports = generateImports(obj, templates, { destination : (options.destination ? options.destination : '') }) const initialization = generateInitialization(obj, templates) - const enums = generateEnums(obj, templates, { destination : (options.destination ? options.destination : '') }) + const enums = generateEnums(obj, templates, { destination : (options.destination ? options.destination : ''), includeAnonymous : options.includeAnonymousSchema }) const eventsEnum = generateEvents(obj, templates) const examples = generateExamples(obj, templates, languages) @@ -620,7 +620,7 @@ const enumFinder = compose( filter(([_key, val]) => isObject(val)) ) -const generateEnums = (json, templates, options = { destination: '' }) => { +const generateEnums = (json, templates, options = { destination: '', includeAnonymous: false }) => { const suffix = options.destination.split('.').pop() return compose( map(val => { @@ -630,7 +630,7 @@ const generateEnums = (json, templates, options = { destination: '' }) => { map(reduce((acc, val) => acc.concat(val).concat('\n'), '')), map(map((schema) => convertEnumTemplate(schema, suffix ? `/types/enum.${suffix}` : '/types/enum', templates))), map(enumFinder), - getSchemas + options.includeAnonymous ? getAllSchemas: getSchemas )(json) } diff --git a/src/macrofier/index.mjs b/src/macrofier/index.mjs index b1d61ee4..c925486a 100644 --- a/src/macrofier/index.mjs +++ b/src/macrofier/index.mjs @@ -44,6 +44,7 @@ const macrofy = async ( templatesPerModule, templatesPerSchema, persistPermission, + includeAnonymousSchema, createModuleDirectories, copySchemasIntoModules, aggregateFile, @@ -159,7 +160,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, destination: t}) + const macros = engine.generateMacros(module, templates, exampleTemplates, {hideExcluded: hideExcluded, copySchemasIntoModules: copySchemasIntoModules, includeAnonymousSchema: includeAnonymousSchema, destination: t}) 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 @@ -174,7 +175,7 @@ const macrofy = async ( }) if (primaryOutput) { - const macros = engine.generateMacros(module, templates, exampleTemplates, {hideExcluded: hideExcluded, copySchemasIntoModules: copySchemasIntoModules, destination: primaryOutput}) + const macros = engine.generateMacros(module, templates, exampleTemplates, {hideExcluded: hideExcluded, copySchemasIntoModules: copySchemasIntoModules, includeAnonymousSchema: includeAnonymousSchema, destination: primaryOutput}) macros.append = append outputFiles[primaryOutput] = engine.insertMacros(outputFiles[primaryOutput], macros) } @@ -256,7 +257,7 @@ const macrofy = async ( Object.values(externalSchemas).forEach( document => { if (templatesPerSchema) { templatesPerSchema.forEach( t => { - const macros = engine.generateMacros(document, templates, exampleTemplates, {hideExcluded: hideExcluded, destination: t}) + const macros = engine.generateMacros(document, templates, exampleTemplates, {hideExcluded: hideExcluded, includeAnonymousSchema: includeAnonymousSchema, destination: t}) let content = getTemplate('/schemas', 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 diff --git a/src/sdk/index.mjs b/src/sdk/index.mjs index c5727cfc..51c919ca 100755 --- a/src/sdk/index.mjs +++ b/src/sdk/index.mjs @@ -58,6 +58,7 @@ const run = async ({ templatesPerModule: config.templatesPerModule, templatesPerSchema: config.templatesPerSchema, persistPermission: config.persistPermission, + includeAnonymousSchema: config.includeAnonymousSchema, operators: config.operators, createModuleDirectories: config.createModuleDirectories, copySchemasIntoModules: config.copySchemasIntoModules,