Skip to content

Commit

Permalink
Merge pull request #211 from rdkcentral/next
Browse files Browse the repository at this point in the history
3.1.1 Release PR
  • Loading branch information
kschrief authored Aug 30, 2024
2 parents 1df6fa8 + f4cbecd commit fb1b09b
Show file tree
Hide file tree
Showing 14 changed files with 85 additions and 13 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
2 changes: 1 addition & 1 deletion languages/cpp/templates/callback-initialization/anyOf.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{property};
std::string ${property};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${property};
${property} = proxyResponse->Value();
2 changes: 1 addition & 1 deletion languages/cpp/templates/json-types/anyOf.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
WPEFramework::Core::JSON::VariantContainer
FireboltSDK::JSON::String
2 changes: 1 addition & 1 deletion languages/cpp/templates/json-types/property-assign.cpp
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Add(_T("${property}"), &${Property});
Add(_T("${property.raw}"), &${Property});
${Property} = other.${Property};
2 changes: 1 addition & 1 deletion languages/cpp/templates/json-types/property-register.cpp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Add(_T("${property}"), &${Property});
Add(_T("${property.raw}"), &${Property});
1 change: 1 addition & 0 deletions languages/javascript/language.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"/index.mjs",
"/defaults.mjs"
],
"enableStringPropertyKeys": true,
"createModuleDirectories": true,
"copySchemasIntoModules": true,
"aggregateFiles": [
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/firebolt-openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1011,6 +1011,13 @@
},
"x-provided-by": {
"type": "string"
},
"x-provider-selection": {
"type": "string",
"enum": [
"focus",
"appId"
]
}
},
"if": {
Expand Down
28 changes: 27 additions & 1 deletion src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
10 changes: 7 additions & 3 deletions src/macrofier/types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/shared/configLoader.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const loadConfig = async (language) => {

export const getConfig = () => {
if (!config) {
return null;
return {};
}
return config
}
5 changes: 5 additions & 0 deletions src/shared/json-schema.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -529,6 +533,7 @@ const getSafeEnumKeyName = (value) => value.split(':').pop()

export {
getSchemaConstraints,
getSafeKeyName,
getSafeEnumKeyName,
getExternalSchemaPaths,
getLocalSchemas,
Expand Down

0 comments on commit fb1b09b

Please sign in to comment.