Skip to content

Commit

Permalink
Anonymous config flag is added to support anonymous schema processing…
Browse files Browse the repository at this point in the history
… based on language requirement
  • Loading branch information
HaseenaSainul committed Jun 22, 2023
1 parent 1cacbd1 commit a1f42f2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 10 deletions.
3 changes: 2 additions & 1 deletion languages/c/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@
"/src/Module_Common.cpp",
"/src/JsonData_Module.h"
],
"persistPermission": true
"persistPermission": true,
"includeAnonymousSchema": true
}
12 changes: 6 additions & 6 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ const getMethods = compose(
getPath(['methods'])
)

const getComponentSchemas = compose(
const getSchemas = compose(
map(Object.entries), // Maybe Array<Array<key, value>>
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) => {
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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 => {
Expand All @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions src/macrofier/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const macrofy = async (
templatesPerModule,
templatesPerSchema,
persistPermission,
includeAnonymousSchema,
createModuleDirectories,
copySchemasIntoModules,
aggregateFile,
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/sdk/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a1f42f2

Please sign in to comment.