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

feature/cpp branch alignment based on next branch merging for both openrpc and apis #171

Merged
merged 1 commit into from
Mar 5, 2024
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
${if.optional}if (proxyResponse->${Property}.IsSet()) {
${base.title}.${property} = std::make_optional<${type}>();
auto index(proxyResponse->${Property}.Elements());
${if.optional}if ((*proxyResponse)${Property.dependency}.${Property}.IsSet()) {
${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property} = std::make_optional<${type}>();
auto index((*proxyResponse)${Property.dependency}.${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}
}${end.if.optional}${if.non.optional}auto index(proxyResponse->${Property}.Elements());
}${end.if.optional}${if.non.optional}auto index((*proxyResponse)${Property.dependency}.${Property}.Elements());
while (index.Next() == true) {
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
${if.object}${items.with.indent}${end.if.object}${if.non.object} ${base.title}${property.dependency}${if.impl.optional}.value()${end.if.impl.optional}.${property}.value().push_back(index.Current().Value());${end.if.non.object}
}${end.if.non.optional}
1 change: 1 addition & 0 deletions languages/cpp/templates/methods/property.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
${method.signature.result} ${info.Title}Impl::${method.name}( ${method.signature.params}${if.params}, ${end.if.params}Firebolt::Error *err ) const
{
const string method = _T("${info.title.lowercase}.${method.name}");
${if.params}JsonObject jsonParameters;${end.if.params}
${if.params}${method.params.serialization}${end.if.params}
${method.result.json} jsonResult;
${method.result.initialization}
Expand Down
2 changes: 1 addition & 1 deletion languages/javascript/templates/declarations/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
*
${method.params.annotations}${if.deprecated} * @deprecated ${method.deprecation}
${end.if.deprecated} */
function ${method.name}(${method.signature.params}): Promise<${method.result.type}>
function ${method.name}(${method.signature.params}): Promise<${method.result.type}>
1 change: 0 additions & 1 deletion languages/javascript/templates/schemas/default.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* ${schema.description}
*/

${schema.shape}
5 changes: 1 addition & 4 deletions languages/javascript/templates/types/default.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
/*
* ${title} - ${description}
*/
type ${title} = ${shape}
type ${title} = ${shape}
3 changes: 0 additions & 3 deletions languages/javascript/templates/types/enum.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
* ${title} - ${description}
*/
${title}: {
${key}: '${value}',
},
3 changes: 0 additions & 3 deletions languages/javascript/templates/types/enum.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
/*
* ${title} - ${description}
*/
enum ${title} {
${key} = '${value}',
}
2 changes: 1 addition & 1 deletion languages/javascript/templates/types/property.mjs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
${property}${if.optional}?${end.if.optional}: ${title} // ${summary}
${property}${if.optional}?${end.if.optional}: ${title} // ${summary}
18 changes: 14 additions & 4 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ const enumFinder = compose(
filter(([_key, val]) => isObject(val))
)

const generateEventEnums = (json, templates, options = { destination: '' }) => {
const generateEnums = (json, templates, options = { destination: '' }) => {
const suffix = options.destination.split('.').pop()
return compose(
option(''),
Expand Down Expand Up @@ -855,7 +855,7 @@ const generateEvents = (json, templates) => {
return acc
}, null)

return generateEventEnums(obj, templates)
return generateEnums(obj, templates)
}

function generateDefaults(json = {}, templates) {
Expand Down Expand Up @@ -1732,7 +1732,11 @@ function generateProviderSubscribe(json, templates) {
function generateProviderInterfaces(json, templates) {
const interfaces = getProvidedCapabilities(json)
const suffix = state.destination ? state.destination.split('.').pop() : ''
let template = getTemplate(suffix ? `/sections/provider-interfaces.${suffix}` : '/sections/provider-interfaces', templates)

let template
if (suffix) {
template = getTemplate(`/sections/provider-interfaces.${suffix}`, templates)
}
if (!template) {
template = getTemplate('/sections/provider-interfaces', templates)
}
Expand Down Expand Up @@ -1814,8 +1818,14 @@ function insertProviderInterfaceMacros(template, capability, moduleJson = {}, te
.replace(/\$\{capability\}/g, capability)
.replace(/[ \t]*\$\{methods\}[ \t]*\n/g, iface.map(method => {
const focusable = method.tags.find(t => t['x-allow-focus'])
let interfaceDeclaration;
const interfaceTemplate = '/interfaces/' + (focusable ? 'focusable' : 'default')
const interfaceDeclaration = getTemplate(suffix ? `${interfaceTemplate}.${suffix}` : interfaceTemplate, templates)
if (suffix) {
interfaceDeclaration = getTemplate(`${interfaceTemplate}.${suffix}`, templates)
}
if (!interfaceDeclaration) {
interfaceDeclaration = getTemplate(interfaceTemplate, templates)
}
xValues = getProviderXValues(method)
method.tags.unshift({
name: 'provider'
Expand Down
10 changes: 4 additions & 6 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 } from '../shared/json-schema.mjs'
import { getPath, localizeDependencies, getSafeEnumKeyName } from '../shared/json-schema.mjs'
import path from "path"

let convertTuplesToArraysOrObjects = false
Expand Down Expand Up @@ -69,8 +69,6 @@ const indent = (str, padding) => {
}
}

const safeName = value => value.split(':').pop().replace(/[\.\-]/g, '_').replace(/\+/g, '_plus').replace(/([a-z])([A-Z0-9])/g, '$1_$2').toUpperCase()

// TODO: This is what's left of getMethodSignatureParams. We need to figure out / handle C's `FireboltTypes_StringHandle`
function getMethodSignatureParams(method, module, { destination, callback }) {
const paramOptional = getTemplate('/parameters/optional')
Expand Down Expand Up @@ -215,7 +213,7 @@ const insertEnumMacros = (content, schema, module, name, suffix, templateDir = "
if (!value) {
value = getTemplate(path.join(templateDir, 'unset' + suffix))
}
value ? values.push(template[i].replace(/\$\{key\}/g, safeName(value))
value ? values.push(template[i].replace(/\$\{key\}/g, getSafeEnumKeyName(value))
.replace(/\$\{value\}/g, value)) : ''
})
template[i] = values.map((value, id) => {
Expand Down Expand Up @@ -401,8 +399,8 @@ const insertObjectMacros = (content, schema, module, title, property, options) =
options2.property = prop
const schemaShape = getSchemaShape(type, module, options2)
properties.push(template
.replace(/\$\{property\}/g, safeName(prop))
.replace(/\$\{Property\}/g, capitalize(safeName(prop)))
.replace(/\$\{property\}/g, getSafeEnumKeyName(prop))
.replace(/\$\{Property\}/g, capitalize(getSafeEnumKeyName(prop)))
.replace(/\$\{parent\.title\}/g, title)
.replace(/\$\{title\}/g, getSchemaType(type, module, options2))
.replace(/\$\{shape\}/g, schemaShape)
Expand Down
Loading