Skip to content

Commit

Permalink
use String type if there is any issue with anyOf merge (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jul 17, 2023
1 parent 5c194a6 commit 30246aa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
27 changes: 20 additions & 7 deletions languages/c/Types.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function union(schemas, module, commonSchemas) {
//console.warn(`Ignoring "${key}" that is already present and same`)
} else {
console.warn(`ERROR "${key}" is not same -${JSON.stringify(result, null, 4)} ${key} ${result[key]} - ${value}`);
throw "ERROR: type is not same"
return {}
}
} else {
//If the Key is a const then merge them into an enum
Expand Down Expand Up @@ -325,8 +325,14 @@ function getSchemaTypeInfo(module = {}, json = {}, name = '', schemas = {}, pref
}
else if (json.anyOf) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
structure = getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options)
if (mergedSchema.type) {
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
structure = getSchemaTypeInfo(module, mergedSchema, '', schemas, prefixName, options)
}
else {
structure.type = fireboltString ? getFireboltStringType() : 'char*'
structure.json.type = 'string'
}
}
else if (json.type === 'object') {
structure.json = json
Expand Down Expand Up @@ -499,8 +505,10 @@ function getSchemaShapeInfo(json, module, schemas = {}, { name = '', prefix = ''
else if (json.anyOf) {
if (level > 0) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
shape += getSchemaShapeInfo(mergedSchema, module, schemas, { name, prefix: prefixName, merged, level, title, summary, descriptions, destination, section, enums })
if (mergedSchema.type) {
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
shape += getSchemaShapeInfo(mergedSchema, module, schemas, { name, prefix: prefixName, merged, level, title, summary, descriptions, destination, section, enums })
}
}
}
else if (json.oneOf) {
Expand Down Expand Up @@ -689,8 +697,13 @@ function getJsonTypeInfo(module = {}, json = {}, name = '', schemas, prefix = ''
}
else if (json.anyOf) {
let mergedSchema = getMergedSchema(module, json, name, schemas)
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
structure = getJsonTypeInfo(module, mergedSchema, name, schemas, prefixName, {descriptions, level})
if (mergedSchema.type) {
let prefixName = ((prefix.length > 0) && (!name.startsWith(prefix))) ? prefix : capitalize(name)
structure = getJsonTypeInfo(module, mergedSchema, name, schemas, prefixName, {descriptions, level})
}
else {
structure.type = getJsonNativeTypeForOpaqueString()
}
}
else if (json.type === 'object') {
if (hasProperties(json) !== true) {
Expand Down
2 changes: 1 addition & 1 deletion languages/c/src/types/JSONHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const getJsonDataPrefix = () => 'JsonData_'
const wpeJsonNameSpace = () => 'WPEFramework::Core::JSON'

const getJsonDataStructName = (modName, name, prefix = '') => {
let result =((prefix.length > 0) && (prefix !== name)) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`
let result =((prefix && prefix.length > 0) && (prefix !== name)) ? `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(prefix)}${capitalize(name)}` : `${capitalize(modName)}::${getJsonDataPrefix()}${capitalize(name)}`

return ((result.includes(wpeJsonNameSpace()) === true) ? result : `${getSdkNameSpace()}::${result}`)
}
Expand Down
6 changes: 3 additions & 3 deletions languages/c/src/types/NativeHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ const getTypeName = (moduleName, varName, prefix = '', upperCase = false, capita

let mName = upperCase ? moduleName.toUpperCase() : capitalize(moduleName)
let vName = upperCase ? varName.toUpperCase() : capitalCase ? capitalize(varName) : varName
if (prefix.length > 0) {
if (prefix && prefix.length > 0) {
prefix = (prefix !== varName) ? (upperCase ? prefix.toUpperCase() : capitalize(prefix)) : ''
}
prefix = (prefix.length > 0) ?(upperCase ? prefix.toUpperCase() : capitalize(prefix)) : prefix
let name = (prefix.length > 0) ? `${mName}_${prefix}${vName}` : `${mName}_${vName}`
prefix = (prefix && prefix.length > 0) ?(upperCase ? prefix.toUpperCase() : capitalize(prefix)) : prefix
let name = (prefix && prefix.length > 0) ? `${mName}_${prefix}${vName}` : `${mName}_${vName}`
return name
}

Expand Down

0 comments on commit 30246aa

Please sign in to comment.