Skip to content

Commit

Permalink
fix: CPP Enum/AnyOf (#210)
Browse files Browse the repository at this point in the history
* fix: Safe name issue reverted from javascript

* fix: Adjust anyOf templates for events

* fix: Make anyOf templates strings

* fix: Revert debug change

* fix: Add enum changes into this branch

* fix: Remove unneeded changes

---------

Co-authored-by: Shah, Kevin <[email protected]>
Co-authored-by: kschri201_comcast <[email protected]>
  • Loading branch information
3 people authored Aug 30, 2024
1 parent 665aad3 commit eb768fb
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 7 deletions.
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});
6 changes: 4 additions & 2 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 @@ -318,7 +318,7 @@ 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) : getSafeEnumKeyName(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 @@ -350,6 +350,8 @@ 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.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)
Expand Down
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 eb768fb

Please sign in to comment.