diff --git a/languages/c/templates/imports/default.c b/languages/c/templates/imports/default.cpp similarity index 100% rename from languages/c/templates/imports/default.c rename to languages/c/templates/imports/default.cpp diff --git a/languages/c/templates/imports/default.h b/languages/c/templates/imports/default.h new file mode 100644 index 00000000..a38b58ef --- /dev/null +++ b/languages/c/templates/imports/default.h @@ -0,0 +1 @@ +#include "Common/${info.title}.h" diff --git a/languages/c/templates/imports/default.jsondata b/languages/c/templates/imports/default.jsondata new file mode 100644 index 00000000..69e241f9 --- /dev/null +++ b/languages/c/templates/imports/default.jsondata @@ -0,0 +1 @@ +#include "JsonData_${info.title}.h" diff --git a/languages/c/templates/modules/include/Common/Module.h b/languages/c/templates/modules/include/Common/Module.h deleted file mode 100644 index 809418a2..00000000 --- a/languages/c/templates/modules/include/Common/Module.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef _COMMON_${info.TITLE}_H -#define _COMMON_${info.TITLE}_H - -#include "Firebolt.h" - -#ifdef __cplusplus -extern "C" { -#endif - -// Enums - -/* ${ENUMS} */ - -// Schemas - -/* ${SCHEMAS} */ - -#ifdef __cplusplus -} -#endif - -#endif // Header Include Guard diff --git a/languages/c/templates/modules/src/JsonData_Module.h b/languages/c/templates/modules/src/JsonData_Module.h deleted file mode 100644 index 2c7ca8c8..00000000 --- a/languages/c/templates/modules/src/JsonData_Module.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2023 Comcast Cable Communications Management, LLC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#pragma once - -#include "Firebolt.h" - -namespace FireboltSDK { - namespace ${info.title} { - - /* ${SCHEMAS}} */ - - } -} diff --git a/languages/c/templates/schemas/src/JsonData_Module.h b/languages/c/templates/schemas/src/JsonData_Module.h index 7c096b94..d0ecbbac 100644 --- a/languages/c/templates/schemas/src/JsonData_Module.h +++ b/languages/c/templates/schemas/src/JsonData_Module.h @@ -18,6 +18,7 @@ #pragma once +/* ${IMPORTS} */ #include "Common/${info.title}.h" namespace FireboltSDK { diff --git a/languages/c/templates/schemas/src/Module_Common.cpp b/languages/c/templates/schemas/src/Module_Common.cpp index b46a1d8f..e2389d50 100644 --- a/languages/c/templates/schemas/src/Module_Common.cpp +++ b/languages/c/templates/schemas/src/Module_Common.cpp @@ -17,6 +17,7 @@ */ #include "FireboltSDK.h" +/* ${IMPORTS} */ #include "JsonData_${info.title}.h" /* ${ENUMS} */ diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index 5ac37109..a2c64ec0 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -338,7 +338,7 @@ const generateMacros = (obj, templates, languages, options = {}) => { // grab the options so we don't have to pass them from method to method Object.assign(state, options) - const imports = generateImports(obj, templates) + 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 eventsEnum = generateEvents(obj, templates) @@ -759,7 +759,7 @@ function getRelatedSchemaLinks(schema = {}, json = {}, templates = {}, options = return links } -const generateImports = (json, templates) => { +const generateImports = (json, templates, options = { destination: '' }) => { let imports = '' if (rpcMethodsOrEmptyArray(json).length) { @@ -789,14 +789,21 @@ const generateImports = (json, templates) => { if (methodsWithXMethodsInResult(json).length) { imports += getTemplate('/imports/x-method', templates) } + const suffix = options.destination.split('.').pop() + const prefix = options.destination.split('/').pop().split('_')[0].toLowerCase() + + let template = prefix ? getTemplate(`/imports/default.${prefix}`, templates) : '' + if (!template) { + template = getTemplate(suffix ? `/imports/default.${suffix}` : '/imports/default', templates) + } if (json['x-schemas'] && Object.keys(json['x-schemas']).length > 0 && !json.info['x-uri-titles']) { - imports += Object.keys(json['x-schemas']).map(shared => getTemplate('/imports/default', templates).replace(/\$\{info.title\}/g, shared)).join('') + imports += Object.keys(json['x-schemas']).map(shared => template.replace(/\$\{info.title\}/g, shared)).join('') } let componentExternalSchema = getComponentExternalSchema(json) if (componentExternalSchema.length && json.info['x-uri-titles']) { - imports += componentExternalSchema.map(shared => getTemplate('/imports/default', templates).replace(/\$\{info.title\}/g, shared)).join('') + imports += componentExternalSchema.map(shared => template.replace(/\$\{info.title\}/g, shared)).join('') } return imports }