Skip to content

Commit

Permalink
feat: App Pass-through
Browse files Browse the repository at this point in the history
  • Loading branch information
jlacivita committed Mar 19, 2024
1 parent 189eed2 commit b126834
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 24 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
],
"license": "Apache-2.0",
"dependencies": {
"ajv": "^8.3.0",
"ajv-formats": "^2.1.0",
"ajv": "^8.12.0",
"ajv-formats": "^2.1.1",
"array.prototype.groupby": "^1.1.0",
"crocks": "^0.12.4",
"deepmerge": "^4.2.2",
Expand Down
37 changes: 37 additions & 0 deletions src/firebolt-openrpc.json
Original file line number Diff line number Diff line change
Expand Up @@ -1007,8 +1007,45 @@
},
"x-error-for": {
"type": "string"
},
"x-provided-by": {
"type": "string"
}
},
"if": {
"required": [
"x-provided-by"
]
},
"then": {
"not": {
"required": [
"x-provides"
]
},
"oneOf": [
{
"required": [ "x-manages"],
"properties": {
"x-manages": {
"type": "array",
"minItems": 1,
"maxItems": 1
}
}
},
{
"required": [ "x-uses"],
"properties": {
"x-uses": {
"type": "array",
"minItems": 1,
"maxItems": 1
}
}
}
]
},
"anyOf": [
{
"required": [ "x-uses"]
Expand Down
6 changes: 3 additions & 3 deletions src/macrofier/engine.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ function generateSchemas(json, templates, options) {
const schemas = JSON.parse(JSON.stringify(json.definitions || (json.components && json.components.schemas) || {}))

const generate = (name, schema, uri, { prefix = '' } = {}) => {
// these are internal schemas used by the firebolt-openrpc tooling, and not meant to be used in code/doc generation
// these are internal schemas used by the fireboltize-openrpc tooling, and not meant to be used in code/doc generation
if (['ListenResponse', 'ProviderRequest', 'ProviderResponse', 'FederatedResponse', 'FederatedRequest'].includes(name)) {
return
}
Expand Down Expand Up @@ -1132,7 +1132,7 @@ function insertMethodMacros(template, methodObj, json, templates, examples = {})
const subscriber = json.methods.find(method => method.tags.find(tag => tag['x-alternative'] === methodObj.name))
const subscriberTemplate = (subscriber ? insertMethodMacros(getTemplate('/codeblocks/subscriber', templates), subscriber, json, templates, examples) : '')
const setterFor = methodObj.tags.find(t => t.name === 'setter') && methodObj.tags.find(t => t.name === 'setter')['x-setter-for'] || ''
const pullsResult = (puller || pullsFor) ? localizeDependencies(pullsFor || methodObj, json).params[1].schema : null
const pullsResult = (puller || pullsFor) ? localizeDependencies(pullsFor || methodObj, json).params.findLast(x=>true).schema : null
const pullsParams = (puller || pullsFor) ? localizeDependencies(getPayloadFromEvent(puller || methodObj), json, null, { mergeAllOfs: true }).properties.parameters : null
const pullsResultType = pullsResult && types.getSchemaShape(pullsResult, json, { destination: state.destination, section: state.section })
const pullsForType = pullsResult && types.getSchemaType(pullsResult, json, { destination: state.destination, section: state.section })
Expand Down Expand Up @@ -1467,7 +1467,7 @@ function generateProviderInterfaces(json, templates) {
function insertProviderInterfaceMacros(template, capability, moduleJson = {}, templates) {
const iface = getProviderInterface(capability, moduleJson, { destination: state.destination, section: state.section })//.map(method => { method.name = method.name.charAt(9).toLowerCase() + method.name.substr(10); return method } )

const uglyName = capability.split(":").slice(-2).map(capitalize).reverse().join('') + "Provider"
const uglyName = capability.split(':').slice(-2).map(capitalize).map(x => x.split('-').map(capitalize).join('')).reverse().join('') + "Provider"
let name = iface.length === 1 ? iface[0].name.charAt(0).toUpperCase() + iface[0].name.substr(1) + "Provider" : uglyName

if (moduleJson.info['x-interface-names']) {
Expand Down
15 changes: 14 additions & 1 deletion src/openrpc/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const run = async ({
json = addExternalMarkdown(json, markdown)

// put module name in front of each method
json.methods.forEach(method => method.name = json.info.title + '.' + method.name)
json.methods.forEach(method => method.name = method.name.includes('\.') ? method.name : json.info.title + '.' + method.name)

// merge any info['x-'] extension values (maps & arrays only..)
Object.keys(json.info).filter(key => key.startsWith('x-')).forEach(extension => {
Expand Down Expand Up @@ -101,6 +101,19 @@ const run = async ({
logSuccess(`Generated the ${json.info.title} module.`)
})

// make sure all provided-by APIs point to a real provider method
const appProvided = openrpc.methods.filter(m => m.tags.find(t=>t['x-provided-by'])) || []
appProvided.forEach(m => {
const providedBy = m.tags.find(t=>t['x-provided-by'])['x-provided-by']
const provider = openrpc.methods.find(m => m.name === providedBy)
if (!provider) {
throw `Method ${m.name} is provided by an undefined method (${providedBy})`
}
else {
console.log(`Method ${m.name} is provided by ${providedBy}`)
}
})

await writeJson(output, openrpc)

console.log()
Expand Down
Loading

0 comments on commit b126834

Please sign in to comment.