Skip to content

Commit

Permalink
Add initial schema generation for team-broker topics
Browse files Browse the repository at this point in the history
  • Loading branch information
knolleary committed Jan 9, 2025
1 parent 71b732d commit 988e31c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
4 changes: 4 additions & 0 deletions forge/ee/routes/teamBroker/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const schemaApi = require('./schema')

module.exports = async function (app) {
app.addHook('preHandler', app.verifySession)

Expand Down Expand Up @@ -35,6 +37,8 @@ module.exports = async function (app) {
}
})

await schemaApi(app)

/**
* Get the Teams MQTT Clients
* @name /api/v1/teams/:teamId/broker/clients
Expand Down
42 changes: 42 additions & 0 deletions forge/ee/routes/teamBroker/schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const YAML = require('yaml')
module.exports = async function (app) {
app.get('/team-broker/schema.yml', async (request, reply) => {
const list = await app.teamBroker.getUsedTopics(request.team.hashid)
const schema = {
asyncapi: '3.0.0',
info: {
version: '1.0.0',
title: `${request.team.name} Team Broker`,
description: 'An auto-generated schema of the topics being used on the team broker'
}
}
// Add the team-broker details

// Figure out the hostname for the team broker
let teamBrokerHost = app.config.broker?.teamBroker?.host
if (!teamBrokerHost) {
// No explict value set, default to broker.${domain}
if (app.config.domain) {
teamBrokerHost = `broker.${app.config.domain}`
}
}
if (teamBrokerHost) {
schema.servers = {
'team-broker': {
host: teamBrokerHost,
protocol: 'mqtt'
}
}
}

if (list.length > 0) {
schema.channels = {}
list.forEach(topic => {
schema.channels[topic] = {
address: topic
}
})
}
reply.send(YAML.stringify(schema))
})
}

0 comments on commit 988e31c

Please sign in to comment.