diff --git a/CHANGELOG.md b/CHANGELOG.md index 71170e34..8ad03536 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,32 @@ +## [3.1.1-next.4](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.1.1-next.3...v3.1.1-next.4) (2024-08-30) + + +### Bug Fixes + +* CPP Enum/AnyOf ([#210](https://github.com/rdkcentral/firebolt-openrpc/issues/210)) ([eb768fb](https://github.com/rdkcentral/firebolt-openrpc/commit/eb768fb5f0d8ce4c123daab428bd53ca7225333c)) + +## [3.1.1-next.3](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.1.1-next.2...v3.1.1-next.3) (2024-08-26) + + +### Bug Fixes + +* Update getSuffix to properly work in pipeline ([#209](https://github.com/rdkcentral/firebolt-openrpc/issues/209)) ([16b4e6e](https://github.com/rdkcentral/firebolt-openrpc/commit/16b4e6eb5a8739a7715eb975104d7bb33053b28c)) + +## [3.1.1-next.2](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.1.1-next.1...v3.1.1-next.2) (2024-08-23) + + +### Bug Fixes + +* Quote unsafe property names in languages that support it ([647043d](https://github.com/rdkcentral/firebolt-openrpc/commit/647043d59ea0399b725d32e4a2e48ee017965288)) +* Return empty config, not null ([f02aadc](https://github.com/rdkcentral/firebolt-openrpc/commit/f02aadcb57f3936f1dcebfe570e418c1d04f626d)) + +## [3.1.1-next.1](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.1.0...v3.1.1-next.1) (2024-08-21) + + +### Bug Fixes + +* Add provider-selection tag to validation schema ([756e88a](https://github.com/rdkcentral/firebolt-openrpc/commit/756e88a92782c8d65ec481182c31c8edb218c9d6)) + # [3.1.0](https://github.com/rdkcentral/firebolt-openrpc/compare/v3.0.0...v3.1.0) (2024-08-08) diff --git a/languages/cpp/templates/callback-initialization/anyOf.cpp b/languages/cpp/templates/callback-initialization/anyOf.cpp index 30f233a7..92a17554 100644 --- a/languages/cpp/templates/callback-initialization/anyOf.cpp +++ b/languages/cpp/templates/callback-initialization/anyOf.cpp @@ -1 +1 @@ -{property}; + std::string ${property}; diff --git a/languages/cpp/templates/callback-result-instantiation/anyOf.cpp b/languages/cpp/templates/callback-result-instantiation/anyOf.cpp index 120561dd..6d8fa873 100644 --- a/languages/cpp/templates/callback-result-instantiation/anyOf.cpp +++ b/languages/cpp/templates/callback-result-instantiation/anyOf.cpp @@ -1 +1 @@ - ${property}; \ No newline at end of file + ${property} = proxyResponse->Value(); \ No newline at end of file diff --git a/languages/cpp/templates/json-types/anyOf.h b/languages/cpp/templates/json-types/anyOf.h index fc121f63..2d60a3c8 100644 --- a/languages/cpp/templates/json-types/anyOf.h +++ b/languages/cpp/templates/json-types/anyOf.h @@ -1 +1 @@ -WPEFramework::Core::JSON::VariantContainer \ No newline at end of file +FireboltSDK::JSON::String \ No newline at end of file diff --git a/languages/cpp/templates/json-types/property-assign.cpp b/languages/cpp/templates/json-types/property-assign.cpp index 36bdbf83..ffdad03d 100644 --- a/languages/cpp/templates/json-types/property-assign.cpp +++ b/languages/cpp/templates/json-types/property-assign.cpp @@ -1,2 +1,2 @@ - Add(_T("${property}"), &${Property}); + Add(_T("${property.raw}"), &${Property}); ${Property} = other.${Property}; diff --git a/languages/cpp/templates/json-types/property-register.cpp b/languages/cpp/templates/json-types/property-register.cpp index 01e2a7e0..e4f9a2b2 100644 --- a/languages/cpp/templates/json-types/property-register.cpp +++ b/languages/cpp/templates/json-types/property-register.cpp @@ -1 +1 @@ - Add(_T("${property}"), &${Property}); \ No newline at end of file + Add(_T("${property.raw}"), &${Property}); \ No newline at end of file diff --git a/languages/javascript/language.config.json b/languages/javascript/language.config.json index 19b4659d..6c5452f5 100644 --- a/languages/javascript/language.config.json +++ b/languages/javascript/language.config.json @@ -5,6 +5,7 @@ "/index.mjs", "/defaults.mjs" ], + "enableStringPropertyKeys": true, "createModuleDirectories": true, "copySchemasIntoModules": true, "aggregateFiles": [ diff --git a/package-lock.json b/package-lock.json index bd8515c2..14676f1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@firebolt-js/openrpc", - "version": "3.1.0", + "version": "3.1.1-next.4", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@firebolt-js/openrpc", - "version": "3.1.0", + "version": "3.1.1-next.4", "license": "Apache-2.0", "dependencies": { "ajv": "^8.12.0", diff --git a/package.json b/package.json index 2ac0e2d3..8b766e9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@firebolt-js/openrpc", - "version": "3.1.0", + "version": "3.1.1-next.4", "description": "The Firebolt SDK Code & Doc Generator", "main": "languages/javascript/src/sdk.mjs", "type": "module", diff --git a/src/firebolt-openrpc.json b/src/firebolt-openrpc.json index 4146ea75..aac66665 100644 --- a/src/firebolt-openrpc.json +++ b/src/firebolt-openrpc.json @@ -1011,6 +1011,13 @@ }, "x-provided-by": { "type": "string" + }, + "x-provider-selection": { + "type": "string", + "enum": [ + "focus", + "appId" + ] } }, "if": { diff --git a/src/macrofier/engine.mjs b/src/macrofier/engine.mjs index aedcc4e9..51f469a8 100644 --- a/src/macrofier/engine.mjs +++ b/src/macrofier/engine.mjs @@ -1161,7 +1161,33 @@ function generateMethods(json = {}, examples = {}, templates = {}, languages = [ event: isEventMethod(methodObj) } - const suffix = state.destination && config.templateExtensionMap ? state.destination.split(state.destination.includes('_') ? '_' : '.').pop() : '' + + /** + * Extracts the suffix from a given file path. + * + * The suffix is determined by the last underscore or period in the filename. + * If the filename contains an underscore, the portion after the last underscore + * is considered the suffix. If no underscore is found but there is a period, + * the portion after the last period (typically the file extension) is considered the suffix. + * If neither an underscore nor a period is found, an empty string is returned. + * + * @param {string} path - The full file path from which to extract the suffix. + * @returns {string} - The extracted suffix or an empty string if no suffix is found. + */ + const getSuffix = (path) => { + // Extract the last part of the path (the filename) + const filename = path.split('/').pop() // Get the last part of the path + // Check for underscores or periods in the filename and handle accordingly + if (filename.includes('_')) { + return filename.split('_').pop() // Return the last part after the last underscore + } else if (filename.includes('.')) { + return filename.split('.').pop() // Return the extension after the last period + } else { + return '' // Return empty if no suffix can be determined + } + } + + const suffix = state.destination && config.templateExtensionMap ? getSuffix(state.destination) : '' // Generate implementation of methods/events for both dynamic and static configured templates Array.from(new Set(['methods'].concat(config.additionalMethodTemplates))).filter(dir => dir).forEach(dir => { diff --git a/src/macrofier/types.mjs b/src/macrofier/types.mjs index acfb0d9b..5fa445f5 100644 --- a/src/macrofier/types.mjs +++ b/src/macrofier/types.mjs @@ -17,7 +17,7 @@ */ import deepmerge from 'deepmerge' -import { getPath, localizeDependencies, getSafeEnumKeyName } from '../shared/json-schema.mjs' +import { getPath, localizeDependencies, getSafeEnumKeyName, getSafeKeyName } from '../shared/json-schema.mjs' import path from "path" import { getConfig } from '../shared/configLoader.mjs' @@ -317,6 +317,8 @@ const insertObjectPatternPropertiesMacros = (content, schema, module, title, opt } const getIndents = level => level ? ' ' : '' +const wrapProp = name => name.match(/[/\.\+]/) ? `"${name}"` : name +const safePropName = name => config.enableStringPropertyKeys ? wrapProp(name) : getSafeKeyName(name) const insertObjectMacros = (content, schema, module, title, property, options) => { const options2 = options ? JSON.parse(JSON.stringify(options)) : {} options2.parent = title @@ -348,8 +350,10 @@ const insertObjectMacros = (content, schema, module, title, property, options) = const description = getSchemaDescription(prop, module) let replacedTemplate = template .replace(/(^\s+)/g, '$1'.repeat(options2.level)) - .replace(/\$\{property\}/g, name) - .replace(/\$\{Property\}/g, capitalize(name)) + .replace(/\$\{property.raw\}/g, name) //Gives the raw RPC propery name, even if it's unsafe + .replace(/\$\{Property.raw\}/g, capitalize(name)) + .replace(/\$\{property\}/g, safePropName(name)) + .replace(/\$\{Property\}/g, capitalize(safePropName(name))) .replace(/\$\{parent\.title\}/g, title) .replace(/\$\{title\}/g, type) .replace(/\$\{shape\}/g, schemaShape) diff --git a/src/shared/configLoader.mjs b/src/shared/configLoader.mjs index 644a7f4e..ca9f8fb5 100644 --- a/src/shared/configLoader.mjs +++ b/src/shared/configLoader.mjs @@ -12,7 +12,7 @@ export const loadConfig = async (language) => { export const getConfig = () => { if (!config) { - return null; + return {}; } return config } diff --git a/src/shared/json-schema.mjs b/src/shared/json-schema.mjs index f140cfd2..db13a833 100644 --- a/src/shared/json-schema.mjs +++ b/src/shared/json-schema.mjs @@ -520,6 +520,10 @@ function mergeOneOf(schema) { return union(schema.oneOf) } +const getSafeKeyName = (value) => value.split(':').pop() + .replace(/[\.\-]/g, '_') // replace dots and dashes + .replace(/\+/g, '_plus') // change + to _plus + const getSafeEnumKeyName = (value) => value.split(':').pop() // use last portion of urn:style:values .replace(/[\.\-]/g, '_') // replace dots and dashes .replace(/\+/g, '_plus') // change + to _plus @@ -529,6 +533,7 @@ const getSafeEnumKeyName = (value) => value.split(':').pop() export { getSchemaConstraints, + getSafeKeyName, getSafeEnumKeyName, getExternalSchemaPaths, getLocalSchemas,