Skip to content

Commit

Permalink
review update
Browse files Browse the repository at this point in the history
  • Loading branch information
HaseenaSainul committed Jul 13, 2023
1 parent b7e8758 commit 600899a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
12 changes: 0 additions & 12 deletions languages/c/src/types/NativeHelpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,7 @@ const { isObject, isArray, propEq, pathSatisfies, hasProp, propSatisfies } = pre
const getModuleName = json => getPathOr(null, ['info', 'title'], json) || json.title || 'missing'

const getFireboltStringType = () => 'FireboltTypes_String_t'
const getHeaderText = () => {

return `/*
* Copyright 2022 Comcast
*
* Auto Generated using firebolt-openrpc tools. DO NOT EDIT.
*
*/
`
}

const capitalize = str => str[0].toUpperCase() + str.substr(1)
const description = (title, str='') => '/* ' + title + (str.length > 0 ? ' - ' + str : '') + ' */'
const isOptional = (prop, json) => (!json.required || !json.required.includes(prop))
Expand Down Expand Up @@ -204,7 +193,6 @@ function getPropertyEventUnregisterSignature(property, module) {


export {
getHeaderText,
getNativeType,
getModuleName,
getPropertyGetterSignature,
Expand Down
14 changes: 7 additions & 7 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const getComponentExternalSchema = (json) => {
let title = ''
if (ref.includes('x-schemas')) {
if (ref.split('/')[2] !== json.info.title) {
title = ref.split('/')[2].toLowerCase()
title = ref.split('/')[2]
}
}
title && !refSchemas.includes(title) ? refSchemas.push(title) : null
Expand Down Expand Up @@ -361,7 +361,7 @@ const addContentDescriptorSubSchema = (descriptor, prefix, obj) => {
}

// only consider sub-objects and sub enums to be sub-schemas
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum)
const isSubSchema = (schema) => schema.type === 'object' || (schema.type === 'string' && schema.enum) || (schema.type === 'array' && schema.items)

const promoteAndNameSubSchemas = (obj) => {
// make a copy so we don't polute our inputs
Expand Down Expand Up @@ -584,11 +584,11 @@ function insertTableofContents(content) {
}

const convertEnumTemplate = (schema, templateName, templates) => {
let enm = getEnum(schema)
let enumSchema = isArraySchema(schema) ? schema.items : schema
const template = getTemplate(templateName, templates).split('\n')
for (var i = 0; i < template.length; i++) {
if (template[i].indexOf('${key}') >= 0) {
template[i] = enm.enum.map(value => {
template[i] = enumSchema.enum.map(value => {
const safeName = value.split(':').pop().replace(/[\.\-]/g, '_').replace(/\+/g, '_plus').replace(/([a-z])([A-Z0-9])/g, '$1_$2').toUpperCase()
return template[i].replace(/\$\{key\}/g, safeName)
.replace(/\$\{value\}/g, value)
Expand Down Expand Up @@ -694,11 +694,11 @@ function sortSchemasByReference(schemas = []) {
return schemas
}

const getEnum = x => x.type && x.type === 'array' ? x.items : x
const isArraySchema = x => x.type && x.type === 'array' && x.items

const isEnum = x => {
let enm = getEnum(x)
return enm.type && enm.type === 'string' && Array.isArray(enm.enum) && x.title
let schema = isArraySchema(x) ? x.items : x
return schema.type && schema.type === 'string' && Array.isArray(schema.enum) && x.title
}

function generateSchemas(json, templates, options) {
Expand Down

0 comments on commit 600899a

Please sign in to comment.