Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use String type if there is any issue with anyOf merge #114

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading